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

2.7 KiB

[range.move.wrap]

25 Ranges library [ranges]

25.7 Range adaptors [range.adaptors]

25.7.3 Movable wrapper [range.move.wrap]

1

#

Many types in this subclause are specified in terms of an exposition-only class template movable-box.

movable-box behaves exactly like optional with the following differences:

movable-box constrains its type parameter T withmove_constructible && is_object_v.

The default constructor of movable-box is equivalent to:constexpr movable-box() noexcept(is_nothrow_default_constructible_v)requires default_initializable: movable-box{in_place} {}

If copyable is not modeled, the copy assignment operator is equivalent to:constexpr movable-box& operator=(const movable-box& that)noexcept(is_nothrow_copy_constructible_v)requires copy_constructible {if (this != addressof(that)) {if (that) emplace(*that); else reset(); }return *this;}

If movable is not modeled, the move assignment operator is equivalent to:constexpr movable-box& operator=(movable-box&& that)noexcept(is_nothrow_move_constructible_v) {if (this != addressof(that)) {if (that) emplace(std::move(*that)); else reset(); }return *this;}

2

#

Recommended practice:

  • (2.1)

    If copy_constructible is true,movable-box should store only a T if either T models copyable, oris_nothrow_move_constructible_v && is_nothrow_copy_constructible_v is true.

  • (2.2)

    Otherwise, movable-box should store only a T if either T models movable oris_nothrow_move_constructible_v is true.