Title
Order of template parameters in optional comparisons
Status
c++20
Section
[optional.comp.with.t]
Submitter
Jonathan Wakely

Created on 2017-03-13.00:00:00 last changed 38 months ago

Messages

Date: 2017-07-16.20:11:05

Proposed resolution:

This wording is relative to N4659.

  1. Modify [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- […]

    […]

Date: 2017-07-16.20:11:05

[ 2016-07, Toronto Thursday night issues processing ]

Status to Ready

Date: 2017-07-15.00:00:00

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

Date: 2017-03-13.00:00:00

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.

History
Date User Action Args
2021-02-25 10:48:01adminsetstatus: wp -> c++20
2017-11-13 19:01:36adminsetstatus: voting -> wp
2017-10-17 18:34:55adminsetstatus: ready -> voting
2017-07-16 20:11:05adminsetmessages: + msg9417
2017-07-16 20:11:05adminsetstatus: new -> ready
2017-07-13 17:00:16adminsetmessages: + msg9364
2017-07-13 17:00:16adminsetmessages: + msg9363
2017-03-13 00:00:00admincreate