From 23149fcc0c0c4b817444b5040ec47a98d8902477 Mon Sep 17 00:00:00 2001 From: Denis Blank Date: Mon, 22 Jun 2015 16:30:08 +0200 Subject: [PATCH] some concepts --- include/Continuable.h | 45 ++++++++++++++++++++++++++++++++++++++++ test.cpp | 48 +++++++++++++++---------------------------- 2 files changed, 62 insertions(+), 31 deletions(-) diff --git a/include/Continuable.h b/include/Continuable.h index cffcba9..ba29240 100644 --- a/include/Continuable.h +++ b/include/Continuable.h @@ -289,6 +289,21 @@ inline auto make_continuable() namespace detail { + template + struct concat_identities; + + template + struct concat_identities, fu::identity> + { + typedef fu::identity type; + }; + + template + struct multiple_chainer_test + { + + }; + template struct void_wrap_trait; @@ -404,6 +419,36 @@ namespace detail { return remove_void_trait(box_continuable_trait(std::forward<_CTy>(functional))); } + + template + struct multiple_result_maker; + + template + struct multiple_result_maker, Last> + { + // typedef decltype(correct(std::declval::type>())) corrected_t; + + /* + typedef typename concat_identities< + fu::identity, + fu::argument_type_of_t + > type; + */ + }; + + template + struct multiple_result_maker, First, Rest...> + { + /* + typedef typename multiple_result_maker< + typename concat_identities< + fu::identity, + fu::argument_type_of_t + >, + Rest... + > type; + */ + }; }; } diff --git a/test.cpp b/test.cpp index 6bdc4aa..9494b89 100644 --- a/test.cpp +++ b/test.cpp @@ -25,6 +25,15 @@ enum SpellCastResult template using Optional = boost::optional; +Continuable<> Log(std::string const& message) +{ + return make_continuable([=](Callback<>&& callback) + { + std::cout << message << std::endl; + callback(); + }); +} + // Original method taking an optional callback. void CastSpell(int id, Optional> const& callback = boost::none) { @@ -47,13 +56,10 @@ Continuable CastSpellPromise(int id) // Void instant returning continuable promise for testing purposes Continuable<> TrivialPromise(std::string const& msg = "") { - return make_continuable([=](Callback<>&& callback) + return Log(msg).then(make_continuable([=](Callback<>&& callback) { - if (!msg.empty()) - std::cout << msg << std::endl; - callback(); - }); + })); } Continuable Validate() @@ -84,6 +90,7 @@ int main(int /*argc*/, char** /*argv*/) std::cout << "Pause a callback (void test) " << std::endl; }) .then(Validate()) + .then(TrivialPromise("huhu")) .then(CastSpellPromise(3)) .then(CastSpellPromise(4)) .then(CastSpellPromise(5)) @@ -110,6 +117,7 @@ int main(int /*argc*/, char** /*argv*/) ) .then([] { + std::cout << "Finished" << std::endl; }); //Continuable cb = make_continuable([](Callback&& callback) @@ -222,34 +230,12 @@ int main(int /*argc*/, char** /*argv*/) //// Here we go //entry(); -/* - auto testaiasj = remove_void_trait([] - { - - }); + detail::functional_traits<>::multiple_result_maker< + fu::identity<>, - */ + std::function> -/* - auto testres = Continuable<>::remove_void_trait([] - { - }); - */ - - auto test1 = detail::functional_traits<>::correct([] - { - }); - - auto test2 = detail::functional_traits<>::correct([] - { - return make_continuable([](Callback&& callback) - { - - callback(1, 2); - }); - }); - - auto test3 = detail::functional_traits<>::correct(make_continuable()); + > test282; std::cout << "ok" << std::endl; return 0;