From 2388471ca7e582a4b7578b1974599c848f0e48ea Mon Sep 17 00:00:00 2001 From: Denis Blank Date: Mon, 22 Jun 2015 15:02:20 +0200 Subject: [PATCH] more work --- include/Continuable.h | 64 +++++++++++++++---------------------------- test.cpp | 4 +++ 2 files changed, 26 insertions(+), 42 deletions(-) diff --git a/include/Continuable.h b/include/Continuable.h index 3164b16..3b7ec76 100644 --- a/include/Continuable.h +++ b/include/Continuable.h @@ -98,9 +98,6 @@ namespace detail } }; - template - struct void_wrap_trait; - template struct functional_traits; @@ -335,20 +332,31 @@ inline auto make_continuable() namespace detail { - template - struct continuable_traits; + template + struct void_wrap_trait; - template - struct continuable_traits> + /// Trait needed for functional_traits::remove_void_trait + template + struct void_wrap_trait> { - + template + static std::function(_ATy...)> wrap(_CTy&& functional) + { + return [functional](_ATy... args) + { + // Invoke the original callback + functional(std::forward<_ATy>(args)...); + + // Return an empty continuable + return make_continuable(); + }; + } }; /// Continuable processing detail implementation template struct functional_traits { - /* /// Wrap void returning functionals to returns an empty continuable. template static auto remove_void_trait(_CTy&& functional) @@ -360,26 +368,19 @@ namespace detail >::value, decltype( detail::void_wrap_trait< - fu::return_type_of_t< + fu::argument_type_of_t< typename std::decay<_CTy>::type > >::wrap(std::declval<_CTy>()) ) - - decltype( - detail::functional_corrector<_CTy>::correct(std::declval<_CTy>()) - ) - // std::function()> >::type { return detail::void_wrap_trait< - fu::return_type_of_t< + fu::argument_type_of_t< typename std::decay<_CTy>::type > >::wrap(std::forward<_CTy>(functional)); - return detail::functional_corrector<_CTy>::correct(std::forward<_CTy>(functional)); } - */ /* @@ -420,9 +421,9 @@ namespace detail }; } - /// Route functionals through and forward to remove_void_trait + /// Route functionals through template - static auto box_continuable_trait(_CTy&& continuable) + inline static auto box_continuable_trait(_CTy&& continuable) -> typename std::enable_if< !detail::is_continuable< typename std::decay<_CTy>::type @@ -430,7 +431,7 @@ namespace detail typename std::decay<_CTy>::type >::type { - return continuable; + return std::forward<_CTy>(continuable); } template @@ -440,27 +441,6 @@ namespace detail } }; - 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 { diff --git a/test.cpp b/test.cpp index cbb9b47..1aaaa55 100644 --- a/test.cpp +++ b/test.cpp @@ -236,6 +236,10 @@ int main(int /*argc*/, char** /*argv*/) }); */ + auto test = detail::functional_traits<>::remove_void_trait([] + { + }); + std::cout << "ok" << std::endl; return 0; }