mirror of
https://github.com/Naios/continuable.git
synced 2026-02-07 10:19: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.
|
/// cti::promise promise\endlink facility for type erasure.
|
||||||
/// \{
|
/// \{
|
||||||
|
|
||||||
// clang-format off
|
|
||||||
namespace detail {
|
namespace detail {
|
||||||
/// A function which isn't size adjusted and move only
|
/// A type erasure which isn't size adjusted and move only
|
||||||
template<std::size_t, typename... Args>
|
template <std::size_t, typename... Args>
|
||||||
using unique_function_adapter = fu2::unique_function<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
|
/// A function which is size adjusted and move only
|
||||||
template<std::size_t Size, typename... Args>
|
template <std::size_t Size, typename... Args>
|
||||||
using unique_function_adjustable = fu2::function_base<true, false, Size,
|
class sized_type_erasure
|
||||||
true, false, Args...>;
|
: 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 adjust the internal capacity of the outer function wrapper so
|
||||||
/// we don't have to allocate twice when using `continuable<...>`.
|
/// we don't have to allocate twice when using `continuable<...>`.
|
||||||
template<typename... Args>
|
template <typename... Args>
|
||||||
using unique_trait_of = continuable_trait<
|
using unique_trait_of = continuable_trait< //
|
||||||
unique_function_adapter,
|
type_erasure, sized_type_erasure,
|
||||||
unique_function_adjustable,
|
Args... //
|
||||||
Args...
|
>;
|
||||||
>;
|
|
||||||
|
|
||||||
/// A type erasure for work objects
|
/// 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
|
} // namespace detail
|
||||||
|
|
||||||
/// Defines a non-copyable continuation type which uses the
|
/// Defines a non-copyable continuation type which uses the
|
||||||
@ -69,29 +87,23 @@ using work = fu2::unique_function<void()>;
|
|||||||
///
|
///
|
||||||
/// Usable like: `continuable<int, float>`
|
/// Usable like: `continuable<int, float>`
|
||||||
template <typename... Args>
|
template <typename... Args>
|
||||||
using continuable = typename detail::unique_trait_of<
|
using continuable = typename detail::unique_trait_of<Args...>::continuable;
|
||||||
Args...
|
|
||||||
>::continuable;
|
|
||||||
|
|
||||||
/// Defines a non-copyable promise type which is using the
|
/// Defines a non-copyable promise type which is using the
|
||||||
/// function2 backend for type erasure.
|
/// function2 backend for type erasure.
|
||||||
///
|
///
|
||||||
/// Usable like: `promise<int, float>`
|
/// Usable like: `promise<int, float>`
|
||||||
template <typename... Args>
|
template <typename... Args>
|
||||||
using promise = typename detail::unique_trait_of<
|
using promise = typename detail::unique_trait_of<Args...>::promise;
|
||||||
Args...
|
|
||||||
>::promise;
|
|
||||||
|
|
||||||
/// Defines a non-copyable type erasure which is capable of carrying
|
/// Defines a non-copyable type erasure which is capable of carrying
|
||||||
/// callable objects passed to executors.
|
/// callable objects passed to executors.
|
||||||
///
|
///
|
||||||
/// \since 4.0.0
|
/// \since 4.0.0
|
||||||
using work = detail::work;
|
using work = detail::work_type_erasure;
|
||||||
|
|
||||||
// TODO channel
|
// TODO channel
|
||||||
// TODO sink
|
// TODO sink
|
||||||
|
|
||||||
// clang-format on
|
|
||||||
/// \}
|
/// \}
|
||||||
} // namespace cti
|
} // namespace cti
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user