proxygen
folly::Replaceable< T > Class Template Reference

#include <Replaceable.h>

Inheritance diagram for folly::Replaceable< T >:
folly::replaceable_detail::dtor_mixin< T > folly::replaceable_detail::default_and_move_ctor_mixin< T, bool, bool > folly::replaceable_detail::copy_ctor_mixin< T > folly::replaceable_detail::move_assignment_mixin< T, bool > folly::replaceable_detail::copy_assignment_mixin< T >

Public Types

using value_type = T
 

Public Member Functions

constexpr Replaceable ()=default
 
constexpr Replaceable (const Replaceable &)=default
 
constexpr Replaceable (Replaceable &&)=default
 
Replaceableoperator= (const Replaceable &)=default
 
Replaceableoperator= (Replaceable &&)=default
 
 ~Replaceable ()=default
 
template<class... Args, std::enable_if_t< std::is_constructible< T, Args &&... >::value, int > = 0>
FOLLY_CPP14_CONSTEXPR Replaceable (in_place_t, Args &&...args) noexcept(std::is_nothrow_constructible< T, Args &&... >::value)
 
template<class U , class... Args, std::enable_if_t< std::is_constructible< T, std::initializer_list< U >, Args &&... >::value, int > = 0>
FOLLY_CPP14_CONSTEXPR Replaceable (in_place_t, std::initializer_list< U > il, Args &&...args) noexcept(std::is_nothrow_constructible< T, std::initializer_list< U >, Args &&... >::value)
 
template<class U = T, std::enable_if_t< std::is_constructible< T, U && >::value &&!std::is_same< std::decay_t< U >, in_place_t >::value &&!std::is_same< Replaceable< T >, std::decay_t< U >>::value &&std::is_convertible< U &&, T >::value, int > = 0>
FOLLY_CPP14_CONSTEXPR Replaceable (U &&other) noexcept(std::is_nothrow_constructible< T, U && >::value)
 
template<class U = T, std::enable_if_t< std::is_constructible< T, U && >::value &&!std::is_same< std::decay_t< U >, in_place_t >::value &&!std::is_same< Replaceable< T >, std::decay_t< U >>::value &&!std::is_convertible< U &&, T >::value, int > = 0>
FOLLY_CPP14_CONSTEXPR Replaceable (U &&other) noexcept(std::is_nothrow_constructible< T, U && >::value)
 
template<class U , std::enable_if_t< std::is_constructible< T, const U & >::value &&!replaceable_detail::is_constructible_from_replaceable< T >::value &&!replaceable_detail::is_convertible_from_replaceable< T >::value &&std::is_convertible< const U &, T >::value, int > = 0>
 Replaceable (const Replaceable< U > &other) noexcept(std::is_nothrow_constructible< T, U const & >::value)
 
template<class U , std::enable_if_t< std::is_constructible< T, const U & >::value &&!replaceable_detail::is_constructible_from_replaceable< T >::value &&!replaceable_detail::is_convertible_from_replaceable< T >::value &&!std::is_convertible< const U &, T >::value, int > = 0>
 Replaceable (const Replaceable< U > &other) noexcept(std::is_nothrow_constructible< T, U const & >::value)
 
template<class U , std::enable_if_t< std::is_constructible< T, U && >::value &&!replaceable_detail::is_constructible_from_replaceable< T >::value &&!replaceable_detail::is_convertible_from_replaceable< T >::value &&std::is_convertible< U &&, T >::value, int > = 0>
 Replaceable (Replaceable< U > &&other) noexcept(std::is_nothrow_constructible< T, U && >::value)
 
template<class U , std::enable_if_t< std::is_constructible< T, U && >::value &&!replaceable_detail::is_constructible_from_replaceable< T >::value &&!replaceable_detail::is_convertible_from_replaceable< T >::value &&!std::is_convertible< U &&, T >::value, int > = 0>
 Replaceable (Replaceable< U > &&other) noexcept(std::is_nothrow_constructible< T, U && >::value)
 
template<class... Args>
Templace (Args &&...args) noexcept
 
template<class U , class... Args>
Templace (std::initializer_list< U > il, Args &&...args) noexcept
 
void swap (Replaceable &other)
 
constexpr const Toperator-> () const
 
FOLLY_CPP14_CONSTEXPR Toperator-> ()
 
constexpr const Toperator* () const &
 
FOLLY_CPP14_CONSTEXPR Toperator* ()&
 
FOLLY_CPP14_CONSTEXPR T && operator* ()&&
 
constexpr const T && operator* () const &&
 

Private Types

using ctor_base = replaceable_detail::default_and_move_ctor_mixin< T >
 

Private Attributes

std::aligned_storage_t< sizeof(T), alignof(T)> storage_ [1]
 

Friends

struct replaceable_detail::dtor_mixin< T >
 
struct replaceable_detail::default_and_move_ctor_mixin< T >
 
struct replaceable_detail::copy_ctor_mixin< T >
 
struct replaceable_detail::move_assignment_mixin< T >
 
struct replaceable_detail::copy_assignment_mixin< T >
 

Detailed Description

template<class T>
class folly::Replaceable< T >

Definition at line 125 of file Replaceable.h.

Member Typedef Documentation

Definition at line 408 of file Replaceable.h.

template<class T>
using folly::Replaceable< T >::value_type = T

Definition at line 411 of file Replaceable.h.

Constructor & Destructor Documentation

template<class T>
constexpr folly::Replaceable< T >::Replaceable ( )
default
template<class T>
constexpr folly::Replaceable< T >::Replaceable ( const Replaceable< T > &  )
default
template<class T>
constexpr folly::Replaceable< T >::Replaceable ( Replaceable< T > &&  )
default
template<class T>
folly::Replaceable< T >::~Replaceable ( )
default
template<class T>
template<class... Args, std::enable_if_t< std::is_constructible< T, Args &&... >::value, int > = 0>
FOLLY_CPP14_CONSTEXPR folly::Replaceable< T >::Replaceable ( in_place_t  ,
Args &&...  args 
)
inlineexplicitnoexcept

Constructors; these are modeled very closely on the definition of std::optional in C++17.

Definition at line 442 of file Replaceable.h.

References testing::Args(), folly::T, and folly::value().

446  : ctor_base(0) {
447  ::new (storage_) T(std::forward<Args>(args)...);
448  }
STL namespace.
folly::std T
internal::ArgsMatcher< InnerMatcher > Args(const InnerMatcher &matcher)
replaceable_detail::default_and_move_ctor_mixin< T > ctor_base
Definition: Replaceable.h:408
std::aligned_storage_t< sizeof(T), alignof(T)> storage_[1]
Definition: Replaceable.h:640
template<class T>
template<class U , class... Args, std::enable_if_t< std::is_constructible< T, std::initializer_list< U >, Args &&... >::value, int > = 0>
FOLLY_CPP14_CONSTEXPR folly::Replaceable< T >::Replaceable ( in_place_t  ,
std::initializer_list< U >  il,
Args &&...  args 
)
inlineexplicitnoexcept

Definition at line 456 of file Replaceable.h.

References folly::T, value, and folly::value().

466  : ctor_base(0) {
467  ::new (storage_) T(il, std::forward<Args>(args)...);
468  }
STL namespace.
folly::std T
internal::ArgsMatcher< InnerMatcher > Args(const InnerMatcher &matcher)
replaceable_detail::default_and_move_ctor_mixin< T > ctor_base
Definition: Replaceable.h:408
std::aligned_storage_t< sizeof(T), alignof(T)> storage_[1]
Definition: Replaceable.h:640
template<class T>
template<class U = T, std::enable_if_t< std::is_constructible< T, U && >::value &&!std::is_same< std::decay_t< U >, in_place_t >::value &&!std::is_same< Replaceable< T >, std::decay_t< U >>::value &&std::is_convertible< U &&, T >::value, int > = 0>
FOLLY_CPP14_CONSTEXPR folly::Replaceable< T >::Replaceable ( U &&  other)
inlinenoexcept

Definition at line 478 of file Replaceable.h.

References folly::T, value, and folly::value().

482  : ctor_base(0) {
483  ::new (storage_) T(std::forward<U>(other));
484  }
STL namespace.
folly::std T
replaceable_detail::default_and_move_ctor_mixin< T > ctor_base
Definition: Replaceable.h:408
std::aligned_storage_t< sizeof(T), alignof(T)> storage_[1]
Definition: Replaceable.h:640
template<class T>
template<class U = T, std::enable_if_t< std::is_constructible< T, U && >::value &&!std::is_same< std::decay_t< U >, in_place_t >::value &&!std::is_same< Replaceable< T >, std::decay_t< U >>::value &&!std::is_convertible< U &&, T >::value, int > = 0>
FOLLY_CPP14_CONSTEXPR folly::Replaceable< T >::Replaceable ( U &&  other)
inlineexplicitnoexcept

Definition at line 494 of file Replaceable.h.

References folly::T, value, and folly::value().

498  : ctor_base(0) {
499  ::new (storage_) T(std::forward<U>(other));
500  }
STL namespace.
folly::std T
replaceable_detail::default_and_move_ctor_mixin< T > ctor_base
Definition: Replaceable.h:408
std::aligned_storage_t< sizeof(T), alignof(T)> storage_[1]
Definition: Replaceable.h:640
template<class T>
template<class U , std::enable_if_t< std::is_constructible< T, const U & >::value &&!replaceable_detail::is_constructible_from_replaceable< T >::value &&!replaceable_detail::is_convertible_from_replaceable< T >::value &&std::is_convertible< const U &, T >::value, int > = 0>
folly::Replaceable< T >::Replaceable ( const Replaceable< U > &  other)
inlinenoexcept

Definition at line 511 of file Replaceable.h.

References folly::T, value, and folly::value().

515  : ctor_base(0) {
516  ::new (storage_) T(*other);
517  }
folly::std T
replaceable_detail::default_and_move_ctor_mixin< T > ctor_base
Definition: Replaceable.h:408
std::aligned_storage_t< sizeof(T), alignof(T)> storage_[1]
Definition: Replaceable.h:640
template<class T>
template<class U , std::enable_if_t< std::is_constructible< T, const U & >::value &&!replaceable_detail::is_constructible_from_replaceable< T >::value &&!replaceable_detail::is_convertible_from_replaceable< T >::value &&!std::is_convertible< const U &, T >::value, int > = 0>
folly::Replaceable< T >::Replaceable ( const Replaceable< U > &  other)
inlineexplicitnoexcept

Definition at line 528 of file Replaceable.h.

References folly::T, value, and folly::value().

532  : ctor_base(0) {
533  ::new (storage_) T(*other);
534  }
folly::std T
replaceable_detail::default_and_move_ctor_mixin< T > ctor_base
Definition: Replaceable.h:408
std::aligned_storage_t< sizeof(T), alignof(T)> storage_[1]
Definition: Replaceable.h:640
template<class T>
template<class U , std::enable_if_t< std::is_constructible< T, U && >::value &&!replaceable_detail::is_constructible_from_replaceable< T >::value &&!replaceable_detail::is_convertible_from_replaceable< T >::value &&std::is_convertible< U &&, T >::value, int > = 0>
folly::Replaceable< T >::Replaceable ( Replaceable< U > &&  other)
inlinenoexcept

Definition at line 545 of file Replaceable.h.

References folly::gen::move, folly::T, value, and folly::value().

549  : ctor_base(0) {
550  ::new (storage_) T(std::move(*other));
551  }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
STL namespace.
folly::std T
replaceable_detail::default_and_move_ctor_mixin< T > ctor_base
Definition: Replaceable.h:408
std::aligned_storage_t< sizeof(T), alignof(T)> storage_[1]
Definition: Replaceable.h:640
template<class T>
template<class U , std::enable_if_t< std::is_constructible< T, U && >::value &&!replaceable_detail::is_constructible_from_replaceable< T >::value &&!replaceable_detail::is_convertible_from_replaceable< T >::value &&!std::is_convertible< U &&, T >::value, int > = 0>
folly::Replaceable< T >::Replaceable ( Replaceable< U > &&  other)
inlineexplicitnoexcept

Definition at line 562 of file Replaceable.h.

References testing::Args(), folly::gen::move, and folly::T.

566  : ctor_base(0) {
567  ::new (storage_) T(std::move(*other));
568  }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
STL namespace.
folly::std T
replaceable_detail::default_and_move_ctor_mixin< T > ctor_base
Definition: Replaceable.h:408
std::aligned_storage_t< sizeof(T), alignof(T)> storage_[1]
Definition: Replaceable.h:640

Member Function Documentation

template<class T>
template<class... Args>
T& folly::Replaceable< T >::emplace ( Args &&...  args)
inlinenoexcept

emplace destructs the contained object and in-place constructs the replacement.

The destructor must not throw (as usual). The constructor must not throw because that would violate the invariant that a Replaceable<T> always contains a T instance.

As these methods are noexcept the program will be terminated if an exception is thrown. If you are encountering this issue you should look at using Optional instead.

Definition at line 583 of file Replaceable.h.

References testing::Args(), folly::launder(), and folly::T.

583  {
584  T* destruct_ptr = launder(reinterpret_cast<T*>(storage_));
585  destruct_ptr->~T();
586  return *::new (storage_) T(std::forward<Args>(args)...);
587  }
STL namespace.
folly::std T
internal::ArgsMatcher< InnerMatcher > Args(const InnerMatcher &matcher)
FOLLY_NODISCARD T * launder(T *in) noexcept
Definition: Launder.h:48
std::aligned_storage_t< sizeof(T), alignof(T)> storage_[1]
Definition: Replaceable.h:640
template<class T>
template<class U , class... Args>
T& folly::Replaceable< T >::emplace ( std::initializer_list< U >  il,
Args &&...  args 
)
inlinenoexcept

Definition at line 590 of file Replaceable.h.

References folly::launder(), and folly::T.

590  {
591  T* destruct_ptr = launder(reinterpret_cast<T*>(storage_));
592  destruct_ptr->~T();
593  return *::new (storage_) T(il, std::forward<Args>(args)...);
594  }
STL namespace.
folly::std T
internal::ArgsMatcher< InnerMatcher > Args(const InnerMatcher &matcher)
FOLLY_NODISCARD T * launder(T *in) noexcept
Definition: Launder.h:48
std::aligned_storage_t< sizeof(T), alignof(T)> storage_[1]
Definition: Replaceable.h:640
template<class T>
constexpr const T& folly::Replaceable< T >::operator* ( ) const
inline

Definition at line 618 of file Replaceable.h.

References folly::launder().

618  {
619  return *launder(reinterpret_cast<T const*>(storage_));
620  }
FOLLY_NODISCARD T * launder(T *in) noexcept
Definition: Launder.h:48
std::aligned_storage_t< sizeof(T), alignof(T)> storage_[1]
Definition: Replaceable.h:640
template<class T>
FOLLY_CPP14_CONSTEXPR T& folly::Replaceable< T >::operator* ( )
inline

Definition at line 622 of file Replaceable.h.

References folly::launder().

622  {
623  return *launder(reinterpret_cast<T*>(storage_));
624  }
FOLLY_NODISCARD T * launder(T *in) noexcept
Definition: Launder.h:48
std::aligned_storage_t< sizeof(T), alignof(T)> storage_[1]
Definition: Replaceable.h:640
template<class T>
FOLLY_CPP14_CONSTEXPR T&& folly::Replaceable< T >::operator* ( )
inline

Definition at line 626 of file Replaceable.h.

References folly::launder(), and folly::gen::move.

626  {
627  return std::move(*launder(reinterpret_cast<T*>(storage_)));
628  }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
FOLLY_NODISCARD T * launder(T *in) noexcept
Definition: Launder.h:48
std::aligned_storage_t< sizeof(T), alignof(T)> storage_[1]
Definition: Replaceable.h:640
template<class T>
constexpr const T&& folly::Replaceable< T >::operator* ( ) const
inline

Definition at line 630 of file Replaceable.h.

References folly::launder(), and folly::gen::move.

630  {
631  return std::move(*launder(reinterpret_cast<T const*>(storage_)));
632  }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
FOLLY_NODISCARD T * launder(T *in) noexcept
Definition: Launder.h:48
std::aligned_storage_t< sizeof(T), alignof(T)> storage_[1]
Definition: Replaceable.h:640
template<class T>
constexpr const T* folly::Replaceable< T >::operator-> ( ) const
inline

Methods to access the contained object. Intended to be very unsurprising.

Definition at line 610 of file Replaceable.h.

References folly::launder().

610  {
611  return launder(reinterpret_cast<T const*>(storage_));
612  }
FOLLY_NODISCARD T * launder(T *in) noexcept
Definition: Launder.h:48
std::aligned_storage_t< sizeof(T), alignof(T)> storage_[1]
Definition: Replaceable.h:640
template<class T>
FOLLY_CPP14_CONSTEXPR T* folly::Replaceable< T >::operator-> ( )
inline

Definition at line 614 of file Replaceable.h.

References folly::launder().

614  {
615  return launder(reinterpret_cast<T*>(storage_));
616  }
FOLLY_NODISCARD T * launder(T *in) noexcept
Definition: Launder.h:48
std::aligned_storage_t< sizeof(T), alignof(T)> storage_[1]
Definition: Replaceable.h:640
template<class T>
Replaceable& folly::Replaceable< T >::operator= ( const Replaceable< T > &  )
default
template<class T>
Replaceable& folly::Replaceable< T >::operator= ( Replaceable< T > &&  )
default
template<class T>
void folly::Replaceable< T >::swap ( Replaceable< T > &  other)
inline

swap just calls swap(T&, T&).

Should be noexcept(std::is_nothrow_swappable<T>value) but we don't depend on C++17 features.

Definition at line 602 of file Replaceable.h.

References folly::f14::swap(), and folly::swap().

602  {
603  using std::swap;
604  swap(*(*this), *other);
605  }
void swap(Replaceable &other)
Definition: Replaceable.h:602
void swap(SwapTrackingAlloc< T > &, SwapTrackingAlloc< T > &)
Definition: F14TestUtil.h:414

Friends And Related Function Documentation

template<class T>
friend struct replaceable_detail::copy_assignment_mixin< T >
friend

Definition at line 639 of file Replaceable.h.

template<class T>
friend struct replaceable_detail::copy_ctor_mixin< T >
friend

Definition at line 637 of file Replaceable.h.

template<class T>
friend struct replaceable_detail::default_and_move_ctor_mixin< T >
friend

Definition at line 636 of file Replaceable.h.

template<class T>
friend struct replaceable_detail::dtor_mixin< T >
friend

Definition at line 635 of file Replaceable.h.

template<class T>
friend struct replaceable_detail::move_assignment_mixin< T >
friend

Definition at line 638 of file Replaceable.h.

Member Data Documentation

template<class T>
std::aligned_storage_t<sizeof(T), alignof(T)> folly::Replaceable< T >::storage_[1]
private

Definition at line 640 of file Replaceable.h.


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