2945. Order of template parameters in optional comparisons

Section: 23.6.8 [optional.comp_with_t] Status: WP Submitter: Jonathan Wakely Opened: 2017-03-13 Last modified: 2017-11-13

Priority: 2

View all other issues in [optional.comp_with_t].

View all issues with WP 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 23.6.2 [optional.syn], <optional> synopsis, as indicated:

    // 23.6.8 [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 23.6.8 [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- […]

    […]