mirror of
https://github.com/Naios/continuable.git
synced 2026-02-08 02:36:40 +08:00
Make the seq dependency only dependent from the aggregate header
This commit is contained in:
parent
a3e995c0ce
commit
3df06820ef
@ -38,6 +38,9 @@ following compilers:
|
|||||||
Although the build is observed with the listed compilers earlier
|
Although the build is observed with the listed compilers earlier
|
||||||
versions might work.
|
versions might work.
|
||||||
|
|
||||||
|
\warning GCC is proven to be slower than Clang in template compilation and
|
||||||
|
thus it is suggested to use Clang instead.
|
||||||
|
|
||||||
\section installation-dependencies Dependencies
|
\section installation-dependencies Dependencies
|
||||||
|
|
||||||
Continuable is a header-only library with one required header-only dependency:
|
Continuable is a header-only library with one required header-only dependency:
|
||||||
|
|||||||
@ -54,7 +54,7 @@ namespace composition {
|
|||||||
/// - value -> value
|
/// - value -> value
|
||||||
/// - single async value -> single value
|
/// - single async value -> single value
|
||||||
/// - multiple async value -> tuple of async values.
|
/// - multiple async value -> tuple of async values.
|
||||||
namespace remapping {
|
namespace aggregated {
|
||||||
/// Guards a type to be default constructible,
|
/// Guards a type to be default constructible,
|
||||||
/// and wraps it into an optional type if it isn't default constructible.
|
/// and wraps it into an optional type if it isn't default constructible.
|
||||||
template <typename T>
|
template <typename T>
|
||||||
@ -220,7 +220,56 @@ void finalize_data(Callback&& callback, Data&& data) {
|
|||||||
std::forward<Callback>(callback),
|
std::forward<Callback>(callback),
|
||||||
std::forward<Data>(data));
|
std::forward<Data>(data));
|
||||||
}
|
}
|
||||||
} // namespace remapping
|
|
||||||
|
struct all_hint_deducer {
|
||||||
|
static constexpr auto deduce(hints::signature_hint_tag<>) noexcept {
|
||||||
|
return spread_this();
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename First>
|
||||||
|
static constexpr auto deduce(hints::signature_hint_tag<First>) {
|
||||||
|
return unpack_lazy(lazy_value_t<First>{});
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename First, typename Second, typename... Args>
|
||||||
|
static constexpr auto
|
||||||
|
deduce(hints::signature_hint_tag<First, Second, Args...>) {
|
||||||
|
return spread_this(unpack_lazy(lazy_value_t<First>{}),
|
||||||
|
unpack_lazy(lazy_value_t<Second>{}),
|
||||||
|
unpack_lazy(lazy_value_t<Args>{})...);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <
|
||||||
|
typename T,
|
||||||
|
std::enable_if_t<base::is_continuable<std::decay_t<T>>::value>* = nullptr>
|
||||||
|
auto operator()(T&& /*continuable*/) const {
|
||||||
|
return deduce(hints::hint_of(traits::identify<T>{}));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
constexpr auto deduce_from_pack(traits::identity<void>)
|
||||||
|
-> hints::signature_hint_tag<>;
|
||||||
|
template <typename... T>
|
||||||
|
constexpr auto deduce_from_pack(traits::identity<std::tuple<T...>>)
|
||||||
|
-> hints::signature_hint_tag<T...>;
|
||||||
|
template <typename T>
|
||||||
|
constexpr auto deduce_from_pack(traits::identity<T>)
|
||||||
|
-> hints::signature_hint_tag<T>;
|
||||||
|
|
||||||
|
// We must guard the mapped type against to be void since this represents an
|
||||||
|
// empty signature hint.
|
||||||
|
template <typename Composition>
|
||||||
|
constexpr auto deduce_hint(Composition&& /*composition*/) {
|
||||||
|
// Don't change this way since it addresses a GCC compiler bug:
|
||||||
|
// error: extra ';' [-Werror=pedantic]
|
||||||
|
// std::declval<Composition>()))>{})){};
|
||||||
|
using mapped_t =
|
||||||
|
decltype(map_pack(all_hint_deducer{}, std::declval<Composition>()));
|
||||||
|
using deduced_t = decltype(deduce_from_pack(traits::identity<mapped_t>{}));
|
||||||
|
return deduced_t{};
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace aggregated
|
||||||
} // namespace composition
|
} // namespace composition
|
||||||
} // namespace detail
|
} // namespace detail
|
||||||
} // namespace cti
|
} // namespace cti
|
||||||
@ -39,7 +39,7 @@
|
|||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
#include <continuable/detail/base.hpp>
|
#include <continuable/detail/base.hpp>
|
||||||
#include <continuable/detail/composition-remapping.hpp>
|
#include <continuable/detail/composition-aggregated.hpp>
|
||||||
#include <continuable/detail/composition.hpp>
|
#include <continuable/detail/composition.hpp>
|
||||||
#include <continuable/detail/hints.hpp>
|
#include <continuable/detail/hints.hpp>
|
||||||
#include <continuable/detail/traits.hpp>
|
#include <continuable/detail/traits.hpp>
|
||||||
@ -49,55 +49,6 @@ namespace cti {
|
|||||||
namespace detail {
|
namespace detail {
|
||||||
namespace composition {
|
namespace composition {
|
||||||
namespace all {
|
namespace all {
|
||||||
struct all_hint_deducer {
|
|
||||||
static constexpr auto deduce(hints::signature_hint_tag<>) noexcept {
|
|
||||||
return spread_this();
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename First>
|
|
||||||
static constexpr auto deduce(hints::signature_hint_tag<First>) {
|
|
||||||
return remapping::unpack_lazy(remapping::lazy_value_t<First>{});
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename First, typename Second, typename... Args>
|
|
||||||
static constexpr auto
|
|
||||||
deduce(hints::signature_hint_tag<First, Second, Args...>) {
|
|
||||||
return spread_this(
|
|
||||||
remapping::unpack_lazy(remapping::lazy_value_t<First>{}),
|
|
||||||
remapping::unpack_lazy(remapping::lazy_value_t<Second>{}),
|
|
||||||
remapping::unpack_lazy(remapping::lazy_value_t<Args>{})...);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <
|
|
||||||
typename T,
|
|
||||||
std::enable_if_t<base::is_continuable<std::decay_t<T>>::value>* = nullptr>
|
|
||||||
auto operator()(T&& /*continuable*/) const {
|
|
||||||
return deduce(hints::hint_of(traits::identify<T>{}));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
constexpr auto deduce_from_pack(traits::identity<void>)
|
|
||||||
-> hints::signature_hint_tag<>;
|
|
||||||
template <typename... T>
|
|
||||||
constexpr auto deduce_from_pack(traits::identity<std::tuple<T...>>)
|
|
||||||
-> hints::signature_hint_tag<T...>;
|
|
||||||
template <typename T>
|
|
||||||
constexpr auto deduce_from_pack(traits::identity<T>)
|
|
||||||
-> hints::signature_hint_tag<T>;
|
|
||||||
|
|
||||||
// We must guard the mapped type against to be void since this represents an
|
|
||||||
// empty signature hint.
|
|
||||||
template <typename Composition>
|
|
||||||
constexpr auto deduce_hint(Composition&& /*composition*/) {
|
|
||||||
// Don't change this way since it addresses a GCC compiler bug:
|
|
||||||
// error: extra ';' [-Werror=pedantic]
|
|
||||||
// std::declval<Composition>()))>{})){};
|
|
||||||
using mapped_t =
|
|
||||||
decltype(map_pack(all_hint_deducer{}, std::declval<Composition>()));
|
|
||||||
using deduced_t = decltype(deduce_from_pack(traits::identity<mapped_t>{}));
|
|
||||||
return deduced_t{};
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Caches the partial results and invokes the callback when all results
|
/// Caches the partial results and invokes the callback when all results
|
||||||
/// are arrived. This class is thread safe.
|
/// are arrived. This class is thread safe.
|
||||||
template <typename Callback, typename Result>
|
template <typename Callback, typename Result>
|
||||||
@ -118,7 +69,7 @@ class result_submitter
|
|||||||
|
|
||||||
// Call the final callback with the cleaned result
|
// Call the final callback with the cleaned result
|
||||||
std::call_once(flag_, [&] {
|
std::call_once(flag_, [&] {
|
||||||
remapping::finalize_data(std::move(callback_), std::move(result_));
|
aggregated::finalize_data(std::move(callback_), std::move(result_));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -185,7 +136,7 @@ template <typename Submitter>
|
|||||||
struct continuable_dispatcher {
|
struct continuable_dispatcher {
|
||||||
std::shared_ptr<Submitter>& submitter;
|
std::shared_ptr<Submitter>& submitter;
|
||||||
|
|
||||||
template <typename Box, std::enable_if_t<remapping::is_continuable_box<
|
template <typename Box, std::enable_if_t<aggregated::is_continuable_box<
|
||||||
std::decay_t<Box>>::value>* = nullptr>
|
std::decay_t<Box>>::value>* = nullptr>
|
||||||
void operator()(Box&& box) const {
|
void operator()(Box&& box) const {
|
||||||
// Retrieve a callback from the submitter and attach it to the continuable
|
// Retrieve a callback from the submitter and attach it to the continuable
|
||||||
@ -199,7 +150,7 @@ template <>
|
|||||||
struct composition_finalizer<composition_strategy_all_tag> {
|
struct composition_finalizer<composition_strategy_all_tag> {
|
||||||
template <typename Composition>
|
template <typename Composition>
|
||||||
static constexpr auto hint() {
|
static constexpr auto hint() {
|
||||||
return decltype(all::deduce_hint(std::declval<Composition>())){};
|
return decltype(aggregated::deduce_hint(std::declval<Composition>())){};
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Finalizes the all logic of a given composition
|
/// Finalizes the all logic of a given composition
|
||||||
@ -209,7 +160,7 @@ struct composition_finalizer<composition_strategy_all_tag> {
|
|||||||
(auto&& callback) mutable {
|
(auto&& callback) mutable {
|
||||||
|
|
||||||
// Create the target result from the composition
|
// Create the target result from the composition
|
||||||
auto result = remapping::box_continuables(std::move(composition));
|
auto result = aggregated::box_continuables(std::move(composition));
|
||||||
|
|
||||||
using submitter_t =
|
using submitter_t =
|
||||||
all::result_submitter<std::decay_t<decltype(callback)>,
|
all::result_submitter<std::decay_t<decltype(callback)>,
|
||||||
|
|||||||
@ -39,8 +39,7 @@
|
|||||||
|
|
||||||
#include <continuable/continuable-traverse-async.hpp>
|
#include <continuable/continuable-traverse-async.hpp>
|
||||||
#include <continuable/detail/base.hpp>
|
#include <continuable/detail/base.hpp>
|
||||||
#include <continuable/detail/composition-all.hpp>
|
#include <continuable/detail/composition-aggregated.hpp>
|
||||||
#include <continuable/detail/composition-remapping.hpp>
|
|
||||||
#include <continuable/detail/traits.hpp>
|
#include <continuable/detail/traits.hpp>
|
||||||
#include <continuable/detail/util.hpp>
|
#include <continuable/detail/util.hpp>
|
||||||
|
|
||||||
@ -93,7 +92,7 @@ public:
|
|||||||
return data_.box;
|
return data_.box;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Box, std::enable_if_t<remapping::is_continuable_box<
|
template <typename Box, std::enable_if_t<aggregated::is_continuable_box<
|
||||||
std::decay_t<Box>>::value>* = nullptr>
|
std::decay_t<Box>>::value>* = nullptr>
|
||||||
bool operator()(async_traverse_visit_tag, Box&& /*box*/) {
|
bool operator()(async_traverse_visit_tag, Box&& /*box*/) {
|
||||||
return false;
|
return false;
|
||||||
@ -121,8 +120,8 @@ public:
|
|||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
void operator()(async_traverse_complete_tag, T&& /*pack*/) {
|
void operator()(async_traverse_complete_tag, T&& /*pack*/) {
|
||||||
return remapping::finalize_data(std::move(data_.callback),
|
return aggregated::finalize_data(std::move(data_.callback),
|
||||||
std::move(data_.box));
|
std::move(data_.box));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
} // namespace seq
|
} // namespace seq
|
||||||
@ -132,9 +131,7 @@ template <>
|
|||||||
struct composition_finalizer<composition_strategy_seq_tag> {
|
struct composition_finalizer<composition_strategy_seq_tag> {
|
||||||
template <typename Composition>
|
template <typename Composition>
|
||||||
static constexpr auto hint() {
|
static constexpr auto hint() {
|
||||||
// The result is the same as in the all composition
|
return decltype(aggregated::deduce_hint(std::declval<Composition>())){};
|
||||||
using all_finalizer = composition_finalizer<composition_strategy_all_tag>;
|
|
||||||
return all_finalizer::hint<Composition>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Finalizes the all logic of a given composition
|
/// Finalizes the all logic of a given composition
|
||||||
@ -143,7 +140,7 @@ struct composition_finalizer<composition_strategy_seq_tag> {
|
|||||||
return [composition = std::forward<Composition>(composition)] // ...
|
return [composition = std::forward<Composition>(composition)] // ...
|
||||||
(auto&& callback) mutable {
|
(auto&& callback) mutable {
|
||||||
|
|
||||||
auto boxed = remapping::box_continuables(std::move(composition));
|
auto boxed = aggregated::box_continuables(std::move(composition));
|
||||||
|
|
||||||
// The data from which the visitor is constructed in-place
|
// The data from which the visitor is constructed in-place
|
||||||
using data_t =
|
using data_t =
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user