Date
2024-04-02.10:29:12
Message id
14032

Content

Proposed resolution:

This wording is relative to N4950.

  1. Modify [string.view.synop], header <string_view> synopsis, as indicated:

    […]
    // [string.view.comparison], non-member comparison functions
    template<class charT, class traits>
      constexpr bool operator==(basic_string_view<charT, traits> x,
                                type_identity_t<basic_string_view<charT, traits>> y) noexcept;
    
    template<class charT, class traits>
      constexpr see below operator<=>(basic_string_view<charT, traits> x,
                                      type_identity_t<basic_string_view<charT, traits>> y) noexcept;
    
    // see [string.view.comparison], sufficient additional overloads of comparison functions
    […]
    
  2. Modify [string.view.comparison] as indicated:

    -1- Let S be basic_string_view<charT, traits>, and sv be an instance of S. Implementations shall provide sufficient additional overloads marked constexpr and noexcept so that an object t with an implicit conversion to S can be compared according to Table 81 [tab:string.view.comparison.overloads].

    Table 81: Additional basic_string_view comparison overloads [tab:string.view.comparison.overloads]
    Expression Equivalent to
    t == sv S(t) == sv
    sv == t sv == S(t)
    t != sv S(t) != sv
    sv != t sv != S(t)
    t < sv S(t) < sv
    sv < t sv < S(t)
    t > sv S(t) > sv
    sv > t sv > S(t)
    t <= sv S(t) <= sv
    sv <= t sv <= S(t)
    t >= sv S(t) >= sv
    sv >= t sv >= S(t)
    t <=> sv S(t) <=> sv
    sv <=> t sv <=> S(t)

    [Example 1: A sample conforming implementation for operator== would be:

    template<class charT, class traits>
      constexpr bool operator==(basic_string_view<charT, traits> lhs,
                                basic_string_view<charT, traits> rhs) noexcept {
        return lhs.compare(rhs) == 0;
      }
    template<class charT, class traits>
      constexpr bool operator==(basic_string_view<charT, traits> lhs,
                                type_identity_t<basic_string_view<charT, traits>> rhs) noexcept {
        return lhs.compare(rhs) == 0;
      }
    

    end example]

    template<class charT, class traits>
      constexpr bool operator==(basic_string_view<charT, traits> lhs,
                                type_identity_t<basic_string_view<charT, traits>> rhs) noexcept;
    
    

    -2- Returns: lhs.compare(rhs) == 0.

    template<class charT, class traits>
      constexpr see below operator<=>(basic_string_view<charT, traits> lhs,
                                      type_identity_t<basic_string_view<charT, traits>> rhs) noexcept;
    

    -3- Let R denote the type traits::comparison_category if that qualified-id is valid and denotes a type ([temp.deduct]), otherwise R is weak_ordering.

    -4- Mandates: R denotes a comparison category type ([cmp.categories]).

    -5- Returns: static_cast<R>(lhs.compare(rhs) <=> 0).

    [Note: The usage of type_identity_t as parameter ensures that an object of type basic_string_view<charT, traits> can always be compared with an object of a type T with an implicit conversion to basic_string_view<charT, traits>, and vice versa, as per [over.match.oper]. — end note]