mirror of
https://github.com/Naios/continuable.git
synced 2025-12-08 01:36:46 +08:00
some concepts
This commit is contained in:
parent
9e9a4434f1
commit
e233fe4785
@ -289,6 +289,21 @@ inline auto make_continuable()
|
||||
|
||||
namespace detail
|
||||
{
|
||||
template<typename Left, typename Right>
|
||||
struct concat_identities;
|
||||
|
||||
template<typename... Left, typename... Right>
|
||||
struct concat_identities<fu::identity<Left...>, fu::identity<Right...>>
|
||||
{
|
||||
typedef fu::identity<Left..., Right...> type;
|
||||
};
|
||||
|
||||
template<typename... _CTy>
|
||||
struct multiple_chainer_test
|
||||
{
|
||||
|
||||
};
|
||||
|
||||
template<typename _ATy>
|
||||
struct void_wrap_trait;
|
||||
|
||||
@ -404,6 +419,36 @@ namespace detail
|
||||
{
|
||||
return remove_void_trait(box_continuable_trait(std::forward<_CTy>(functional)));
|
||||
}
|
||||
|
||||
template<typename Current, typename First, typename... Rest>
|
||||
struct multiple_result_maker;
|
||||
|
||||
template<typename... Previous, typename Last>
|
||||
struct multiple_result_maker<fu::identity<Previous...>, Last>
|
||||
{
|
||||
// typedef decltype(correct(std::declval<typename std::decay<Last>::type>())) corrected_t;
|
||||
|
||||
/*
|
||||
typedef typename concat_identities<
|
||||
fu::identity<Previous...>,
|
||||
fu::argument_type_of_t<Last>
|
||||
> type;
|
||||
*/
|
||||
};
|
||||
|
||||
template<typename... Previous, typename First, typename... Rest>
|
||||
struct multiple_result_maker<fu::identity<Previous...>, First, Rest...>
|
||||
{
|
||||
/*
|
||||
typedef typename multiple_result_maker<
|
||||
typename concat_identities<
|
||||
fu::identity<Previous...>,
|
||||
fu::argument_type_of_t<First>
|
||||
>,
|
||||
Rest...
|
||||
> type;
|
||||
*/
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
48
test.cpp
48
test.cpp
@ -25,6 +25,15 @@ enum SpellCastResult
|
||||
template<typename T>
|
||||
using Optional = boost::optional<T>;
|
||||
|
||||
Continuable<> Log(std::string const& message)
|
||||
{
|
||||
return make_continuable([=](Callback<>&& callback)
|
||||
{
|
||||
std::cout << message << std::endl;
|
||||
callback();
|
||||
});
|
||||
}
|
||||
|
||||
// Original method taking an optional callback.
|
||||
void CastSpell(int id, Optional<Callback<SpellCastResult>> const& callback = boost::none)
|
||||
{
|
||||
@ -47,13 +56,10 @@ Continuable<SpellCastResult> CastSpellPromise(int id)
|
||||
// Void instant returning continuable promise for testing purposes
|
||||
Continuable<> TrivialPromise(std::string const& msg = "")
|
||||
{
|
||||
return make_continuable([=](Callback<>&& callback)
|
||||
return Log(msg).then(make_continuable([=](Callback<>&& callback)
|
||||
{
|
||||
if (!msg.empty())
|
||||
std::cout << msg << std::endl;
|
||||
|
||||
callback();
|
||||
});
|
||||
}));
|
||||
}
|
||||
|
||||
Continuable<bool> Validate()
|
||||
@ -84,6 +90,7 @@ int main(int /*argc*/, char** /*argv*/)
|
||||
std::cout << "Pause a callback (void test) " << std::endl;
|
||||
})
|
||||
.then(Validate())
|
||||
.then(TrivialPromise("huhu"))
|
||||
.then(CastSpellPromise(3))
|
||||
.then(CastSpellPromise(4))
|
||||
.then(CastSpellPromise(5))
|
||||
@ -110,6 +117,7 @@ int main(int /*argc*/, char** /*argv*/)
|
||||
)
|
||||
.then([]
|
||||
{
|
||||
std::cout << "Finished" << std::endl;
|
||||
});
|
||||
|
||||
//Continuable<bool> cb = make_continuable([](Callback<bool>&& callback)
|
||||
@ -222,34 +230,12 @@ int main(int /*argc*/, char** /*argv*/)
|
||||
//// Here we go
|
||||
//entry();
|
||||
|
||||
/*
|
||||
auto testaiasj = remove_void_trait([]
|
||||
{
|
||||
|
||||
});
|
||||
detail::functional_traits<>::multiple_result_maker<
|
||||
fu::identity<>,
|
||||
|
||||
*/
|
||||
std::function<Continuable<int>>
|
||||
|
||||
/*
|
||||
auto testres = Continuable<>::remove_void_trait([]
|
||||
{
|
||||
});
|
||||
*/
|
||||
|
||||
auto test1 = detail::functional_traits<>::correct([]
|
||||
{
|
||||
});
|
||||
|
||||
auto test2 = detail::functional_traits<>::correct([]
|
||||
{
|
||||
return make_continuable([](Callback<int, int>&& callback)
|
||||
{
|
||||
|
||||
callback(1, 2);
|
||||
});
|
||||
});
|
||||
|
||||
auto test3 = detail::functional_traits<>::correct(make_continuable());
|
||||
> test282;
|
||||
|
||||
std::cout << "ok" << std::endl;
|
||||
return 0;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user