folly::rvalue_reference_wrapper

Class template that wraps a reference to an rvalue. Similar to std::reference_wrapper but with three important differences:

Synopsis

Declared in <folly/lang/RValueReferenceWrapper.h>

template<class T>
class rvalue_reference_wrapper;

Description

1) folly::rvalue_reference_wrappers can only be moved, not copied; 2) the get() function and the conversion-to-T operator are destructive and not const, they invalidate the wrapper; 3) the constructor-from-T is explicit.

These restrictions are designed to make it harder to accidentally create a a dangling rvalue reference, or to use an rvalue reference multiple times. (Using an rvalue reference typically implies invalidation of the target object, such as move-assignment to another object.)

Type Aliases

NameDescription
type The referenced value type.

Member Functions

NameDescription
rvalue_reference_wrapper [constructor]Constructors
operator= Destructive move assignment.
get Explicit unwrap. Destructive.
operator() Calls the callable object to whom reference is stored. Only available if the wrapped reference points to a callable object. Destructive.
valid Check whether wrapped reference is valid.
operator T&& Implicit conversion to raw reference. Destructive.

Non-Member Functions

NameDescription
rrefCreate a folly::rvalue_reference_wrapper. Analogous to std::ref().
rrefDeleted lvalue overload of rref to prevent wrapping lvalues.