mirror of
https://github.com/Naios/continuable.git
synced 2026-02-14 06:09:48 +08:00
Add the possible to direct use the continuable
This commit is contained in:
parent
836facdcdf
commit
074859d14f
@ -136,9 +136,11 @@ namespace detail
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Then implementation of eval functionals.
|
// Then implementation of eval functionals.
|
||||||
|
// Enable if the given type isn't a continuable.
|
||||||
template<typename _CTy>
|
template<typename _CTy>
|
||||||
auto _then(_CTy&& functional)
|
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.
|
// 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.
|
// 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));
|
}, 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:
|
public:
|
||||||
/// Deleted copy construct
|
/// Deleted copy construct
|
||||||
_ContinuableImpl(_ContinuableImpl const&) = delete;
|
_ContinuableImpl(_ContinuableImpl const&) = delete;
|
||||||
|
|||||||
11
test.cpp
11
test.cpp
@ -83,14 +83,9 @@ int main(int /*argc*/, char** /*argv*/)
|
|||||||
{
|
{
|
||||||
std::cout << "Pause a callback (void test) " << std::endl;
|
std::cout << "Pause a callback (void test) " << std::endl;
|
||||||
})
|
})
|
||||||
.then([]
|
.then(CastSpellPromise(3))
|
||||||
{
|
.then(CastSpellPromise(4))
|
||||||
return CastSpellPromise(3);
|
.then(CastSpellPromise(5))
|
||||||
})
|
|
||||||
.then([](SpellCastResult)
|
|
||||||
{
|
|
||||||
return CastSpellPromise(4);
|
|
||||||
})
|
|
||||||
.then([](SpellCastResult)
|
.then([](SpellCastResult)
|
||||||
{
|
{
|
||||||
return Validate();
|
return Validate();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user