11 #include <type_traits> 61 void dismiss() noexcept {
73 static const T& asConst(
const T& t) noexcept {
80 template <
typename FunctionType>
84 std::is_nothrow_copy_constructible<FunctionType>::value)
87 makeFailsafe(std::is_nothrow_copy_constructible<FunctionType>{},
91 std::is_nothrow_copy_constructible<FunctionType>::value)
94 makeFailsafe(std::is_nothrow_copy_constructible<FunctionType>{},
98 std::is_nothrow_move_constructible<FunctionType>::value)
100 std::move_if_noexcept(fn),
101 makeFailsafe(std::is_nothrow_move_constructible<FunctionType>{},
105 std::is_nothrow_move_constructible<FunctionType>::value)
106 : function_(std::move_if_noexcept(other.function_)) {
112 dismissed_ = other.dismissed_;
113 other.dismissed_ =
true;
124 return makeEmptyScopeGuard();
127 template <
typename Fn>
128 static auto makeFailsafe(std::false_type, Fn* fn) noexcept
133 template <
typename Fn>
139 void*
operator new(std::size_t) =
delete;
141 void execute() noexcept { function_(); }
143 FunctionType function_;
146 template <
typename FunctionType>
148 MakeGuard(FunctionType&& fn) noexcept(
149 std::is_nothrow_constructible<
typename std::decay<FunctionType>::type,
150 FunctionType>::value) {
152 std::forward<FunctionType>(fn));
Simple registry implementation in Caffe2 that uses static variables to register object creators durin...
ScopeGuardImplBase && ScopeGuard
This is largely unneeded if you just use auto for your guards.
ScopeGuard is a general implementation of the "Initialization is Resource Acquisition" idiom...