proxygen
folly::rvalue_reference_wrapper< T > Class Template Reference

#include <RValueReferenceWrapper.h>

Public Types

using type = T
 

Public Member Functions

 rvalue_reference_wrapper () noexcept
 
 rvalue_reference_wrapper (T &&ref) noexcept
 
 rvalue_reference_wrapper (T &) noexcept=delete
 
 rvalue_reference_wrapper (rvalue_reference_wrapper< T > &&other) noexcept
 
rvalue_reference_wrapperoperator= (rvalue_reference_wrapper &&other) noexcept
 
 operator T && ()&&noexcept
 
T && get ()&&noexcept
 
template<class... Args>
decltype(auto) operator() (Args &&...args)&&noexcept(noexcept(std::declval< T >()(std::forward< Args >(args)...)))
 
bool valid () const noexcept
 

Private Member Functions

 rvalue_reference_wrapper (const rvalue_reference_wrapper &)=delete
 
rvalue_reference_wrapperoperator= (const rvalue_reference_wrapper &)=delete
 

Private Attributes

Tptr_
 

Detailed Description

template<class T>
class folly::rvalue_reference_wrapper< T >

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

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.)

folly::rref

Examples:
/facebook/proxygen/proxygen/folly/folly/container/Iterator.h.

Definition at line 42 of file RValueReferenceWrapper.h.

Member Typedef Documentation

Constructor & Destructor Documentation

template<class T>
folly::rvalue_reference_wrapper< T >::rvalue_reference_wrapper ( )
inlinenoexcept

Default constructor. Creates an invalid reference. Must be move-assigned to in order to be come valid.

Examples:
/facebook/proxygen/proxygen/folly/folly/lang/RValueReferenceWrapper.h.

Definition at line 50 of file RValueReferenceWrapper.h.

Referenced by folly::rvalue_reference_wrapper< T >::rvalue_reference_wrapper(), and folly::rvalue_reference_wrapper< T >::valid().

template<class T>
folly::rvalue_reference_wrapper< T >::rvalue_reference_wrapper ( T &&  ref)
inlineexplicitnoexcept

Explicit constructor to make it harder to accidentally create a dangling reference to a temporary.

Definition at line 56 of file RValueReferenceWrapper.h.

References folly::pushmi::__adl::noexcept(), folly::rvalue_reference_wrapper< T >::rvalue_reference_wrapper(), and folly::T.

57  : ptr_(std::addressof(ref)) {}
template<class T>
folly::rvalue_reference_wrapper< T >::rvalue_reference_wrapper ( T )
explicitdeletenoexcept

No construction from lvalue reference. Use std::move.

template<class T>
folly::rvalue_reference_wrapper< T >::rvalue_reference_wrapper ( rvalue_reference_wrapper< T > &&  other)
inlinenoexcept

Destructive move construction.

Definition at line 67 of file RValueReferenceWrapper.h.

68  : ptr_(other.ptr_) {
69  other.ptr_ = nullptr;
70  }
template<class T>
folly::rvalue_reference_wrapper< T >::rvalue_reference_wrapper ( const rvalue_reference_wrapper< T > &  )
privatedelete

Member Function Documentation

template<class T>
T&& folly::rvalue_reference_wrapper< T >::get ( )
inlinenoexcept

Explicit unwrap. Destructive.

Definition at line 92 of file RValueReferenceWrapper.h.

References testing::Args(), folly::rvalue_reference_wrapper< T >::ptr_, folly::T, and folly::rvalue_reference_wrapper< T >::valid().

Referenced by folly::rvalue_reference_wrapper< T >::operator T &&(), and folly::rvalue_reference_wrapper< T >::operator()().

92  {
93  assert(valid());
94  T& ref = *ptr_;
95  ptr_ = nullptr;
96  return static_cast<T&&>(ref);
97  }
folly::std T
template<class T>
folly::rvalue_reference_wrapper< T >::operator T && ( )
inlinenoexcept

Implicit conversion to raw reference. Destructive.

Definition at line 85 of file RValueReferenceWrapper.h.

References folly::rvalue_reference_wrapper< T >::get().

85  {
86  return static_cast<rvalue_reference_wrapper&&>(*this).get();
87  }
template<class T>
template<class... Args>
decltype(auto) folly::rvalue_reference_wrapper< T >::operator() ( Args &&...  args)
inlinenoexcept

Calls the callable object to whom reference is stored. Only available if the wrapped reference points to a callable object. Destructive.

Examples:
/facebook/proxygen/proxygen/folly/folly/lang/RValueReferenceWrapper.h.

Definition at line 104 of file RValueReferenceWrapper.h.

References folly::rvalue_reference_wrapper< T >::get().

105  {
106  return static_cast<rvalue_reference_wrapper&&>(*this).get()(
107  std::forward<Args>(args)...);
108  }
template<class T>
rvalue_reference_wrapper& folly::rvalue_reference_wrapper< T >::operator= ( rvalue_reference_wrapper< T > &&  other)
inlinenoexcept

Destructive move assignment.

Examples:
/facebook/proxygen/proxygen/folly/folly/lang/RValueReferenceWrapper.h.

Definition at line 75 of file RValueReferenceWrapper.h.

References folly::rvalue_reference_wrapper< T >::ptr_.

Referenced by folly::rvalue_reference_wrapper< T >::valid().

76  {
77  ptr_ = other.ptr_;
78  other.ptr_ = nullptr;
79  return *this;
80  }
template<class T>
rvalue_reference_wrapper& folly::rvalue_reference_wrapper< T >::operator= ( const rvalue_reference_wrapper< T > &  )
privatedelete

Member Data Documentation


The documentation for this class was generated from the following file: