Quick Links:

bal | bbl | bdl | bsl

Public Member Functions

bdlb::ScopeExit< EXIT_FUNC > Class Template Reference

#include <bdlb_scopeexit.h>

List of all members.

Public Member Functions

template<class EXIT_FUNC_PARAM >
 ScopeExit (BSLS_COMPILERFEATURES_FORWARD_REF(EXIT_FUNC_PARAM) function, typename bsl::enable_if< bsl::is_convertible< const typename MoveUtil::Decay< EXIT_FUNC_PARAM >::type &, EXIT_FUNC >::value||bsl::is_convertible< bslmf::MovableRef< typename MoveUtil::Decay< EXIT_FUNC_PARAM >::type >, EXIT_FUNC >::value >::type *=0)
 ScopeExit (bslmf::MovableRef< ScopeExit > original)
 ~ScopeExit ()
void release ()

Detailed Description

template<class EXIT_FUNC>
class bdlb::ScopeExit< EXIT_FUNC >

ScopeExit is a general-purpose scope proctor class template that is intended to be used as an automatic (stack) variable that calls an exit function upon its destruction (when its scope is exited).

The template argument EXIT_FUNC shall be a function object type, or a pointer to a function. If EXIT_FUNC is an object type, it shall satisfy the requirements of Destructible, Callable, and MoveConstructible as specified by the ISO C++ standard. Note that to fulfill the MoveConstructible constraint a type does not have to implement a move constructor. If it has a copy constructor, that will work fine as long at the move constructor is not deleted (or in case of C++03 emulated moves, private). The behavior is undefined if calling (the member instance of) EXIT_FUNC throws an exception (as it will be called from the destructor).

See Component bdlb_scopeexit


Constructor & Destructor Documentation

template<class EXIT_FUNC>
template<class EXIT_FUNC_PARAM >
bdlb::ScopeExit< EXIT_FUNC >::ScopeExit ( BSLS_COMPILERFEATURES_FORWARD_REF(EXIT_FUNC_PARAM)  function,
typename bsl::enable_if< bsl::is_convertible< const typename MoveUtil::Decay< EXIT_FUNC_PARAM >::type &, EXIT_FUNC >::value||bsl::is_convertible< bslmf::MovableRef< typename MoveUtil::Decay< EXIT_FUNC_PARAM >::type >, EXIT_FUNC >::value >::type = 0 
) [explicit]

Create a ScopeExit object, which, upon its destruction will invoke the specified function (or functor) unless its release method was called. If function is copied into the EXIT_FUNC member, and that copy throws an exception, invoke function and rethrow the exception. If EXIT_FUNC_PARAM cannot be move converted to EXIT_FUNC via no-throw means (either because such conversion does not exist or it is not marked as non-throwing), function will always be copied into the member. This constructor participates in overload resolution only if EXIT_FUNC_PARAM is neither EXIT_FUNC nor bdlb::ScopeExit<EXIT_FUNC> and EXIT_FUNC_PARAM is convertible to EXIT_FUNC. The behavior is undefined if function or the member instance of EXIT_FUNC throws an exception upon invocation.

template<class EXIT_FUNC>
bdlb::ScopeExit< EXIT_FUNC >::ScopeExit ( bslmf::MovableRef< ScopeExit< EXIT_FUNC > >  original  ) 

If bsl::is_nothrow_move_constructible<EXIT_FUNC>value is true or EXIT_FUNC is a move-only type, move construct, otherwise, copy construct the exit function from the specified original. If construction succeeds, call release() on original.

template<class EXIT_FUNC>
bdlb::ScopeExit< EXIT_FUNC >::~ScopeExit (  ) 

Destroy this object. Execute the exit function unless release() has been called on this object.


Member Function Documentation

template<class EXIT_FUNC>
void bdlb::ScopeExit< EXIT_FUNC >::release (  ) 

Turn off the execution of the exit function of this object on destruction.


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