3254. Strike stop_token's operator!=

Section: 32.3.4 [stoptoken] Status: C++20 Submitter: Casey Carter Opened: 2019-08-06 Last modified: 2021-02-25

Priority: 0

View all issues with C++20 status.

Discussion:

In the shiny new world of the future, we need not declare overloads of operator!= that return !(x == y); the rewrite rule in 12.2.2.3 [over.match.oper] para 3.4.3 achieves the same effect. Consequently, we should not declare such unnecessary operator!= overloads. The synopsis of class stop_token in 32.3.4 [stoptoken] declares exactly such an operator!= friend which should be struck.

[01-2020 Moved to Tentatively Ready after 5 positive votes on the reflector.]

Proposed resolution:

This wording is relative to N4830.

  1. Modify 32.3.4 [stoptoken], class stop_token synopsis, as indicated:

    namespace std {
      class stop_token {
      public:  
        […]
        [[nodiscard]] friend bool operator==(const stop_token& lhs, const stop_token& rhs) noexcept;
        [[nodiscard]] friend bool operator!=(const stop_token& lhs, const stop_token& rhs) noexcept;
        friend void swap(stop_token& lhs, stop_token& rhs) noexcept;
      };
    }
    
  2. Modify [stoptoken.cmp] and [stoptoken.special] as indicated:

    32.3.3.3 Non-member functionsComparisons [stoptoken.nonmemberscmp]

    [[nodiscard]] bool operator==(const stop_token& lhs, const stop_token& rhs) noexcept;
    

    -1- Returns: true if lhs and rhs have ownership of the same stop state or if both lhs and rhs do not have ownership of a stop state; otherwise false.

    [[nodiscard]] bool operator!=(const stop_token& lhs, const stop_token& rhs) noexcept;
    

    -2- Returns: !(lhs==rhs).

    32.3.3.4 Specialized algorithms [stoptoken.special]

    friend void swap(stop_token& x, stop_token& y) noexcept;
    

    -1- Effects: Equivalent to: x.swap(y).