2945. Order of template parameters in optional comparisons

Section: 22.5.8 [optional.comp.with.t] Status: C++20 Submitter: Jonathan Wakely Opened: 2017-03-13 Last modified: 2021-06-06

Priority: 2

View all other issues in [optional.comp.with.t].

View all issues with C++20 status.

Discussion:

LWG 2934 added an additional template parameter to the comparison operators for std::optional, but the ones that compare U with optional<T> have the parameters backwards compared to the function parameters:

template <class T, class U>
constexpr bool operator==(const U&, const optional<T>&);

Ville confirmed there's no particular reason for this, it's just how he wrote the proposed resolution, but as this has normative effect we should consider if we really want the template parameters and function parameters to be in different orders or not.

[2017-07-13, Casey Carter provides wording]

[2016-07, Toronto Thursday night issues processing]

Status to Ready

Proposed resolution:

This wording is relative to N4659.

  1. Modify 22.5.2 [optional.syn], <optional> synopsis, as indicated:

    //  [optional.comp_with_t], comparison with T
    template <class T, class U> constexpr bool operator==(const optional<T>&, const U&);
    template <class T, class U> constexpr bool operator==(const UT&, const optional<TU>&);
    template <class T, class U> constexpr bool operator!=(const optional<T>&, const U&);
    template <class T, class U> constexpr bool operator!=(const UT&, const optional<TU>&);
    template <class T, class U> constexpr bool operator<(const optional<T>&, const U&);
    template <class T, class U> constexpr bool operator<(const UT&, const optional<TU>&);
    template <class T, class U> constexpr bool operator<=(const optional<T>&, const U&);
    template <class T, class U> constexpr bool operator<=(const UT&, const optional<TU>&);
    template <class T, class U> constexpr bool operator>(const optional<T>&, const U&);
    template <class T, class U> constexpr bool operator>(const UT&, const optional<TU>&);
    template <class T, class U> constexpr bool operator>=(const optional<T>&, const U&);
    template <class T, class U> constexpr bool operator>=(const UT&, const optional<TU>&);
    
  2. Modify [optional.comp_with_t] as indicated:

    template <class T, class U> constexpr bool operator==(const UT& v, const optional<TU>& x);
    

    -3- […]

    […]

    template <class T, class U> constexpr bool operator!=(const UT& v, const optional<TU>& x);
    

    -7- […]

    […]

    template <class T, class U> constexpr bool operator<(const UT& v, const optional<TU>& x);
    

    -11- […]

    […]

    template <class T, class U> constexpr bool operator<=(const UT& v, const optional<TU>& x);
    

    -15- […]

    […]

    template <class T, class U> constexpr bool operator>(const UT& v, const optional<TU>& x);
    

    -19- […]

    […]

    template <class T, class U> constexpr bool operator>=(const UT& v, const optional<TU>& x);
    

    -23- […]

    […]