Open1
`std::execution` まわり
forwarding_query
が sender attributes やら environment やらの性質を引き継ぐか否かを決定するのは分かったけど何でそんなものが用意されているんだろうか?
struct my_query_object_t {
constexpr bool query(std::forwarding_query_t) { return false; }
template <class Env>
decltype(auto) operator()(const Env& env) const noexcept {
return env.query(my_query_object_t{});
}
};
inline constexpr my_query_object_t my_query_object{};
struct my_receiver {
using receiver_concept = std::execution::receiver_t;
void set_value(auto&&...) const noexcept {}
void set_error(auto&&) const noexcept {}
void set_stopped() const noexcept {}
struct env {
std::allocator<void> query(std::get_allocator_t) const noexcept { return {}; }
int query(my_query_object_t) const noexcept { return 42; }
};
env get_env() const noexcept { return {}; }
};
static_assert( std::forwarding_query(std::get_allocator));
static_assert(not std::forwarding_query( my_query_object));
my_receiver recv;
auto env = std::execution::get_env(recv);
auto alloc = std::get_allocator(env); // well-formed
auto my_value = my_query_object(env); // well-formed
auto env2 = FWD-ENV(env); // FWD-ENV を通す
auto alloc2 = std::get_allocator(env2); // well-formed
auto my_value2 = my_query_object(env2); // !!! ill-formed !!!