Skip to content

receiver/sender constraint that checks get_env(rcvr) is valid redundantly checks the result is queryable #322

@lewissbaker

Description

@lewissbaker
Collaborator

The concept for receiver and sender both check that get_env(o) is valid and returns a type that satisfies queryable. e.g.

// [exec.recv.concepts]
template<class Rcvr>
    concept receiver =
      derived_from<typename remove_cvref_t<Rcvr>::receiver_concept, receiver_t> &&
      requires(const remove_cvref_t<Rcvr>& rcvr) {
        { get_env(rcvr) } -> queryable;
      } &&
      move_constructible<remove_cvref_t<Rcvr>> &&       // rvalues are movable, and
      constructible_from<remove_cvref_t<Rcvr>, Rcvr>;   // lvalues are copyable

However, the get_env CPO itself already mandates that the result of the get_env call satisfies queryable, so the additional check in the receiver concept for this seems redundant.

Can we simplify the receiver concept to just check that get_env(rcvr) is valid?

Note that #321 is also exploring whether we need to check get_env(rcvr) at all, since it has an unconstrained fallback overload that should match any receiver.

Activity

lewissbaker

lewissbaker commented on Feb 3, 2025

@lewissbaker
CollaboratorAuthor

Further, the requires clause could be simplified from requires(const remove_cvref_t<Rcvr>& rcvr) to just requires(const Rcvr& rcvr) as reference-collapsing will result in the same parameter type.

And the derived_from constraint could be simplified to use remove_ref_t instead of remove_cvref_t when computing the receiver_concept type as the cv-qualification does not need to be stripped to get access to the ::receiver_concept member.

lewissbaker

lewissbaker commented on Feb 4, 2025

@lewissbaker
CollaboratorAuthor

I suggest simplifying the receiver concept to:

// [exec.recv.concepts]
template<class Rcvr>
    concept receiver =
      derived_from<typename remove_ref_t<Rcvr>::receiver_concept, receiver_t> &&
      requires(const Rcvr& rcvr) {
        get_env(rcvr);
      } &&
      move_constructible<remove_cvref_t<Rcvr>> &&       // rvalues are movable, and
      constructible_from<remove_cvref_t<Rcvr>, Rcvr>;   // lvalues are copyable

and similarly, simplifying the sender concept to:

  template<class Sndr>
    concept sender =
      bool(enable-sender<remove_cvref_t<Sndr>>) &&
      requires (const Sndr& sndr) {
        get_env(sndr);
      } &&
      move_constructible<remove_cvref_t<Sndr>> &&
      constructible_from<remove_cvref_t<Sndr>, Sndr>;
added
bugSomething isn't working
enhancementNew feature or request
and removed
bugSomething isn't working
on Feb 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @lewissbaker

        Issue actions

          receiver/sender constraint that checks `get_env(rcvr)` is valid redundantly checks the result is `queryable` · Issue #322 · cplusplus/sender-receiver