From 519ab69d40d95d7cac4dbbb938da09d025157543 Mon Sep 17 00:00:00 2001 From: Denis Blank Date: Tue, 14 Jul 2015 22:17:04 +0200 Subject: [PATCH] more tests --- include/Continuable.h | 16 ++++++---------- test.cpp | 39 ++++++++++++++++++++++++++++++--------- 2 files changed, 36 insertions(+), 19 deletions(-) diff --git a/include/Continuable.h b/include/Continuable.h index 45962f7..c3600e7 100644 --- a/include/Continuable.h +++ b/include/Continuable.h @@ -357,6 +357,7 @@ namespace detail typedef Tuple tuple; }; + /* template struct continuable_returner { @@ -381,6 +382,7 @@ namespace detail return std::move(returning_continuable); } }; + */ /// Continuable processing detail implementation template @@ -440,22 +442,16 @@ namespace detail static_assert(std::is_rvalue_reference<_CTy&&>::value, "Given continuable must be passed as r-value!"); - std::function::type(_ATy...)> returning_function; - - continuable_returner<_CTy, _ATy...> returner(std::forward<_CTy>(continuable)); - - return std::move(returning_function); - // 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 0b4ce10..a0b6324 100644 --- a/test.cpp +++ b/test.cpp @@ -127,6 +127,30 @@ namespace detail } */ +template +class continuable_returner +{ + _CTy returning_continuable; + +public: + continuable_returner(_CTy&& returning_continuable_) + : returning_continuable(std::move(returning_continuable_)) { } + + continuable_returner& operator= (continuable_returner&) = delete; + + continuable_returner& operator= (continuable_returner&& right) + { + // returning_continuable = std::move(right.returning_continuable); + return *this; + }; + + auto operator()(_ATy&&...) + -> _CTy + { + return std::move(returning_continuable); + } +}; + int main(int /*argc*/, char** /*argv*/) { /* @@ -411,18 +435,15 @@ int main(int /*argc*/, char** /*argv*/) conv_test_1(1, 1); - struct TestFunctor - { - void operator() (int) - { - } - }; + - TestFunctor fn; + continuable_returner> fn(std::unique_ptr(new int(5))); - static_assert(fu::is_unwrappable::value, "not unwrappable!"); + continuable_returner> other_fn = std::move(fn); - std::function fntest = std::move(fn); + // static_assert(fu::is_unwrappable::value, "not unwrappable!"); + + // std::function fntest = std::move(fn); return 0; }