mirror of
https://github.com/Naios/continuable.git
synced 2025-12-07 17:26:47 +08:00
More work on the hint calculation for all and seq compositions
This commit is contained in:
parent
c4cdb3c3b0
commit
6e1350086e
@ -179,7 +179,7 @@ struct all_hint_deducer {
|
|||||||
template <typename First, typename Second, typename... Args>
|
template <typename First, typename Second, typename... Args>
|
||||||
static constexpr auto
|
static constexpr auto
|
||||||
deduce(hints::signature_hint_tag<First, Second, Args...>) {
|
deduce(hints::signature_hint_tag<First, Second, Args...>) {
|
||||||
return std::make_tuple(First{}, Second{}, Args{}...);
|
return spread_this(First{}, Second{}, Args{}...);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <
|
template <
|
||||||
@ -190,8 +190,13 @@ struct all_hint_deducer {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Converts the given argument to a tuple if it isn't a tuple already
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
|
struct is_tuple : std::false_type {};
|
||||||
|
template <typename... T>
|
||||||
|
struct is_tuple<std::tuple<T...>> : std::true_type {};
|
||||||
|
|
||||||
|
/// Converts the given argument to a tuple if it isn't a tuple already
|
||||||
|
template <typename T, std::enable_if_t<!is_tuple<T>::value>* = nullptr>
|
||||||
constexpr auto tupelize(T&& arg) {
|
constexpr auto tupelize(T&& arg) {
|
||||||
return std::make_tuple(std::forward<T>(arg));
|
return std::make_tuple(std::forward<T>(arg));
|
||||||
}
|
}
|
||||||
@ -209,26 +214,23 @@ constexpr auto flatten(T&& tuple) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
struct convert_to_hint {
|
constexpr auto deduce_from_pack(traits::identity<void>)
|
||||||
template <typename... T>
|
-> hints::signature_hint_tag<>;
|
||||||
constexpr auto operator()(T...) -> hints::signature_hint_tag<T...>;
|
template <typename... T>
|
||||||
};
|
constexpr auto deduce_from_pack(traits::identity<std::tuple<T...>>)
|
||||||
constexpr auto deduce_from_pack(traits::identity<void>) {
|
-> hints::signature_hint_tag<T...>;
|
||||||
return hints::signature_hint_tag<>{};
|
template <typename T, std::enable_if_t<!is_tuple<T>::value>* = nullptr>
|
||||||
}
|
constexpr auto deduce_from_pack(traits::identity<T>)
|
||||||
template <typename T>
|
-> hints::signature_hint_tag<T>;
|
||||||
constexpr auto deduce_from_pack(traits::identity<T>) {
|
|
||||||
return decltype(
|
|
||||||
traits::unpack(flatten(std::declval<T>()), convert_to_hint{})){};
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename Composition>
|
template <typename Composition>
|
||||||
constexpr auto deduce_hint(Composition&& composition) {
|
constexpr auto deduce_hint(Composition&& /*composition*/) {
|
||||||
using deduced_t = decltype(
|
using deduced_t =
|
||||||
map_pack(all_hint_deducer{}, std::forward<Composition>(composition)));
|
decltype(map_pack(all_hint_deducer{}, std::declval<Composition>()));
|
||||||
|
|
||||||
// We must guard deduced_t against to be void since this represents an
|
// We must guard deduced_t against to be void since this represents an
|
||||||
// empty signature hint.
|
// empty signature hint.
|
||||||
return deduce_from_pack(traits::identity<deduced_t>{});
|
return decltype(deduce_from_pack(traits::identity<deduced_t>{})){};
|
||||||
}
|
}
|
||||||
} // namespace all
|
} // namespace all
|
||||||
|
|
||||||
|
|||||||
@ -215,6 +215,7 @@ constexpr auto map_spread(C&& callable, T&&... args)
|
|||||||
-> decltype(apply_spread_impl(is_any_spread_t<T...>{},
|
-> decltype(apply_spread_impl(is_any_spread_t<T...>{},
|
||||||
std::forward<C>(callable),
|
std::forward<C>(callable),
|
||||||
std::forward<T>(args)...)) {
|
std::forward<T>(args)...)) {
|
||||||
|
|
||||||
// Check whether any of the args is a detail::flatted_tuple_t,
|
// Check whether any of the args is a detail::flatted_tuple_t,
|
||||||
// if not, use the linear called version for better
|
// if not, use the linear called version for better
|
||||||
// compilation speed.
|
// compilation speed.
|
||||||
|
|||||||
@ -27,6 +27,7 @@
|
|||||||
|
|
||||||
#include <continuable/continuable.hpp>
|
#include <continuable/continuable.hpp>
|
||||||
|
|
||||||
|
/*
|
||||||
static cti::continuable<std::string> http_request(std::string url) {
|
static cti::continuable<std::string> http_request(std::string url) {
|
||||||
return [url = std::move(url)](cti::promise<std::string> promise) {
|
return [url = std::move(url)](cti::promise<std::string> promise) {
|
||||||
if (false) {
|
if (false) {
|
||||||
@ -118,6 +119,7 @@ void old() {
|
|||||||
// ...
|
// ...
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
int main(int, char**) {
|
int main(int, char**) {
|
||||||
using namespace cti::detail;
|
using namespace cti::detail;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user