| Technical Specification | ||||
| Filesystem library(filesystem TS) | ||||
| Library fundamentals(library fundamentals TS) | ||||
| Library fundamentals 2(library fundamentals TS v2) | ||||
| Library fundamentals 3(library fundamentals TS v3) | ||||
| Extensions for parallelism(parallelism TS) | ||||
| Extensions for parallelism 2(parallelism TS v2) | ||||
| Extensions for concurrency(concurrency TS) | ||||
| Extensions for concurrency 2(concurrency TS v2) | ||||
| Concepts(concepts TS) | ||||
| Ranges(ranges TS) | ||||
| Reflection(reflection TS) | ||||
| Mathematical special functions(special functions TR) | ||||
| Experimental Non-TS | ||||
| Pattern Matching | ||||
| Linear Algebra | ||||
| std::execution | ||||
| Contracts | ||||
| 2D Graphics |
| Member functions | ||||
optional::operator= | ||||
| Observers | ||||
| Modifiers | ||||
| Non-member functions | ||||
| Helper classes | ||||
| Helper objects | ||||
optional& operator=(std::experimental::nullopt_t)noexcept; | (1) | (library fundamentals TS) |
optional& operator=(const optional& other); | (2) | (library fundamentals TS) |
optional& operator=( optional&& other)noexcept(/* see below */); | (3) | (library fundamentals TS) |
template<class U> optional& operator=( U&& value); | (4) | (library fundamentals TS) |
Replaces contents of*this with the contents ofother.
Contents |
| other | - | anotheroptional object whose contained value to assign |
| value | - | value to assign to the contained value |
| Type requirements | ||
-T must meet the requirements ofCopyAssignable andCopyConstructible in order to use overload (2). | ||
-T must meet the requirements ofMoveAssignable andMoveConstructible in order to use overload (3). | ||
*this
T. If an exception is thrown, the initialization state of*this (and ofother in case of (2)) is unchanged, i.e. if the object contained a value, it still contains a value, and the other way round. The contents ofvalue and the contained values of*this andother depend on the exception safety guarantees of the operation from which the exception originates (copy-constructor, move-assignment, etc.).noexcept declaration:An optional objectop may be turned into an empty optional with bothop={}; andop= nullopt;.
#include <experimental/optional>#include <iostream> int main(){std::experimental::optional<constchar*> s1="abc", s2;// constructor s2= s1;// assignment s1="def";// decaying assignment (U = char[4], T = const char*)std::cout<<*s2<<' '<<*s1<<'\n';}
Output:
abc def
| constructs the contained value in-place (public member function)[edit] |