NVIDIA / stdexec

`std::execution`, the proposed C++ framework for asynchronous and parallel programming.
Apache License 2.0
1.56k stars 159 forks source link

clarification of `receiver` concept and `receiver_of` concept #351

Closed huixie90 closed 2 years ago

huixie90 commented 2 years ago

The receiver concept gives the flexibility to specify the error type with expcetion_ptr being the default

template<class T, class E = exception_ptr>
concept receiver = ...

But the receiver_of concept forces to use expcetion_ptr as the error type

template<class T, class... An>
concept receiver_of =
  receiver<T> && ...

Is this by design and what is the rationale behind this inconsistency?

ericniebler commented 2 years ago

This is intentional, although not all the authors of P2300 agree about this. The intent is that all receivers support exception_ptr as an error type. A function such as the following:

template <receiver_of<int> R>
void tag_invoke(connect_t, my_sender const&, R&&);

... is constrained to accept a receiver that accepts an int as a value and an exception_ptr as an error. If a function is going to send another kind of error -- say, error_code -- it would look like this:

template <receiver_of<int> R>
  requires receiver<R, error_code>
void tag_invoke(connect_t, my_sender const&, R&&);

That receiver type must accept both exception_ptr and error_code as errors.