Files
2025-10-25 03:02:53 +03:00

51 lines
2.7 KiB
Markdown
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

[range.move.wrap]
# 25 Ranges library [[ranges]](./#ranges)
## 25.7 Range adaptors [[range.adaptors]](range.adaptors#range.move.wrap)
### 25.7.3 Movable wrapper [range.move.wrap]
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L4308)
Many types in this subclause are specified in terms of
an exposition-only class template *movable-box*[.](#1.sentence-1)
*movable-box*<T> behaves exactly like optional<T> with the following differences:
- [(1.1)](#1.1)
*movable-box*<T> constrains
its type parameter T with[move_constructible](concept.moveconstructible#concept:move_constructible "18.4.13Concept move_­constructible[concept.moveconstructible]")<T> && is_object_v<T>.
- [(1.2)](#1.2)
The default
constructor of *movable-box*<T> is equivalent to:constexpr *movable-box*() noexcept(is_nothrow_default_constructible_v<T>)requires [default_initializable](concept.default.init#concept:default_initializable "18.4.12Concept default_­initializable[concept.default.init]")<T>: *movable-box*{in_place} {}
- [(1.3)](#1.3)
If [copyable](concepts.object#concept:copyable "18.6Object concepts[concepts.object]")<T> is not
modeled, the copy assignment operator is equivalent to:constexpr *movable-box*& operator=(const *movable-box*& that)noexcept(is_nothrow_copy_constructible_v<T>)requires [copy_constructible](concept.copyconstructible#concept:copy_constructible "18.4.14Concept copy_­constructible[concept.copyconstructible]")<T> {if (this != addressof(that)) {if (that) emplace(*that); else reset(); }return *this;}
- [(1.4)](#1.4)
If [movable](concepts.object#concept:movable "18.6Object concepts[concepts.object]")<T> is not modeled,
the move assignment operator is equivalent to:constexpr *movable-box*& operator=(*movable-box*&& that)noexcept(is_nothrow_move_constructible_v<T>) {if (this != addressof(that)) {if (that) emplace(std::move(*that)); else reset(); }return *this;}
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L4354)
*Recommended practice*:
- [(2.1)](#2.1)
If [copy_constructible](concept.copyconstructible#concept:copy_constructible "18.4.14Concept copy_­constructible[concept.copyconstructible]")<T> is true,*movable-box*<T> should store only a T if either T models [copyable](concepts.object#concept:copyable "18.6Object concepts[concepts.object]"), oris_nothrow_move_constructible_v<T> && is_nothrow_copy_constructible_v<T> is true[.](#2.1.sentence-1)
- [(2.2)](#2.2)
Otherwise, *movable-box*<T> should store only a T if either T models [movable](concepts.object#concept:movable "18.6Object concepts[concepts.object]") oris_nothrow_move_constructible_v<T> is true[.](#2.2.sentence-1)