Semiregular wrapper (C++20)
template<class T> requires std::CopyConstructible<T> && std::is_object_v<T> |
(since C++20) | |
ranges::single_view, ranges::filter_view and ranges::transform_view are specified in terms of an exposition-only class template semiregular
. The name semiregular
is for exposition purposes only and not normative.
semiregular<T>
behaves exactly like std::optional<T>
with a little differences, which makes it model Semiregular
.
Template parameters
T | - | the type of the value to manage initialization state for. The type must be a object type and model CopyConstructible
|
Member functions
Following member functions are conditionally different from corresponding member functions of std::optional.
semiregular::semiregular
constexpr semiregular() noexcept(std::is_nothrow_default_constructible_v<T>); |
||
If T
models DefaultConstructible
, the default constructor of semiregular<T>
constructs a semiregular wrapper containing a value-initialized T
and is equivalent to:
constexpr semiregular() noexcept(std::is_nothrow_default_constructible_v<T>) : semiregular{std::in_place} { }
Otherwise, the default constructor is equivalent to the default constructor of std::optional
and constructs a semiregular wrapper which does not contain a value.
semiregular::operator=
semiregular& operator=(const semiregular& other) noexcept(std::is_nothrow_copy_constructible_v<T>) |
(1) | |
semiregular& operator=(semiregular&& other) noexcept(std::is_nothrow_move_constructible_v<T>) |
(2) | |
Otherwise, the copy assignment operator is identical to the copy assignment operator of
std::optional
.Otherwise, the move assignment operator is identical to the move assignment operator of
std::optional
.