Add the possible to direct use the continuable

This commit is contained in:
Naios 2015-06-16 20:02:00 +02:00
parent 836facdcdf
commit 074859d14f
2 changed files with 26 additions and 9 deletions

View File

@ -136,9 +136,11 @@ namespace detail
}
// Then implementation of eval functionals.
// Enable if the given type isn't a continuable.
template<typename _CTy>
auto _then(_CTy&& functional)
-> typename unary_chainer_t<_CTy>::result_t
-> typename std::enable_if<!is_continuable<typename std::decay<_CTy>::type>::value,
typename unary_chainer_t<_CTy>::result_t>::type
{
// Transfer the insert function to the local scope.
// Also use it as an r-value reference to try to get move semantics with c++11 lambdas.
@ -157,6 +159,26 @@ namespace detail
}, std::move(*this));
}
// The continuable itself
template<typename _CTy>
auto _then(_CTy&& continuable)
-> typename std::enable_if<is_continuable<typename std::decay<_CTy>::type>::value,
typename std::decay<_CTy>::type>::type
{
static_assert(std::is_rvalue_reference<_CTy&&>::value,
"Given continuable must be passed as r-value!");
// Trick C++11 lambda capture rules for non copyable but moveable continuables.
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 _then([shared_continuable](_ATy...)
{
return std::move(*shared_continuable);
});
}
public:
/// Deleted copy construct
_ContinuableImpl(_ContinuableImpl const&) = delete;

View File

@ -83,14 +83,9 @@ int main(int /*argc*/, char** /*argv*/)
{
std::cout << "Pause a callback (void test) " << std::endl;
})
.then([]
{
return CastSpellPromise(3);
})
.then([](SpellCastResult)
{
return CastSpellPromise(4);
})
.then(CastSpellPromise(3))
.then(CastSpellPromise(4))
.then(CastSpellPromise(5))
.then([](SpellCastResult)
{
return Validate();