From f60d01c757dba603c967559b7e2b13c80f3c4204 Mon Sep 17 00:00:00 2001 From: Denis Blank Date: Sun, 21 Jun 2015 16:05:59 +0200 Subject: [PATCH] reorganize forward declarations --- include/Continuable.h | 133 +++++++++++++++++++++--------------------- 1 file changed, 67 insertions(+), 66 deletions(-) diff --git a/include/Continuable.h b/include/Continuable.h index 241fde1..eb7488a 100644 --- a/include/Continuable.h +++ b/include/Continuable.h @@ -36,7 +36,6 @@ void debug(std::string const& m) } /// Debug end -// Continuable forward declaration. template class Continuable; @@ -107,6 +106,8 @@ namespace detail } // detail +/// A continuable provides useful methods to react on the result of callbacks +/// and allows to chain multiple callback calls to a chain. template class Continuable { @@ -345,71 +346,6 @@ public: namespace detail { - template - struct functional_corrector - { - static int correct(_CTy&&) - { - return 1; - } - }; - - template - struct void_wrap_trait> - { - template - static std::function(Args...)> wrap(_CTy&& functional) - { - return [functional](Args... args) - { - // Invoke the original callback - functional(std::forward(args)...); - - // FIXME return make_empty_continuable() - // Return a fake continuable - return Continuable<>([](Callback<>&& callback) - { - callback(); - }); - }; - } - }; - - - template<> - struct convert_void_to_continuable - { - typedef Continuable<> type; - - template - static type invoke(Fn functional, Args&&... args) - { - // Invoke the void returning functional - functional(std::forward(args)...); - - // Return a fake void continuable - return type([](Callback<>&& callback) - { - callback(); - }); - } - }; - - template - struct convert_void_to_continuable> - { - typedef Continuable<_CTy...> type; - - template - static type invoke(Fn functional, Args&&... args) - { - // Invoke the functional as usual. - return functional(std::forward(args)...); - } - }; - /// A continuable provides useful methods to react on the result of callbacks - /// and allows to chain multiple callback calls to a chain. - template struct ContinuableFactory; @@ -460,4 +396,69 @@ inline auto make_continuable() }); } +namespace detail +{ + template + struct functional_corrector + { + static int correct(_CTy&&) + { + return 1; + } + }; + + template + struct void_wrap_trait> + { + template + static std::function(Args...)> wrap(_CTy&& functional) + { + return [functional](Args... args) + { + // Invoke the original callback + functional(std::forward(args)...); + + // FIXME return make_empty_continuable() + // Return a fake continuable + return Continuable<>([](Callback<>&& callback) + { + callback(); + }); + }; + } + }; + + template<> + struct convert_void_to_continuable + { + typedef Continuable<> type; + + template + static type invoke(Fn functional, Args&&... args) + { + // Invoke the void returning functional + functional(std::forward(args)...); + + // Return a fake void continuable + return type([](Callback<>&& callback) + { + callback(); + }); + } + }; + + template + struct convert_void_to_continuable> + { + typedef Continuable<_CTy...> type; + + template + static type invoke(Fn functional, Args&&... args) + { + // Invoke the functional as usual. + return functional(std::forward(args)...); + } + }; +} + #endif // _CONTINUABLE_H_