半正则包装 (C++20)
来自cppreference.com
                    
                                        
                    
                    
                                                            
                    | template<class T>     requires std::copy_constructible<T> && std::is_object_v<T> | (C++20 起) | |
ranges::single_view 、 ranges::filter_view 及 ranges::transform_view 通过仅为说明的类模板 semiregular_box 指定。名字 semiregular_box 仅为说明目的而设,是非规范性的。
semiregular_box<T> 表现恰如 std::optional<T> ,但有一些小区别,这使得它实现 semiregular 。
模板形参
| T | - | 要管理初始化状态的值的类型。该类型必须为对象类型并实现 copy_constructible 。 | 
成员函数
下列成员函数条件性地异于 std::optional 的对应成员函数。
semiregular_box::semiregular_box
| constexpr semiregular_box() noexcept(std::is_nothrow_default_constructible_v<T>); | ||
若 T 实现 default_initializable ,则 semiregular_box<T> 的默认构造函数构造含有值初始化的 T 的半正则包装,并且等价于:
constexpr semiregular_box() noexcept(std::is_nothrow_default_constructible_v<T>) : semiregular_box{std::in_place} { }
否则,默认构造函数等同于 std::optional 的默认构造函数,并构造不含值的半正则包装。
semiregular_box::operator=
| semiregular_box& operator=(const semiregular_box& other) noexcept(std::is_nothrow_copy_constructible_v<T>) | (1) | |
| semiregular_box& operator=(semiregular_box&& other) noexcept(std::is_nothrow_move_constructible_v<T>) | (2) | |
1) 若 Assignable<T&, const T&> 未被满足,则复制赋值运算符的函数体等价于 if (other) emplace(*other); else reset(); return *this; 。
否则,复制赋值运算符等同于
否则,复制赋值运算符等同于
std::optional 的复制赋值运算符。2) 若 Assignable<T&, T> 未被满足,则移动赋值运算符的函数体等价于 if (other) emplace(std::move(*other)); else reset(); return *this; 。
否则,移动赋值运算符等同于
否则,移动赋值运算符等同于
std::optional 的移动赋值运算符。 
	