More work on the hint calculation for all and seq compositions

This commit is contained in:
Denis Blank 2018-02-27 17:18:52 +01:00
parent c4cdb3c3b0
commit 6e1350086e
3 changed files with 23 additions and 18 deletions

View File

@ -179,7 +179,7 @@ struct all_hint_deducer {
template <typename First, typename Second, typename... Args>
static constexpr auto
deduce(hints::signature_hint_tag<First, Second, Args...>) {
return std::make_tuple(First{}, Second{}, Args{}...);
return spread_this(First{}, Second{}, Args{}...);
}
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>
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) {
return std::make_tuple(std::forward<T>(arg));
}
@ -209,26 +214,23 @@ constexpr auto flatten(T&& tuple) {
});
}
struct convert_to_hint {
template <typename... T>
constexpr auto operator()(T...) -> hints::signature_hint_tag<T...>;
};
constexpr auto deduce_from_pack(traits::identity<void>) {
return hints::signature_hint_tag<>{};
}
template <typename T>
constexpr auto deduce_from_pack(traits::identity<T>) {
return decltype(
traits::unpack(flatten(std::declval<T>()), convert_to_hint{})){};
}
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, std::enable_if_t<!is_tuple<T>::value>* = nullptr>
constexpr auto deduce_from_pack(traits::identity<T>)
-> hints::signature_hint_tag<T>;
template <typename Composition>
constexpr auto deduce_hint(Composition&& composition) {
using deduced_t = decltype(
map_pack(all_hint_deducer{}, std::forward<Composition>(composition)));
constexpr auto deduce_hint(Composition&& /*composition*/) {
using deduced_t =
decltype(map_pack(all_hint_deducer{}, std::declval<Composition>()));
// We must guard deduced_t against to be void since this represents an
// empty signature hint.
return deduce_from_pack(traits::identity<deduced_t>{});
return decltype(deduce_from_pack(traits::identity<deduced_t>{})){};
}
} // namespace all

View File

@ -215,6 +215,7 @@ constexpr auto map_spread(C&& callable, T&&... args)
-> decltype(apply_spread_impl(is_any_spread_t<T...>{},
std::forward<C>(callable),
std::forward<T>(args)...)) {
// Check whether any of the args is a detail::flatted_tuple_t,
// if not, use the linear called version for better
// compilation speed.

View File

@ -27,6 +27,7 @@
#include <continuable/continuable.hpp>
/*
static cti::continuable<std::string> http_request(std::string url) {
return [url = std::move(url)](cti::promise<std::string> promise) {
if (false) {
@ -118,6 +119,7 @@ void old() {
// ...
});
}
*/
int main(int, char**) {
using namespace cti::detail;