1) 如同用 T& t = std::forward<U>(x); 转换x 为T&,然后存储到 t 的引用。此重载只有在 typename std::decay<U>::type 与reference_wrapper 不是同一类型且表达式 FUN(std::declval<U>()) 为良构时才会参与重载决议,其中 FUN 指名虚构的函数集。 void FUN(T&) noexcept;
reference_wrapper::operator() Non-member functions operator==operator<=> (C++26)(C++26) Deduction guides (C++17) Helper classes basic_common_reference<std::reference_wrapper> (C++23) template< class... ArgTypes > typename std::result_of<T&(ArgTypes&&...)>::type operator() ( ArgTypes...
From cppreference.com Function objects std::reference_wrapper Member functions reference_wrapper::reference_wrapper reference_wrapper::operator= reference_wrapper::getreference_wrapper::operator T& reference_wrapper::operator() Non-member functions
一看就是std::reference_wrapper的解引用类,就是从std::reference_wrapper<T>得到T&。
std::reference_wrapper<T> is a copyable and assignable object that imitates a reference (T&). It gives the non-nullable guarantee of a reference and the pointer-like flexibility to rebind to another object.
在C++23中,std::basic_common_reference针对std::reference_wrapper的特化已经实现了提案中的要求。以下是一个示例: 代码语言:cpp 代码运行次数:0 运行 AI代码解释 #include<concepts>#include<functional>static_assert(std::same_as<std::common_reference_t<int&,std::reference_wrapper<int>>,int&>);static_...
Ifarg_iis of typestd::reference_wrapper<T>(for example,std::reforstd::crefwas used in the initial call tostd::bind), thenv_iisarg_i.get()and its typeV_iisT&: the stored argument is passed by reference into the invoked function object. ...
std::ref(j)返回的就是std::reference_wrapper<int>对象。 reference_wrapper std::reference_wrapper及其辅助函数大致长成这样: template<typenameT> classreference_wrapper { public: template<typenameU> reference_wrapper(U&& x): ptr(std::addressof(x)) { } ...
您所谈论的逻辑完全在std::bind本身中实现。它需要从std::reference_wrapper获得的主要功能是它可以被“...
(T& t)noexcept{returnt; }template<classT>voidFUN(T&&) =delete; }template<classT>classreference_wrapper {public:// typestypedefT type;// construct/copy/destroytemplate<classU,class=decltype( detail::FUN<T>(std::declval<U>()), std::enable_if_t<!std::is_same_v<reference_wrapper, my:...