mirror of
https://github.com/Naios/continuable.git
synced 2025-12-06 16:56:44 +08:00
work on build
This commit is contained in:
parent
caa83bf2be
commit
1131215890
@ -19,6 +19,16 @@
|
||||
#ifndef _CALLBACK_H_
|
||||
#define _CALLBACK_H_
|
||||
|
||||
enum SpellCastResult
|
||||
{
|
||||
SPELL_FAILED_SUCCESS = 0,
|
||||
SPELL_FAILED_AFFECTING_COMBAT = 1,
|
||||
SPELL_FAILED_ALREADY_AT_FULL_HEALTH = 2,
|
||||
SPELL_FAILED_ALREADY_AT_FULL_MANA = 3,
|
||||
SPELL_FAILED_ALREADY_AT_FULL_POWER = 4,
|
||||
SPELL_FAILED_ALREADY_BEING_TAMED = 5
|
||||
};
|
||||
|
||||
#include <functional>
|
||||
#include <utility>
|
||||
#include <memory>
|
||||
|
||||
@ -189,9 +189,26 @@ public:
|
||||
/// Placeholder
|
||||
template<typename... _CTy>
|
||||
auto all(_CTy&&... functionals)
|
||||
-> Continuable&
|
||||
-> Continuable<SpellCastResult, SpellCastResult>
|
||||
/*typename detail::multiple_when_all_chainer_t<
|
||||
fu::identity<_ATy...>,
|
||||
fu::identity<_CTy...>
|
||||
>::make_result::continuable_t
|
||||
*/
|
||||
{
|
||||
return *this;
|
||||
return then([]()
|
||||
{
|
||||
return Continuable<SpellCastResult, SpellCastResult>();
|
||||
});
|
||||
|
||||
/*
|
||||
|
||||
return then(
|
||||
detail::multiple_when_all_chainer_t<
|
||||
fu::identity<_ATy...>,
|
||||
fu::identity<_CTy...>
|
||||
>::make_when_all(std::forward<_CTy>(functionals)...))
|
||||
*/
|
||||
}
|
||||
|
||||
/// Placeholder
|
||||
@ -491,9 +508,20 @@ namespace detail
|
||||
template<typename... Args>
|
||||
struct multiple_when_all_chainer_t_make_result<fu::identity<Args...>>
|
||||
{
|
||||
typedef Continuable<Args...> type;
|
||||
typedef Continuable<Args...> continuable_t;
|
||||
|
||||
// type create()
|
||||
typedef std::function<continuable_t()> return_t;
|
||||
|
||||
template <typename... _ATy, typename... _CTy>
|
||||
static return_t create(_CTy&&... functionals)
|
||||
{
|
||||
return [=](_ATy&&... args)
|
||||
{
|
||||
|
||||
|
||||
return continuable_t();
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
template <typename... _ATy, typename... _CTy>
|
||||
@ -507,11 +535,13 @@ namespace detail
|
||||
|
||||
static std::size_t const size = result_maker::size;
|
||||
|
||||
typedef typename multiple_when_all_chainer_t_make_result<arguments_t> make_result;
|
||||
|
||||
// Creates one continuable from multiple ones
|
||||
static auto make_when_all(_CTy&&... args)
|
||||
-> typename multiple_when_all_chainer_t_make_result<arguments_t>::type
|
||||
-> typename make_result::return_t
|
||||
{
|
||||
return multiple_when_all_chainer_t_make_result<arguments_t>::type();
|
||||
return make_result::create(std::forward<_CTy>(args)...);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
38
test.cpp
38
test.cpp
@ -12,15 +12,7 @@
|
||||
|
||||
#include <boost/optional.hpp>
|
||||
|
||||
enum SpellCastResult
|
||||
{
|
||||
SPELL_FAILED_SUCCESS = 0,
|
||||
SPELL_FAILED_AFFECTING_COMBAT = 1,
|
||||
SPELL_FAILED_ALREADY_AT_FULL_HEALTH = 2,
|
||||
SPELL_FAILED_ALREADY_AT_FULL_MANA = 3,
|
||||
SPELL_FAILED_ALREADY_AT_FULL_POWER = 4,
|
||||
SPELL_FAILED_ALREADY_BEING_TAMED = 5
|
||||
};
|
||||
|
||||
|
||||
template<typename T>
|
||||
using Optional = boost::optional<T>;
|
||||
@ -135,6 +127,7 @@ inline auto apply(F && f, T && t)
|
||||
|
||||
int main(int /*argc*/, char** /*argv*/)
|
||||
{
|
||||
/*
|
||||
CastSpellPromise(1)
|
||||
.then([](SpellCastResult)
|
||||
{
|
||||
@ -183,7 +176,7 @@ int main(int /*argc*/, char** /*argv*/)
|
||||
{
|
||||
std::cout << "Finished" << std::endl;
|
||||
});
|
||||
|
||||
*/
|
||||
//Continuable<bool> cb = make_continuable([](Callback<bool>&& callback)
|
||||
//{
|
||||
|
||||
@ -345,21 +338,23 @@ int main(int /*argc*/, char** /*argv*/)
|
||||
>
|
||||
>::result_maker::partial_results_t myres123345;
|
||||
|
||||
/*
|
||||
auto firstType = detail::multiple_when_all_chainer_t<
|
||||
fu::identity<>,
|
||||
fu::identity<
|
||||
std::function<Continuable<SpellCastResult>()>,
|
||||
std::function<Continuable<>()>,
|
||||
std::function<Continuable<SpellCastResult>()>,
|
||||
std::function<Continuable<SpellCastResult>()>
|
||||
>
|
||||
>::make_when_all(
|
||||
[]
|
||||
{
|
||||
return make_continuable();
|
||||
// void
|
||||
return CastSpellPromise(10);
|
||||
},
|
||||
[]
|
||||
{
|
||||
return CastSpellPromise(10);
|
||||
return make_continuable();
|
||||
},
|
||||
[]
|
||||
{
|
||||
@ -368,7 +363,24 @@ int main(int /*argc*/, char** /*argv*/)
|
||||
.then([](SpellCastResult, SpellCastResult)
|
||||
{
|
||||
|
||||
})
|
||||
.then([]
|
||||
{
|
||||
|
||||
});
|
||||
*/
|
||||
|
||||
auto promise = std::move(make_continuable()
|
||||
.all(
|
||||
[]
|
||||
{
|
||||
// void
|
||||
return CastSpellPromise(10);
|
||||
},
|
||||
[]
|
||||
{
|
||||
return CastSpellPromise(20);
|
||||
}));
|
||||
|
||||
std::cout << "ok" << std::endl;
|
||||
return 0;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user