std::experimental::optional<T>::operator=

Replaces contents of *this with the contents of other.

# Declarations

optional& operator=( std::experimental::nullopt_t ) noexcept;

(library fundamentals TS)

optional& operator=( const optional& other );

(library fundamentals TS)

optional& operator=( optional&& other ) noexcept(/* see below */);

(library fundamentals TS)

template< class U >
optional& operator=( U&& value );

(library fundamentals TS)

# Parameters

# Return value

*this

# Notes

An optional object op may be turned into an empty optional with both op = {}; and op = nullopt;.

# Example

#include <experimental/optional>
#include <iostream>
 
int main()
{
    std::experimental::optional<const char*> s1 = "abc", s2; // constructor
    s2 = s1; // assignment
    s1 = "def"; // decaying assignment (U = char[4], T = const char*)
    std::cout << *s2 << ' ' << *s1 << '\n';
}

# See also