From b8e6edfbe8c52cf3058437714e4e29a0b2794f4b Mon Sep 17 00:00:00 2001 From: Denis Blank Date: Tue, 11 Aug 2015 16:05:18 +0200 Subject: [PATCH] cleanup and build fix --- Incubator.cpp | 7 +- include/Continuable.h | 227 +++++++++++++++++++----------------------- 2 files changed, 108 insertions(+), 126 deletions(-) diff --git a/Incubator.cpp b/Incubator.cpp index cadf441..e6e9f3e 100644 --- a/Incubator.cpp +++ b/Incubator.cpp @@ -605,6 +605,9 @@ void some_examples() }) .then([](SpellCastResult) { + }) + .then([] + { }); // DispatcherPool countPool(1); @@ -715,12 +718,12 @@ void test_incubator() { test_cross_forward(); - std::function(int, float)> fn1 = detail::partial_corrector::correct([](int, float) + std::function(int, float)> fn1 = detail::correctors::partial_signature_corrector::correct([](int, float) { return make_continuable(); }); - std::function(int, float)> fn2 = detail::partial_corrector::correct([] + std::function(int, float)> fn2 = detail::correctors::partial_signature_corrector::correct([] { return make_continuable(); }); diff --git a/include/Continuable.h b/include/Continuable.h index b818667..1023fe5 100644 --- a/include/Continuable.h +++ b/include/Continuable.h @@ -57,7 +57,7 @@ namespace detail }; template - struct continuable_acceptor; + struct continuable_corrector; template struct continuable_unwrap; @@ -153,13 +153,13 @@ public: auto then(_CTy&& functional) -> typename detail::continuable_unwrap<_CTy, _ATy...>::continuable_t { - static_assert(std::is_same, + /*static_assert(std::is_same, typename detail::continuable_unwrap<_CTy, _ATy...>::arguments_t>::value, - "Given function signature isn't correct, for now it must match strictly!"); + "Given function signature isn't correct, for now it must match strictly!");*/ ForwardFunction&& callback = std::move(_callback_insert); - auto&& corrected = detail::continuable_acceptor<_ATy...>::accept(std::forward<_CTy>(functional)); + auto&& corrected = detail::continuable_corrector<_ATy...>::correct(std::forward<_CTy>(functional)); return typename detail::continuable_unwrap<_CTy, _ATy...>::continuable_t( [corrected, callback](typename detail::continuable_unwrap<_CTy, _ATy...>::callback_t&& call_next) @@ -222,6 +222,7 @@ public: namespace detail { + // TODO remove this template struct ContinuableFactory; @@ -258,11 +259,6 @@ inline auto make_continuable(_FTy&& functional) } /// Creates an empty continuable. -/// Can be used to start a chain with aggregate methods. -/// empty_continuable() -/// .all(...) -/// .some(...) -/// .any(...) inline auto make_continuable() -> Continuable<> { @@ -274,33 +270,71 @@ inline auto make_continuable() namespace detail { - template - struct concat_identities; - - template - struct concat_identities, fu::identity> + namespace correctors { - typedef fu::identity type; - }; + /// Corrects functionals with non expected signatures + /// to match the expected ones. + /// Used in `partialized_signature_corrector` + template + struct partial_signature_corrector + { + /// Corrector + template + static auto correct(_CTy&& functional) + -> typename std::enable_if< + !std::is_same< + fu::argument_type_of_t< + typename std::decay<_CTy>::type + >, + fu::identity<_ATy...> + >::value, + std::function< + fu::return_type_of_t< + typename std::decay<_CTy>::type + >(_ATy...) + > + >::type + { + // Make use of std::bind's signature erasure + return std::bind(std::forward<_CTy>(functional)); + } - template - struct identity_to_tuple; + // Route through + template + static auto correct(_CTy&& functional) + -> typename std::enable_if< + std::is_same< + fu::argument_type_of_t< + typename std::decay<_CTy>::type + >, + fu::identity<_ATy...> + >::value, + _CTy + >::type + { + return std::forward<_CTy>(functional); + } + }; - template - struct identity_to_tuple> - { - typedef std::tuple type; - }; + } // namespace correctors - template - struct void_wrap_trait; - - /// Trait needed for functional_traits::remove_void_trait + /// Corrector for given Continuables. template - struct void_wrap_trait> + struct continuable_corrector { + /// Wrap void returning functionals to return an empty continuable. + /// Example: + /// void(int, float) to Continuable<>(int, float) template - static std::function(_ATy...)> wrap(_CTy&& functional) + static auto void_returning_corrector(_CTy&& functional) + -> typename std::enable_if< + std::is_void< + fu::return_type_of_t< + typename std::decay<_CTy>::type + > + >::value, + std::function(_ATy...)> + >::type { return [functional](_ATy&&... args) { @@ -311,85 +345,10 @@ namespace detail return make_continuable(); }; } - }; - - /// Corrects functionals with non expected signatures - /// to match the expected ones. - /// Used in `partialize_correct_trait` - template - struct partial_corrector - { - /// Corrector - template - static auto correct(_CTy&& functional) - -> typename std::enable_if< - !std::is_same< - fu::argument_type_of_t< - typename std::decay<_CTy>::type - >, - fu::identity<_ATy...> - >::value, - std::function< - fu::return_type_of_t< - typename std::decay<_CTy>::type - >(_ATy...) - > - >::type - { - // Make use of std::bind's signature erasure - return std::bind(std::forward<_CTy>(functional)); - } - - // Route through - template - static auto correct(_CTy&& functional) - -> typename std::enable_if< - std::is_same< - fu::argument_type_of_t< - typename std::decay<_CTy>::type - >, - fu::identity<_ATy...> - >::value, - _CTy - >::type - { - return std::forward<_CTy>(functional); - } - }; - - template - struct continuable_acceptor - { - /// Wrap void returning functionals to return an empty continuable. - /// Example: - /// void(int, float) to Continuable<>(int, float) - template - static auto remove_void_trait(_CTy&& functional) - -> typename std::enable_if< - std::is_void< - fu::return_type_of_t< - typename std::decay<_CTy>::type - > - >::value, - decltype( - detail::void_wrap_trait< - fu::argument_type_of_t< - typename std::decay<_CTy>::type - > - >::wrap(std::declval<_CTy>()) - ) - >::type - { - return detail::void_wrap_trait< - fu::argument_type_of_t< - typename std::decay<_CTy>::type - > - >::wrap(std::forward<_CTy>(functional)); - } /// Route continuable returning functionals through. template - static auto remove_void_trait(_CTy&& functional) + static auto void_returning_corrector(_CTy&& functional) -> typename std::enable_if< !std::is_void< fu::return_type_of_t< @@ -402,16 +361,16 @@ namespace detail } template - static inline auto partialize_correct_trait(_CTy&& functional) - -> _CTy// decltype(partial_corrector<_ATy...>::correct(std::declval<_CTy>())) + static inline auto partialized_signature_corrector(_CTy&& functional) + -> _CTy// decltype(correctors::partial_signature_corrector<_ATy...>::correct(std::declval<_CTy>())) { - // return partial_corrector<_ATy...>::correct(std::forward<_CTy>(functional)); + // return correctors::partial_signature_corrector<_ATy...>::correct(std::forward<_CTy>(functional)); return std::forward<_CTy>(functional); } /// Wrap Continuables into the continuable returning functional type. template - static auto box_continuable_trait(_CTy&& continuable) + static auto unboxed_continuable_corrector(_CTy&& continuable) -> typename std::enable_if< detail::is_continuable< typename std::decay<_CTy>::type @@ -436,62 +395,82 @@ namespace detail }; } - /// `box_continuable_trait`: Converts plain Continuables to continuable retuning functions. + /// `unboxed_continuable_corrector`: Converts plain Continuables to continuable retuning functions. template static auto correct_stage(_CTy&& functional) -> typename std::enable_if< detail::is_continuable< typename std::decay<_CTy>::type >::value, - decltype(box_continuable_trait(std::declval<_CTy>())) + decltype(unboxed_continuable_corrector(std::declval<_CTy>())) >::type { - return box_continuable_trait(std::forward<_CTy>(functional)); + return unboxed_continuable_corrector(std::forward<_CTy>(functional)); } - /// `partialize_correct_trait`: Converts functionals with not matching args signature. - /// `remove_void_trait`: Converts void return to empty continuable. + /// `partialized_signature_corrector`: Converts functionals with not matching args signature. + /// `void_returning_corrector`: Converts void return to empty continuable. template static auto correct_stage(_CTy&& functional) -> typename std::enable_if< !detail::is_continuable< typename std::decay<_CTy>::type >::value, - decltype(remove_void_trait(partialize_correct_trait(std::declval<_CTy>()))) + decltype(void_returning_corrector(partialized_signature_corrector(std::declval<_CTy>()))) >::type { - return remove_void_trait(partialize_correct_trait(std::forward<_CTy>(functional))); + return void_returning_corrector(partialized_signature_corrector(std::forward<_CTy>(functional))); } /// Accepts and corrects user given functionals through several stages into the form: /// Continuable<_CArgs...>(_FArgs) template - static inline auto accept(_CTy&& functional) + static inline auto correct(_CTy&& functional) -> decltype(correct_stage(std::declval<_CTy>())) { return correct_stage(std::forward<_CTy>(functional)); } - }; + + }; // struct continuable_corrector // Unwraps the corrected type of Continuables template struct continuable_unwrap { // Corrected user given functional - typedef decltype(continuable_acceptor<_ATy...>:: - accept(std::declval::type>())) accepted_t; + typedef decltype(continuable_corrector<_ATy...>:: + correct(std::declval::type>())) corrected_t; - typedef fu::return_type_of_t continuable_t; + typedef fu::return_type_of_t continuable_t; - typedef fu::argument_type_of_t arguments_t; + typedef fu::argument_type_of_t arguments_t; typedef typename continuable_t::CallbackFunction callback_t; typedef fu::argument_type_of_t callback_arguments_t; - }; + + }; // struct continuable_unwrap /* - /// Position wrapper class to pass ints as type + template + struct concat_identities; + + template + struct concat_identities, fu::identity> + { + typedef fu::identity type; + }; + + template + struct identity_to_tuple; + + template + struct identity_to_tuple> + { + typedef std::tuple type; + }; + + /// Position wrapper class to pass ints as type template struct partial_result {