Namespaces
Variants

std::reference_wrapper<T>:: reference_wrapper

From cppreference.net
Utilities library
Function objects
Function invocation
(C++17) (C++23)
Identity function object
(C++20)
Old binders and adaptors
( until C++17* )
( until C++17* )
( until C++17* )
( until C++17* )
( until C++17* ) ( until C++17* ) ( until C++17* ) ( until C++17* )
( until C++20* )
( until C++20* )
( until C++17* ) ( until C++17* )
( until C++17* ) ( until C++17* )

( until C++17* )
( until C++17* ) ( until C++17* ) ( until C++17* ) ( until C++17* )
( until C++20* )
( until C++20* )
template < class U >
reference_wrapper ( U && x ) noexcept ( /*see below*/ ) ;
(1) (C++11 起)
(C++20 起为 constexpr)
reference_wrapper ( const reference_wrapper & other ) noexcept ;
(2) (C++11 起)
(C++20 起为 constexpr)

构造一个新的引用包装器。

1) x 转换为 T& ,如同通过 T & t = std:: forward < U > ( x ) ; 进行转换,随后存储 t 的引用。此重载仅当 typename std:: decay < U > :: type reference_wrapper 类型不同,且表达式 FUN ( std:: declval < U > ( ) ) 是良构的时参与重载决议,其中 FUN 代表以下虚构函数集合:
void FUN(T&) noexcept;
void FUN(T&&) = delete;
2) 复制构造函数。存储对 other. get ( ) 的引用。

目录

参数

x - 要包装的对象
other - 另一个引用包装器

异常

1)
noexcept 规范:
noexcept ( noexcept ( FUN ( std:: declval < U > ( ) ) ) )
其中 FUN 是上文描述中提及的虚构函数集合。

示例

缺陷报告

以下行为变更缺陷报告被追溯应用于先前发布的C++标准。

缺陷报告 应用于 发布时的行为 正确行为
LWG 2993 C++11 已删除的 reference_wrapper(T&&) 构造函数在某些情况下会干扰
重载决议
替换为构造函数模板