operator=(std::experimental::optional) - cppreference.com

##### cppreference.com

##### Search

Create account

##### Namespaces

- Page
- Discussion

##### Variants

##### Views

- View
- Edit
- History

##### Actions

# operator=(std::experimental::optional)

From cppreference.com
< cpp‎ | experimental‎ | optional

Defined in header `<experimental/optional>` |  |
Compare two `optional` objects |  |
template< class T > constexpr bool operator==( const optional<T>& lhs, const optional<T>& rhs ); | (1) | (library fundamentals TS)
template< class T > constexpr bool operator<( const optional<T>& lhs, const optional<T>& rhs ); | (2) | (library fundamentals TS)
Compare an `optional` object with a `nullopt` |  |
template< class T > constexpr bool operator==( const optional<T>& opt, std::nullopt_t ); | (3) | (library fundamentals TS)
template< class T > constexpr bool operator==( std::nullopt_t, const optional<T>& opt ); | (4) | (library fundamentals TS)
template< class T > constexpr bool operator<( const optional<T>& opt, std::nullopt_t ); | (5) | (library fundamentals TS)
template< class T > constexpr bool operator<( std::nullopt_t, const optional<T>& opt); | (6) | (library fundamentals TS)
Compare an `optional` object with a `T` |  |
template< class T > constexpr bool operator==( const optional<T>& opt, const T& v ); | (7) | (library fundamentals TS)
template< class T > constexpr bool operator==( const T& value, const optional<T>& opt ); | (8) | (library fundamentals TS)
template< class T > constexpr bool operator<( const optional<T>& opt, const T& v ); | (9) | (library fundamentals TS)

Performs comparison operations on `optional` objects.

1-2) Compares two `optional` objects, `lhs` and `rhs`. The contained values are compared only if both `lhs` and `rhs` are in engaged states. Otherwise,

    - `lhs` is considered equal to `rhs` if, and only if, both `lhs` and `rhs` are in disengaged states.
    - `lhs` is considered less than `rhs` if, and only if, `rhs` is in engaged state and `lhs` is not.

3-6) Compares `opt` with a `nullopt`. Equivalent to (1-2) when comparing to an `optional` with engaged state.
7-9) Compares `opt` with a `value`. The values are compared only if `opt` is in engaged state. Otherwise, `opt` is considered less than `value`.

### [edit] Parameters

lhs, rhs, opt | - | an `optional` object to compare
value | - | value to compare to the contained value
Type requirements
- `T` must meet the requirements of `EqualityComparable` in order to use overloads (1, 7-8).

### [edit] Return value

1) If bool(lhs) != bool(rhs), returns false
Otherwise, if bool(lhs) == bool(rhs) == false, returns true
Otherwise, returns *lhs == *rhs.
2) If bool(rhs) == false returns false
Otherwise, if lhs == false, returns true
Otherwise returns std::less<T>{}(*x, *y)
3) Returns !opt.
4) Returns false.
5) Returns !opt.
6) Returns bool(opt)
7-8) Returns bool(opt) ? *opt == value : false.
9) Returns bool(opt) ? std::less<T>{}(*opt, value) : true.

### [edit] Exceptions

1-2) (none)
3-6)
`noexcept` specification:
noexcept
7-9) (none)
Retrieved from "http://en.cppreference.com/mwiki/index.php?title=cpp/experimental/optional/operator_cmp&oldid=69015"
Category:

- unconditionally noexcept