ranges::single_view, ranges::repeat_view,(since C++23) and range adaptors that store an invocable object are specified in terms of an exposition-only class template copyable-box
(until C++23)movable-box
(since C++23). The name shown here is for exposition purposes only.
The wrapper behaves exactly like std::optional<T>, except that the default constructor, copy assignment operator, and move assignment operator are (conditionally) different from those of std::optional, which augments T
with assignability when needed and makes it always satisfy copyable
or movable
(since C++23).
The default constructor is provided if and only if T
models default_initializable
.
A default-constructed wrapper contains a value-initialized T
object.
constexpr /*copyable-box*/& operator=(const /*copyable-box*/& other);
noexcept(/* see below */);
optional
object
std::optional<T>
) [edit] destroys the contained value, if there is one
std::optional<T>
) [edit] assigns contents
std::optional<T>
) [edit] Observers accesses the contained value
std::optional<T>
) [edit] checks whether the object contains a value
std::optional<T>
) [edit] Modifiers destroys any contained value
std::optional<T>
) [edit] constructs the contained value in-place
std::optional<T>
) [edit] [edit] Notes
A copyable-box
(until C++23)movable-box
(since C++23) does not contain a value only if
T
does not model movable
or copyable
, and an exception is thrown on move assignment or copy assignment respectively, orBefore P2325R3, the wrapper was called semiregular-box
in the standard and always satisfied semiregular
, as the default constructor was always provided (which might construct a valueless wrapper).
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
DR Applied to Behavior as published Correct behavior P2325R3 C++20 ifT
is not default_initializable
, the default constructor
default_initializable
LWG 3572 C++20 conditionally different assignment operators were not constexpr made constexpr [edit] See also
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4