mirror of
https://github.com/Naios/continuable.git
synced 2026-02-08 18:56:40 +08:00
some work
This commit is contained in:
parent
0ab2ac076c
commit
c4ffc8249e
@ -23,31 +23,46 @@
|
|||||||
|
|
||||||
namespace detail
|
namespace detail
|
||||||
{
|
{
|
||||||
|
template<typename _Cain, typename _Proxy>
|
||||||
|
struct ContinuableState;
|
||||||
|
|
||||||
|
template<typename... _Cain, typename _Proxy>
|
||||||
|
struct ContinuableState<std::tuple<_Cain...>, _Proxy>
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef ContinuableState<std::tuple<>, void> EmptyContinuableState;
|
||||||
|
|
||||||
} // detail
|
} // detail
|
||||||
|
|
||||||
template <typename... Args>
|
template<typename _CTy, typename _State = detail::EmptyContinuableState>
|
||||||
struct ContinuableState
|
|
||||||
/*
|
|
||||||
;
|
|
||||||
template <typename... Args>
|
|
||||||
struct ContinuableState<Args...>
|
|
||||||
*/
|
|
||||||
{
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename _CTy, typename _State = ContinuableState<>>
|
|
||||||
class Continuable;
|
class Continuable;
|
||||||
|
|
||||||
template <typename... _ATy, typename _State>
|
template<typename... _ATy, typename _State>
|
||||||
class Continuable<std::function<void(_ATy...)>, _State>
|
class Continuable<std::function<void(_ATy...)>, _State>
|
||||||
{
|
{
|
||||||
|
/// Corrects void return types from functional types which should be Continuable<Callback<>>
|
||||||
|
template<typename _RTy>
|
||||||
|
struct convert_void_to_continuable;
|
||||||
|
|
||||||
|
template<>
|
||||||
|
struct convert_void_to_continuable<void>
|
||||||
|
{
|
||||||
|
typedef Continuable<Callback<>> type;
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename... _CArgs>
|
||||||
|
struct convert_void_to_continuable<Continuable<_CArgs...>>
|
||||||
|
{
|
||||||
|
typedef Continuable<_CArgs...> type;
|
||||||
|
};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
typedef std::function<void(Callback<_ATy...>&&)> ForwardFunction;
|
typedef std::function<void(Callback<_ATy...>&&)> ForwardFunction;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Functional which expects a callback that is inserted from the Continuable
|
/// Functional which expects a callback that is inserted from the Continuable
|
||||||
// to chain everything together
|
/// to chain everything together
|
||||||
ForwardFunction _callback_insert;
|
ForwardFunction _callback_insert;
|
||||||
|
|
||||||
bool _released;
|
bool _released;
|
||||||
@ -58,11 +73,11 @@ private:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
/// Deleted copy construct
|
/// Deleted copy construct
|
||||||
template <typename _RCTy, typename _RState>
|
template<typename _RCTy, typename _RState>
|
||||||
Continuable(Continuable<_RCTy, _RState> const&) = delete;
|
Continuable(Continuable<_RCTy, _RState> const&) = delete;
|
||||||
|
|
||||||
/// Move construct
|
/// Move construct
|
||||||
template <typename _RCTy, typename _RState>
|
template<typename _RCTy, typename _RState>
|
||||||
Continuable(Continuable<_RCTy, _RState>&& right)
|
Continuable(Continuable<_RCTy, _RState>&& right)
|
||||||
: _released(right._released)
|
: _released(right._released)
|
||||||
{
|
{
|
||||||
@ -85,11 +100,11 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Deleted copy assign
|
/// Deleted copy assign
|
||||||
template <typename _RCTy, typename _RState>
|
template<typename _RCTy, typename _RState>
|
||||||
Continuable& operator= (Continuable<_RCTy, _RState> const&) = delete;
|
Continuable& operator= (Continuable<_RCTy, _RState> const&) = delete;
|
||||||
|
|
||||||
/// Move construct assign
|
/// Move construct assign
|
||||||
template <typename _RCTy, typename _RState>
|
template<typename _RCTy, typename _RState>
|
||||||
Continuable& operator= (Continuable<_RCTy, _RState>&& right)
|
Continuable& operator= (Continuable<_RCTy, _RState>&& right)
|
||||||
{
|
{
|
||||||
_released = right._released;
|
_released = right._released;
|
||||||
@ -98,13 +113,23 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO Accept only correct callbacks
|
// TODO Accept only correct callbacks
|
||||||
template <typename _CTy>
|
template<typename _CTy>
|
||||||
Continuable<Callback<_ATy...>> then(_CTy&&)
|
Continuable<Callback<_ATy...>> then(_CTy&&)
|
||||||
{
|
{
|
||||||
// TODO Transmute the returned callback here.
|
// TODO Transmute the returned callback here.
|
||||||
return Continuable<Callback<_ATy...>>(std::move(*this));
|
return Continuable<Callback<_ATy...>>(std::move(*this));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
// TODO Accept only correct callbacks
|
||||||
|
template<typename... _CTy>
|
||||||
|
Continuable<Callback<_ATy...>> all(_CTy&&...)
|
||||||
|
{
|
||||||
|
// TODO Transmute the returned callback here.
|
||||||
|
return Continuable<Callback<_ATy...>>(std::move(*this));
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
/// Invalidates the Continuable
|
/// Invalidates the Continuable
|
||||||
Continuable& invalidate()
|
Continuable& invalidate()
|
||||||
{
|
{
|
||||||
@ -115,10 +140,10 @@ public:
|
|||||||
|
|
||||||
namespace detail
|
namespace detail
|
||||||
{
|
{
|
||||||
template <typename _FTy, typename _RTy, typename... _ATy>
|
template<typename _FTy, typename _RTy, typename... _ATy>
|
||||||
struct ContinuableFactory;
|
struct ContinuableFactory;
|
||||||
|
|
||||||
template <typename _FTy, typename _RTy, typename... _ATy>
|
template<typename _FTy, typename _RTy, typename... _ATy>
|
||||||
struct ContinuableFactory<_FTy, _RTy, ::fu::identity<std::function<void(_ATy...)>&&>>
|
struct ContinuableFactory<_FTy, _RTy, ::fu::identity<std::function<void(_ATy...)>&&>>
|
||||||
{
|
{
|
||||||
static auto CreateFrom(_FTy&& functional)
|
static auto CreateFrom(_FTy&& functional)
|
||||||
@ -129,7 +154,7 @@ namespace detail
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename _FTy>
|
template<typename _FTy>
|
||||||
using continuable_factory_t = ContinuableFactory<
|
using continuable_factory_t = ContinuableFactory<
|
||||||
_FTy, ::fu::return_type_of_t<_FTy>, ::fu::argument_type_of_t<_FTy>>;
|
_FTy, ::fu::return_type_of_t<_FTy>, ::fu::argument_type_of_t<_FTy>>;
|
||||||
|
|
||||||
@ -143,7 +168,7 @@ namespace detail
|
|||||||
/// /* Continue here */
|
/// /* Continue here */
|
||||||
/// callback(5);
|
/// callback(5);
|
||||||
/// });
|
/// });
|
||||||
template <typename _FTy>
|
template<typename _FTy>
|
||||||
inline auto make_continuable(_FTy&& functional)
|
inline auto make_continuable(_FTy&& functional)
|
||||||
-> decltype(detail::continuable_factory_t<_FTy>::CreateFrom(std::declval<_FTy>()))
|
-> decltype(detail::continuable_factory_t<_FTy>::CreateFrom(std::declval<_FTy>()))
|
||||||
{
|
{
|
||||||
|
|||||||
@ -11,13 +11,13 @@
|
|||||||
/*
|
/*
|
||||||
struct ProtoContinueable
|
struct ProtoContinueable
|
||||||
{
|
{
|
||||||
template <typename Callback>
|
template<typename Callback>
|
||||||
ProtoContinueable then(Callback&& callback)
|
ProtoContinueable then(Callback&& callback)
|
||||||
{
|
{
|
||||||
return ProtoContinueable();
|
return ProtoContinueable();
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Container>
|
template<typename Container>
|
||||||
ProtoContinueable weak(Container& container)
|
ProtoContinueable weak(Container& container)
|
||||||
{
|
{
|
||||||
return ProtoContinueable();
|
return ProtoContinueable();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user