mirror of
https://github.com/Naios/continuable.git
synced 2025-12-06 16:56:44 +08:00
some tests
This commit is contained in:
parent
1b91d859c6
commit
06c0e73c29
@ -400,6 +400,31 @@ namespace detail
|
||||
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.
|
||||
template<typename _CTy>
|
||||
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<typename std::decay<_CTy>::type> shared_continuable =
|
||||
std::make_shared<typename std::decay<_CTy>::type>(std::forward<_CTy>(continuable));
|
||||
/*std::shared_ptr<typename std::decay<_CTy>::type> shared_continuable =
|
||||
std::make_shared<typename std::decay<_CTy>::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
|
||||
|
||||
25
test.cpp
25
test.cpp
@ -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;
|
||||
}
|
||||
|
||||
/*
|
||||
namespace detail
|
||||
{
|
||||
template<typename, typename>
|
||||
@ -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<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!")));
|
||||
});
|
||||
},
|
||||
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!")));
|
||||
}),
|
||||
TrivialPromise())
|
||||
.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);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user