stdreference_wrapper(3)
std::reference_wrapper - std::reference_wrapper
Synopsis
Defined in header <functional>
template< class T > (since C++11)
class reference_wrapper;std::reference_wrapper is a class template that wraps a reference in a copyable, assignable object. It is frequently used as a mechanism to store references inside standard containers (like std::vector) which cannot normally hold references. Specifically, std::reference_wrapper is a CopyConstructible and CopyAssignable wrapper around a reference to object or reference to function of type T. Instances of std::reference_wrapper are objects (they can be copied or stored in containers) but they are implicitly convertible to T&, so that they can be used as arguments with the functions that take the underlying type by reference. If the stored reference is Callable, std::reference_wrapper is callable with the same arguments. Helper functions std::ref and std::cref are often used to generate std::reference_wrapper objects. std::reference_wrapper is also used to pass objects by reference to std::bind, the constructor of std::thread, or the helper functions std::make_pair and std::make_tuple. std::reference_wrapper is guaranteed to be TriviallyCopyable. (since C++17) T may be an incomplete type. (since C++20)
Member types
type definition
type T
result_type(deprecated in C++17)(removed in C++20) The return type of T if T is a function. Otherwise, not defined