mirror of
https://github.com/Naios/continuable.git
synced 2026-02-07 02:09:46 +08:00
Use new types instead of aliases for type erasure
* Makes compiler output much more readable
This commit is contained in:
parent
d4cb7dd7b3
commit
1cbfcbea6d
@ -41,27 +41,45 @@ namespace cti {
|
||||
/// cti::promise promise\endlink facility for type erasure.
|
||||
/// \{
|
||||
|
||||
// clang-format off
|
||||
namespace detail {
|
||||
/// A function which isn't size adjusted and move only
|
||||
template<std::size_t, typename... Args>
|
||||
using unique_function_adapter = fu2::unique_function<Args...>;
|
||||
/// A type erasure which isn't size adjusted and move only
|
||||
template <std::size_t, typename... Args>
|
||||
class type_erasure : public fu2::unique_function<Args...> {
|
||||
public:
|
||||
using fu2::unique_function<Args...>::unique_function;
|
||||
using fu2::unique_function<Args...>::operator=;
|
||||
using fu2::unique_function<Args...>::operator();
|
||||
};
|
||||
|
||||
/// A function which is size adjusted and move only
|
||||
template<std::size_t Size, typename... Args>
|
||||
using unique_function_adjustable = fu2::function_base<true, false, Size,
|
||||
true, false, Args...>;
|
||||
template <std::size_t Size, typename... Args>
|
||||
class sized_type_erasure
|
||||
: public fu2::function_base<true, false, Size, true, false, Args...> {
|
||||
|
||||
public:
|
||||
using fu2::function_base<true, false, Size, //
|
||||
true, false, Args...>::function_base;
|
||||
using fu2::function_base<true, false, Size, //
|
||||
true, false, Args...>::operator=;
|
||||
using fu2::function_base<true, false, Size, //
|
||||
true, false, Args...>::operator();
|
||||
};
|
||||
|
||||
/// We adjust the internal capacity of the outer function wrapper so
|
||||
/// we don't have to allocate twice when using `continuable<...>`.
|
||||
template<typename... Args>
|
||||
using unique_trait_of = continuable_trait<
|
||||
unique_function_adapter,
|
||||
unique_function_adjustable,
|
||||
Args...
|
||||
>;
|
||||
template <typename... Args>
|
||||
using unique_trait_of = continuable_trait< //
|
||||
type_erasure, sized_type_erasure,
|
||||
Args... //
|
||||
>;
|
||||
|
||||
/// A type erasure for work objects
|
||||
using work = fu2::unique_function<void()>;
|
||||
class work_type_erasure : public fu2::unique_function<void()> {
|
||||
public:
|
||||
using fu2::unique_function<void()>::unique_function;
|
||||
using fu2::unique_function<void()>::operator=;
|
||||
using fu2::unique_function<void()>::operator();
|
||||
};
|
||||
} // namespace detail
|
||||
|
||||
/// Defines a non-copyable continuation type which uses the
|
||||
@ -69,29 +87,23 @@ using work = fu2::unique_function<void()>;
|
||||
///
|
||||
/// Usable like: `continuable<int, float>`
|
||||
template <typename... Args>
|
||||
using continuable = typename detail::unique_trait_of<
|
||||
Args...
|
||||
>::continuable;
|
||||
using continuable = typename detail::unique_trait_of<Args...>::continuable;
|
||||
|
||||
/// Defines a non-copyable promise type which is using the
|
||||
/// function2 backend for type erasure.
|
||||
///
|
||||
/// Usable like: `promise<int, float>`
|
||||
template <typename... Args>
|
||||
using promise = typename detail::unique_trait_of<
|
||||
Args...
|
||||
>::promise;
|
||||
using promise = typename detail::unique_trait_of<Args...>::promise;
|
||||
|
||||
/// Defines a non-copyable type erasure which is capable of carrying
|
||||
/// callable objects passed to executors.
|
||||
///
|
||||
/// \since 4.0.0
|
||||
using work = detail::work;
|
||||
using work = detail::work_type_erasure;
|
||||
|
||||
// TODO channel
|
||||
// TODO sink
|
||||
|
||||
// clang-format on
|
||||
/// \}
|
||||
} // namespace cti
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user