From 06c0e73c2971fc99ff04b5664fb92271b8ebbc84 Mon Sep 17 00:00:00 2001 From: Denis Blank Date: Sun, 12 Jul 2015 22:36:13 +0200 Subject: [PATCH] some tests --- include/Continuable.h | 35 +++++++++++++++++++++++++++++++---- test.cpp | 25 +++++++++++++++++++------ 2 files changed, 50 insertions(+), 10 deletions(-) diff --git a/include/Continuable.h b/include/Continuable.h index 21865f9..f2fbcfb 100644 --- a/include/Continuable.h +++ b/include/Continuable.h @@ -400,6 +400,31 @@ namespace detail return std::forward<_CTy>(functional); } + template + struct continuable_returner + { + typename std::decay<_CTy>::type returning_continuable; + + continuable_returner(typename std::decay<_CTy>::type&& returning_continuable_) + : returning_continuable(std::move(returning_continuable_)) { } + + continuable_returner(continuable_returner&) = delete; + + continuable_returner& operator= (continuable_returner&) = delete; + + continuable_returner& operator= (continuable_returner&& right) + { + returning_continuable = std::move(right.returning_continuable); + return *this; + }; + + auto operator()(_ATy&&...) + -> typename std::decay<_CTy>::type + { + return std::move(returning_continuable); + } + }; + /// Wrap continuables into the continuable returning functional type. template static auto box_continuable_trait(_CTy&& continuable) @@ -415,16 +440,18 @@ namespace detail static_assert(std::is_rvalue_reference<_CTy&&>::value, "Given continuable must be passed as r-value!"); + return continuable_returner<_CTy>(std::forward<_CTy>(continuable)); + // Trick C++11 lambda capture rules for non copyable but moveable continuables. // TODO Use the stack instead of heap variables. - std::shared_ptr::type> shared_continuable = - std::make_shared::type>(std::forward<_CTy>(continuable)); + /*std::shared_ptr::type> shared_continuable = + std::make_shared::type>(std::forward<_CTy>(continuable));*/ // Create a fake function which returns the value on invoke. - return [shared_continuable](_ATy&&...) + /*return [shared_continuable](_ATy&&...) { return std::move(*shared_continuable); - }; + };*/ } /// Route functionals through diff --git a/test.cpp b/test.cpp index a91b59c..0b4ce10 100644 --- a/test.cpp +++ b/test.cpp @@ -110,6 +110,7 @@ void test_unwrap(std::string const& msg) std::cout << msg << " is unwrappable: " << (fu::is_unwrappable::value ? "true" : "false") << std::endl; } +/* namespace detail { template @@ -124,6 +125,7 @@ namespace detail }; } +*/ int main(int /*argc*/, char** /*argv*/) { @@ -386,12 +388,10 @@ int main(int /*argc*/, char** /*argv*/) CastSpellPromise(10) .then(CastSpellPromise(15)), CastSpellPromise(20), - [] { - return make_continuable([](Callback>&& callback) - { - callback(true, false, 0.3f, std::unique_ptr(new std::string("oh, all work is done!"))); - }); - }, + make_continuable([](Callback>&& callback) + { + callback(true, false, 0.3f, std::unique_ptr(new std::string("oh, all work is done!"))); + }), TrivialPromise()) .then([](SpellCastResult r0, SpellCastResult r1, bool r2, bool r3, double r4, std::unique_ptr message) { @@ -411,5 +411,18 @@ int main(int /*argc*/, char** /*argv*/) conv_test_1(1, 1); + struct TestFunctor + { + void operator() (int) + { + } + }; + + TestFunctor fn; + + static_assert(fu::is_unwrappable::value, "not unwrappable!"); + + std::function fntest = std::move(fn); + return 0; }