8#ifndef INCLUDED_BDLB_SCOPEEXIT
9#define INCLUDED_BDLB_SCOPEEXIT
594#include <bdlscm_version.h>
612#include <bsl_functional.h>
614#ifdef BSLS_COMPILERFEATURES_SUPPORT_TRAITS_HEADER
615 #include <bsl_type_traits.h>
617#ifdef BSLS_COMPILERFEATURES_SUPPORT_CTAD
618 #include <bsl_utility.h>
631#ifdef BSLS_COMPILERFEATURES_SUPPORT_RVALUE_REFERENCES
648 #define BDLB_SCOPEEXIT_USES_MODERN_CPP
651#ifdef BDE_BUILD_TARGET_EXC
652 #define BDLB_SCOPEEXIT_NOEXCEPT_SPEC BSLS_KEYWORD_NOEXCEPT_SPECIFICATION
654 #define BDLB_SCOPEEXIT_NOEXCEPT_SPEC(...)
663#ifdef BDLB_SCOPEEXIT_USES_MODERN_CPP
664 #define BDLB_SCOPEEXIT_PROCTOR(NAME, EXIT_FUNC) \
665 auto NAME{ BloombergLP::bdlb::ScopeExitUtil::makeScopeExit(EXIT_FUNC) }
667 #define BDLB_SCOPEEXIT_PROCTOR(NAME, EXIT_FUNC) \
668 BloombergLP::bdlb::ScopeExitAny NAME((EXIT_FUNC))
675#define BDLB_SCOPEEXIT_PRIVATE_CAT(X, Y) BDLB_SCOPEEXIT_PRIVATE_CAT_IMP(X, Y)
680#define BDLB_SCOPEEXIT_PRIVATE_CAT_IMP(X, Y) X##Y
685#if defined(BSLS_PLATFORM_CMP_MSVC) || defined(BSLS_PLATFCORM_CMP_GNU) || \
686 defined(BSLS_PLATFCORM_CMP_CLANG)
692 #define BDLB_SCOPEEXIT_PRIVATE_UNIQNUM __COUNTER__
694 #define BDLB_SCOPEEXIT_PRIVATE_UNIQNUM __LINE__
704#define BDLB_SCOPEEXIT_GUARD(EXIT_FUNC) \
706 const BDLB_SCOPEEXIT_PROCTOR( \
707 BDLB_SCOPEEXIT_PRIVATE_CAT(bdlbScopeExitGuard_, \
708 BDLB_SCOPEEXIT_PRIVATE_UNIQNUM), \
736template <
class EXIT_FUNC>
764 EXIT_FUNC d_exitFunction;
765 bool d_executeOnDestruction;
771#ifdef BSLS_COMPILERFEATURES_SUPPORT_RVALUE_REFERENCES
791 template <
class EXIT_FUNC_PARAM>
794#ifdef BSLS_COMPILERFEATURES_SUPPORT_TRAITS_HEADER
801 bsl::is_constructible<
805 bsl::is_constructible<
825#ifdef BSLS_COMPILERFEATURES_SUPPORT_TRAITS_HEADER
843#ifdef BSLS_COMPILERFEATURES_SUPPORT_TRAITS_HEADER
846 || bsl::is_nothrow_copy_constructible<EXIT_FUNC>::value);
864#ifdef BSLS_COMPILERFEATURES_SUPPORT_CTAD
866template <
class EXIT_FUNC_PARAM>
879#ifdef BDLB_SCOPEEXIT_USES_MODERN_CPP
889struct ScopeExitUtil {
896 template <
class EXIT_FUNC_PARAM>
900 makeScopeExit(EXIT_FUNC_PARAM&& function);
913template <
class EXIT_FUNC>
914template <
class EXIT_FUNC_PARAM>
919#ifdef BSLS_COMPILERFEATURES_SUPPORT_TRAITS_HEADER
920 bsl::is_constructible<
924 bsl::is_constructible<
939#ifdef BDE_BUILD_TARGET_EXC
942#ifdef BSLS_COMPILERFEATURES_SUPPORT_TRAITS_HEADER
946 bsl::is_nothrow_constructible<EXIT_FUNC,
947 EXIT_FUNC_PARAM>::value ||
948 !bsl::is_constructible<
951 EXIT_FUNC_PARAM>::type&
955 EXIT_FUNC_PARAM>::type&
966, d_executeOnDestruction(
true)
969#ifdef BDE_BUILD_TARGET_EXC
972 MoveUtil::access(function)();
976#ifdef BSLS_COMPILERFEATURES_SUPPORT_TRAITS_HEADER
977template <
class EXIT_FUNC>
978inline ScopeExit<EXIT_FUNC>::ScopeExit(
void (*function)())
979#ifdef BDE_BUILD_TARGET_EXC
982: d_exitFunction(function)
983, d_executeOnDestruction(
true)
986#ifdef BDE_BUILD_TARGET_EXC
994template <
class EXIT_FUNC>
997#ifdef BSLS_COMPILERFEATURES_SUPPORT_TRAITS_HEADER
1000 || bsl::is_nothrow_copy_constructible<EXIT_FUNC>::value)
1005: d_exitFunction(MoveUtil::move_if_noexcept(
1006 MoveUtil::access(original).d_exitFunction))
1007, d_executeOnDestruction(
true)
1009 MoveUtil::access(original).
release();
1012template <
class EXIT_FUNC>
1016 if (d_executeOnDestruction) {
1022template <
class EXIT_FUNC>
1026 d_executeOnDestruction =
false;
1029#ifdef BDLB_SCOPEEXIT_USES_MODERN_CPP
1036template <
class EXIT_FUNC_PARAM>
1039ScopeExitUtil::makeScopeExit(EXIT_FUNC_PARAM&& function)
1042 bslmf::Util::forward<EXIT_FUNC_PARAM>(function));
1054#ifndef BSLS_COMPILERFEATURES_SUPPORT_TRAITS_HEADER
1059template <
class EXIT_FUNC>
1066#ifdef BDLB_SCOPEEXIT_USES_MODERN_CPP
1067#undef BDLB_SCOPEEXIT_USES_MODERN_CPP
1070#ifdef BDLB_SCOPEEXIT_NOEXCEPT_SPEC
1071#undef BDLB_SCOPEEXIT_NOEXCEPT_SPEC
Definition bdlb_scopeexit.h:737
void release()
Definition bdlb_scopeexit.h:1024
ScopeExit(bslmf::MovableRef< ScopeExit > original) BDLB_SCOPEEXIT_NOEXCEPT_SPEC(bsl ~ScopeExit()
Definition bdlb_scopeexit.h:1014
Forward declaration.
Definition bslstl_function.h:934
Definition bslmf_movableref.h:751
#define BDLB_SCOPEEXIT_NOEXCEPT_SPEC(...)
Definition bdlb_scopeexit.h:654
#define BSLA_NODISCARD_CPP17
Definition bsla_nodiscard.h:321
#define BSLA_NODISCARD
Definition bsla_nodiscard.h:320
#define BSLMF_ASSERT(expr)
Definition bslmf_assert.h:229
#define BSLS_COMPILERFEATURES_FORWARD_REF(T)
Definition bsls_compilerfeatures.h:2012
#define BSLS_COMPILERFEATURES_FORWARD(T, V)
Definition bsls_compilerfeatures.h:2018
#define BSLS_COMPILERFEATURES_CPLUSPLUS
Definition bsls_compilerfeatures.h:1183
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
#define BSLS_KEYWORD_DELETED
Definition bsls_keyword.h:609
Definition bdlb_algorithmworkaroundutil.h:74
ScopeExit< bsl::function< void()> > ScopeExitAny
Definition bdlb_scopeexit.h:877
Definition bdlb_printmethods.h:283
Definition bslmf_conditional.h:120
Definition bslmf_enableif.h:525
Definition bslmf_isconvertible.h:867
Definition bslmf_isfunction.h:232
Definition bslmf_isnothrowmoveconstructible.h:358
Definition bslmf_ispointer.h:138
Definition bslmf_isreference.h:137
BloombergLP::bslmf::RemovePointer_Imp< t_TYPE >::Type type
Definition bslmf_removepointer.h:267
Definition bslmf_movableref.h:863
Definition bslmf_movableref.h:825
Definition bslmf_movableref.h:791
static BSLS_KEYWORD_CONSTEXPR const t_TYPE & forward(const t_TYPE &t) BSLS_KEYWORD_NOEXCEPT
Definition bslmf_util.h:460