Namespaces
Variants
Views
Actions

operator==, <=>(std::reference_wrapper)

From cppreference.com
 
 
Utilities library
Language support
Type support (basic types, RTTI)
Library feature-test macros (C++20)
Dynamic memory management
Program utilities
Coroutine support (C++20)
Variadic functions
Debugging support
(C++26)
Three-way comparison
(C++20)
(C++20)(C++20)(C++20)
(C++20)(C++20)(C++20)
General utilities
Date and time
Function objects
Formatting library (C++20)
(C++11)
Relational operators (deprecated in C++20)
Integer comparison functions
(C++20)(C++20)(C++20)   
(C++20)
Swap and type operations
(C++14)
(C++11)
(C++11)
(C++11)
(C++17)
Common vocabulary types
(C++11)
(C++17)
(C++17)
(C++17)
(C++11)
(C++17)
(C++23)
Elementary string conversions
(C++17)
(C++17)

 
Function objects
Function invocation
(C++17)(C++23)
Identity function object
(C++20)
Transparent operator wrappers
(C++14)
(C++14)
(C++14)
(C++14)  
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)

Old binders and adaptors
(until C++17*)
(until C++17*)
(until C++17*)
(until C++17*)  
(until C++17*)
(until C++17*)(until C++17*)(until C++17*)(until C++17*)
(until C++20*)
(until C++20*)
(until C++17*)(until C++17*)
(until C++17*)(until C++17*)

(until C++17*)
(until C++17*)(until C++17*)(until C++17*)(until C++17*)
(until C++20*)
(until C++20*)
 
 
friend constexpr bool
    operator==( reference_wrapper lhs, reference_wrapper rhs );
(1) (since C++26)
friend constexpr bool
    operator==( reference_wrapper lhs, reference_wrapper<const T> rhs );
(2) (since C++26)
friend constexpr bool
    operator==( reference_wrapper lhs, const T& ref );
(3) (since C++26)
friend constexpr synth-three-way-result<T>
    operator<=>( reference_wrapper lhs, reference_wrapper rhs );
(4) (since C++26)
friend constexpr synth-three-way-result<T>
    operator<=>( reference_wrapper lhs, reference_wrapper<const T> rhs );
(5) (since C++26)
friend constexpr synth-three-way-result<T>
    operator<=>( reference_wrapper lhs, const T& ref );
(6) (since C++26)

Performs comparison operations on reference_wrapper objects.

1,2) Compares two reference_wrapper objects. The objects compare equal if and only if lhs.get() and rhs.get() are equal.
  • Both overloads participate in overload resolution only if lhs.get() == rhs.get() is well-formed and its result is convertible to bool.
  • The overload (2) participates in overload resolution only if std::is_const_v<T> is false.
3) Compares reference_wrapper object with a reference. The parameters compare equal if and only if lhs.get() is equal to ref.
  • The overload (3) participates in overload resolution only if lhs.get() == ref is well-formed and its result is convertible to bool.
4,5) Compares two reference_wrapper objects as if by synth-three-way(lhs.get(), rhs.get()).
  • The overload (5) participates in overload resolution only if std::is_const_v<T> is false.
6) Compares reference_wrapper object with a reference as if by synth-three-way(lhs.get(), ref).

The <, <=, >, >=, and != operators are synthesized from operator<=> and operator== respectively.

Contents

[edit] Parameters

lhs, rhs - reference_wrapper object to compare
ref - reference to compare to the reference_wrapper object

[edit] Return value

1,2) lhs.get() == rhs.get().
3) lhs.get() == ref.
4,5) synth-three-way(lhs.get(), rhs.get()).
6) synth-three-way(lhs.get(), ref).

[edit] Exceptions

Throws when and what the comparison throws.

[edit] Example