some tests

This commit is contained in:
Denis Blank 2015-07-12 22:36:13 +02:00 committed by Naios
parent 1b91d859c6
commit 06c0e73c29
2 changed files with 50 additions and 10 deletions

View File

@ -400,6 +400,31 @@ namespace detail
return std::forward<_CTy>(functional); return std::forward<_CTy>(functional);
} }
template<typename _CTy>
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. /// Wrap continuables into the continuable returning functional type.
template<typename _CTy> template<typename _CTy>
static auto box_continuable_trait(_CTy&& continuable) static auto box_continuable_trait(_CTy&& continuable)
@ -415,16 +440,18 @@ namespace detail
static_assert(std::is_rvalue_reference<_CTy&&>::value, static_assert(std::is_rvalue_reference<_CTy&&>::value,
"Given continuable must be passed as r-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. // Trick C++11 lambda capture rules for non copyable but moveable continuables.
// TODO Use the stack instead of heap variables. // TODO Use the stack instead of heap variables.
std::shared_ptr<typename std::decay<_CTy>::type> shared_continuable = /*std::shared_ptr<typename std::decay<_CTy>::type> shared_continuable =
std::make_shared<typename std::decay<_CTy>::type>(std::forward<_CTy>(continuable)); std::make_shared<typename std::decay<_CTy>::type>(std::forward<_CTy>(continuable));*/
// Create a fake function which returns the value on invoke. // Create a fake function which returns the value on invoke.
return [shared_continuable](_ATy&&...) /*return [shared_continuable](_ATy&&...)
{ {
return std::move(*shared_continuable); return std::move(*shared_continuable);
}; };*/
} }
/// Route functionals through /// Route functionals through

View File

@ -110,6 +110,7 @@ void test_unwrap(std::string const& msg)
std::cout << msg << " is unwrappable: " << (fu::is_unwrappable<T...>::value ? "true" : "false") << std::endl; std::cout << msg << " is unwrappable: " << (fu::is_unwrappable<T...>::value ? "true" : "false") << std::endl;
} }
/*
namespace detail namespace detail
{ {
template<typename, typename> template<typename, typename>
@ -124,6 +125,7 @@ namespace detail
}; };
} }
*/
int main(int /*argc*/, char** /*argv*/) int main(int /*argc*/, char** /*argv*/)
{ {
@ -386,12 +388,10 @@ int main(int /*argc*/, char** /*argv*/)
CastSpellPromise(10) CastSpellPromise(10)
.then(CastSpellPromise(15)), .then(CastSpellPromise(15)),
CastSpellPromise(20), CastSpellPromise(20),
[] { make_continuable([](Callback<bool, bool, double , std::unique_ptr<std::string>>&& callback)
return make_continuable([](Callback<bool, bool, double , std::unique_ptr<std::string>>&& callback) {
{ callback(true, false, 0.3f, std::unique_ptr<std::string>(new std::string("oh, all work is done!")));
callback(true, false, 0.3f, std::unique_ptr<std::string>(new std::string("oh, all work is done!"))); }),
});
},
TrivialPromise()) TrivialPromise())
.then([](SpellCastResult r0, SpellCastResult r1, bool r2, bool r3, double r4, std::unique_ptr<std::string> message) .then([](SpellCastResult r0, SpellCastResult r1, bool r2, bool r3, double r4, std::unique_ptr<std::string> message)
{ {
@ -411,5 +411,18 @@ int main(int /*argc*/, char** /*argv*/)
conv_test_1(1, 1); conv_test_1(1, 1);
struct TestFunctor
{
void operator() (int)
{
}
};
TestFunctor fn;
static_assert(fu::is_unwrappable<TestFunctor>::value, "not unwrappable!");
std::function<void(int)> fntest = std::move(fn);
return 0; return 0;
} }