BloombergLP::bdlb::ScopeExit::ScopeExit

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.

Synopsis

Declared in <bdlb_scopeexit.h>

template<class EXIT_FUNC_PARAM>
explicit
ScopeExit(
    EXIT_FUNC_PARAM&& function,
    void* = 0)
requires bsl::is_constructible<  // Copy construct
            EXIT_FUNC,
            const typename MoveUtil::Decay<EXIT_FUNC_PARAM>::type&
        >::value                                                             ||
        bsl::is_constructible<  // Move construct
            EXIT_FUNC,
            bslmf::MovableRef<typename MoveUtil::Decay<EXIT_FUNC_PARAM>::type>
        >::value;