BloombergLP::bdlb::ScopeExit::ScopeExit

Constructors

Synopses

Declared in <bdlb_scopeexit.h>

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.

ScopeExit(bslmf::MovableRef<ScopeExit> original) noexcept(/* see-below */);
» more...

Create a ScopeExit object, which, upon its destruction will invoke the specified function unless the 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. The behavior is undefined if function or the member instance of EXIT_FUNC throws an exception upon invocation. Note that this separate constructor for function pointers exists because without it the forwarding logic in the templated constructor implementation generates warnings about meaningless types generated.

explicit
ScopeExit(void(* function)());
» more...

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_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;
» more...