proxygen
folly::detail::ScopeGuardImpl< FunctionType, InvokeNoexcept > Class Template Reference

#include <ScopeGuard.h>

Inheritance diagram for folly::detail::ScopeGuardImpl< FunctionType, InvokeNoexcept >:
folly::detail::ScopeGuardImplBase

Public Member Functions

 ScopeGuardImpl (FunctionType &fn) noexcept(std::is_nothrow_copy_constructible< FunctionType >::value)
 
 ScopeGuardImpl (const FunctionType &fn) noexcept(std::is_nothrow_copy_constructible< FunctionType >::value)
 
 ScopeGuardImpl (FunctionType &&fn) noexcept(std::is_nothrow_move_constructible< FunctionType >::value)
 
 ScopeGuardImpl (ScopeGuardImpl &&other) noexcept(std::is_nothrow_move_constructible< FunctionType >::value)
 
 ~ScopeGuardImpl () noexcept(InvokeNoexcept)
 
- Public Member Functions inherited from folly::detail::ScopeGuardImplBase
void dismiss () noexcept
 

Private Member Functions

template<typename Fn >
 ScopeGuardImpl (Fn &&fn, ScopeGuardImplBase &&failsafe)
 
void * operator new (std::size_t)=delete
 
void execute () noexcept(InvokeNoexcept)
 

Static Private Member Functions

static ScopeGuardImplBase makeFailsafe (std::true_type, const void *) noexcept
 
template<typename Fn >
static auto makeFailsafe (std::false_type, Fn *fn) noexcept-> ScopeGuardImpl< decltype(std::ref(*fn)), InvokeNoexcept >
 

Private Attributes

FunctionType function_
 

Additional Inherited Members

- Protected Member Functions inherited from folly::detail::ScopeGuardImplBase
 ScopeGuardImplBase () noexcept
 
- Static Protected Member Functions inherited from folly::detail::ScopeGuardImplBase
static void warnAboutToCrash () noexcept
 
static ScopeGuardImplBase makeEmptyScopeGuard () noexcept
 
template<typename T >
static const TasConst (const T &t) noexcept
 
- Protected Attributes inherited from folly::detail::ScopeGuardImplBase
bool dismissed_
 

Detailed Description

template<typename FunctionType, bool InvokeNoexcept>
class folly::detail::ScopeGuardImpl< FunctionType, InvokeNoexcept >

Definition at line 58 of file ScopeGuard.h.

Constructor & Destructor Documentation

template<typename FunctionType, bool InvokeNoexcept>
folly::detail::ScopeGuardImpl< FunctionType, InvokeNoexcept >::ScopeGuardImpl ( FunctionType &  fn)
inlineexplicitnoexcept

Definition at line 60 of file ScopeGuard.h.

63  asConst(fn),
65  std::is_nothrow_copy_constructible<FunctionType>{},
66  &fn)) {}
static ScopeGuardImplBase makeFailsafe(std::true_type, const void *) noexcept
Definition: ScopeGuard.h:102
static const T & asConst(const T &t) noexcept
Definition: ScopeGuard.h:50
ScopeGuardImpl(FunctionType &fn) noexcept(std::is_nothrow_copy_constructible< FunctionType >::value)
Definition: ScopeGuard.h:60
template<typename FunctionType, bool InvokeNoexcept>
folly::detail::ScopeGuardImpl< FunctionType, InvokeNoexcept >::ScopeGuardImpl ( const FunctionType &  fn)
inlineexplicitnoexcept

Definition at line 68 of file ScopeGuard.h.

71  fn,
73  std::is_nothrow_copy_constructible<FunctionType>{},
74  &fn)) {}
static ScopeGuardImplBase makeFailsafe(std::true_type, const void *) noexcept
Definition: ScopeGuard.h:102
ScopeGuardImpl(FunctionType &fn) noexcept(std::is_nothrow_copy_constructible< FunctionType >::value)
Definition: ScopeGuard.h:60
template<typename FunctionType, bool InvokeNoexcept>
folly::detail::ScopeGuardImpl< FunctionType, InvokeNoexcept >::ScopeGuardImpl ( FunctionType &&  fn)
inlineexplicitnoexcept

Definition at line 76 of file ScopeGuard.h.

79  std::move_if_noexcept(fn),
81  std::is_nothrow_move_constructible<FunctionType>{},
82  &fn)) {}
static ScopeGuardImplBase makeFailsafe(std::true_type, const void *) noexcept
Definition: ScopeGuard.h:102
ScopeGuardImpl(FunctionType &fn) noexcept(std::is_nothrow_copy_constructible< FunctionType >::value)
Definition: ScopeGuard.h:60
template<typename FunctionType, bool InvokeNoexcept>
folly::detail::ScopeGuardImpl< FunctionType, InvokeNoexcept >::ScopeGuardImpl ( ScopeGuardImpl< FunctionType, InvokeNoexcept > &&  other)
inlinenoexcept

Definition at line 84 of file ScopeGuard.h.

References folly::detail::ScopeGuardImplBase::dismissed_, and folly::exchange().

86  : function_(std::move_if_noexcept(other.function_)) {
87  // If the above line attempts a copy and the copy throws, other is
88  // left owning the cleanup action and will execute it (or not) depending
89  // on the value of other.dismissed_. The following lines only execute
90  // if the move/copy succeeded, in which case *this assumes ownership of
91  // the cleanup action and dismisses other.
92  dismissed_ = exchange(other.dismissed_, true);
93  }
T exchange(T &obj, U &&new_value)
Definition: Utility.h:120
template<typename FunctionType, bool InvokeNoexcept>
folly::detail::ScopeGuardImpl< FunctionType, InvokeNoexcept >::~ScopeGuardImpl ( )
inlinenoexcept

Definition at line 95 of file ScopeGuard.h.

References folly::detail::ScopeGuardImplBase::dismissed_.

95  {
96  if (!dismissed_) {
97  execute();
98  }
99  }
void execute() noexcept(InvokeNoexcept)
Definition: ScopeGuard.h:121
template<typename FunctionType, bool InvokeNoexcept>
template<typename Fn >
folly::detail::ScopeGuardImpl< FunctionType, InvokeNoexcept >::ScopeGuardImpl ( Fn &&  fn,
ScopeGuardImplBase &&  failsafe 
)
inlineexplicitprivate

Definition at line 114 of file ScopeGuard.h.

References folly::detail::ScopeGuardImplBase::dismiss().

115  : ScopeGuardImplBase{}, function_(std::forward<Fn>(fn)) {
116  failsafe.dismiss();
117  }

Member Function Documentation

template<typename FunctionType, bool InvokeNoexcept>
void folly::detail::ScopeGuardImpl< FunctionType, InvokeNoexcept >::execute ( )
inlineprivatenoexcept

Definition at line 121 of file ScopeGuard.h.

References folly::detail::ScopeGuardImplBase::warnAboutToCrash().

121  {
122  if (InvokeNoexcept) {
123  try {
124  function_();
125  } catch (...) {
127  std::terminate();
128  }
129  } else {
130  function_();
131  }
132  }
static void warnAboutToCrash() noexcept
Definition: ScopeGuard.cpp:21
template<typename FunctionType, bool InvokeNoexcept>
static ScopeGuardImplBase folly::detail::ScopeGuardImpl< FunctionType, InvokeNoexcept >::makeFailsafe ( std::true_type  ,
const void *   
)
inlinestaticprivatenoexcept

Definition at line 102 of file ScopeGuard.h.

References folly::detail::ScopeGuardImplBase::makeEmptyScopeGuard().

102  {
103  return makeEmptyScopeGuard();
104  }
static ScopeGuardImplBase makeEmptyScopeGuard() noexcept
Definition: ScopeGuard.h:45
template<typename FunctionType, bool InvokeNoexcept>
template<typename Fn >
static auto folly::detail::ScopeGuardImpl< FunctionType, InvokeNoexcept >::makeFailsafe ( std::false_type  ,
Fn *  fn 
) -> ScopeGuardImpl<decltype(std::ref(*fn)), InvokeNoexcept>
inlinestaticprivatenoexcept

Definition at line 107 of file ScopeGuard.h.

108  {
109  return ScopeGuardImpl<decltype(std::ref(*fn)), InvokeNoexcept>{
110  std::ref(*fn)};
111  }
template<typename FunctionType, bool InvokeNoexcept>
void* folly::detail::ScopeGuardImpl< FunctionType, InvokeNoexcept >::operator new ( std::size_t  )
privatedelete

Member Data Documentation

template<typename FunctionType, bool InvokeNoexcept>
FunctionType folly::detail::ScopeGuardImpl< FunctionType, InvokeNoexcept >::function_
private

Definition at line 134 of file ScopeGuard.h.


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