Files
cppdraft_translate/cppdraft/optional/specalg.md
2025-10-25 03:02:53 +03:00

69 lines
2.1 KiB
Markdown
Raw 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.

[optional.specalg]
# 22 General utilities library [[utilities]](./#utilities)
## 22.5 Optional objects [[optional]](optional#specalg)
### 22.5.10 Specialized algorithms [optional.specalg]
[🔗](#lib:swap,optional)
`template<class T>
constexpr void swap(optional<T>& x, optional<T>& y) noexcept(noexcept(x.swap(y)));
`
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L5456)
*Constraints*: is_reference_v<T> || (is_move_constructible_v<T> && is_swappable_v<T>) is true[.](#1.sentence-1)
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L5463)
*Effects*: Calls x.swap(y)[.](#2.sentence-1)
[🔗](#lib:make_optional)
`template<class T> constexpr optional<decay_t<T>> make_optional(T&& v);
`
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L5474)
*Constraints*: The call to make_optional does not use
an explicit [*template-argument-list*](temp.names#nt:template-argument-list "13.3Names of template specializations[temp.names]") that
begins with a type [*template-argument*](temp.names#nt:template-argument "13.3Names of template specializations[temp.names]")[.](#3.sentence-1)
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L5480)
*Returns*: optional<decay_t<T>>(std::forward<T>(v))[.](#4.sentence-1)
[🔗](#lib:make_optional_)
`template<class T, class...Args>
constexpr optional<T> make_optional(Args&&... args);
`
[5](#5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L5492)
*Effects*: Equivalent to: return optional<T>(in_place, std::forward<Args>(args)...);
[🔗](#lib:make_optional__)
`template<class T, class U, class... Args>
constexpr optional<T> make_optional(initializer_list<U> il, Args&&... args);
`
[6](#6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L5504)
*Effects*: Equivalent to: return optional<T>(in_place, il, std::forward<Args>(args)...);