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

42 lines
3.1 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.

[refwrap.general]
# 22 General utilities library [[utilities]](./#utilities)
## 22.10 Function objects [[function.objects]](function.objects#refwrap.general)
### 22.10.6 Class template reference_wrapper [[refwrap]](refwrap#general)
#### 22.10.6.1 General [refwrap.general]
[🔗](#lib:reference_wrapper)
namespace std {template<class T> class reference_wrapper {public:// typesusing type = T; // [[refwrap.const]](refwrap.const "22.10.6.2Constructors"), constructorstemplate<class U>constexpr reference_wrapper(U&&) noexcept(*see below*); constexpr reference_wrapper(const reference_wrapper& x) noexcept; // [[refwrap.assign]](refwrap.assign "22.10.6.3Assignment"), assignmentconstexpr reference_wrapper& operator=(const reference_wrapper& x) noexcept; // [[refwrap.access]](refwrap.access "22.10.6.4Access"), accessconstexpr operator T& () const noexcept; constexpr T& get() const noexcept; // [[refwrap.invoke]](refwrap.invoke "22.10.6.5Invocation"), invocationtemplate<class... ArgTypes>constexpr invoke_result_t<T&, ArgTypes...> operator()(ArgTypes&&...) constnoexcept(is_nothrow_invocable_v<T&, ArgTypes...>); // [[refwrap.comparisons]](refwrap.comparisons "22.10.6.6Comparisons"), comparisonsfriend constexpr bool operator==(reference_wrapper, reference_wrapper); friend constexpr bool operator==(reference_wrapper, const T&); friend constexpr bool operator==(reference_wrapper, reference_wrapper<const T>); friend constexpr auto operator<=>(reference_wrapper, reference_wrapper); friend constexpr auto operator<=>(reference_wrapper, const T&); friend constexpr auto operator<=>(reference_wrapper, reference_wrapper<const T>); }; template<class T> reference_wrapper(T&) -> reference_wrapper<T>;}
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L11697)
reference_wrapper<T> is a [*Cpp17CopyConstructible*](utility.arg.requirements#:Cpp17CopyConstructible "16.4.4.2Template argument requirements[utility.arg.requirements]") and [*Cpp17CopyAssignable*](utility.arg.requirements#:Cpp17CopyAssignable "16.4.4.2Template argument requirements[utility.arg.requirements]") wrapper
around a reference to an object or function of type T[.](#1.sentence-1)
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L11701)
reference_wrapper<T> is
a trivially copyable type ([[basic.types.general]](basic.types.general#term.trivially.copyable.type "6.9.1General"))[.](#2.sentence-1)
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L11705)
The template parameter T of reference_wrapper may be an incomplete type[.](#3.sentence-1)
[*Note [1](#note-1)*:
Using the comparison operators described in [[refwrap.comparisons]](refwrap.comparisons "22.10.6.6Comparisons") with T being an incomplete type
can lead to an ill-formed program
with no diagnostic required ([[temp.point]](temp.point "13.8.4.1Point of instantiation"), [[temp.constr.atomic]](temp.constr.atomic "13.5.2.3Atomic constraints"))[.](#3.sentence-2)
— *end note*]