Chris@16: Chris@16: // Copyright (C) 2006-2009, 2012 Alexander Nasonov Chris@16: // Copyright (C) 2012 Lorenzo Caminiti Chris@16: // Distributed under the Boost Software License, Version 1.0 Chris@16: // (see accompanying file LICENSE_1_0.txt or a copy at Chris@16: // http://www.boost.org/LICENSE_1_0.txt) Chris@16: // Home at http://www.boost.org/libs/scope_exit Chris@16: Chris@16: #ifndef FILE_boost_scope_exit_hpp_INCLUDED Chris@16: #define FILE_boost_scope_exit_hpp_INCLUDED Chris@16: Chris@16: #ifndef DOXYGEN Chris@16: Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@101: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@101: #include Chris@101: #include Chris@16: #include Chris@16: #include Chris@101: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@101: #include Chris@16: Chris@16: // PRIVATE/PROTECTED // Chris@16: Chris@16: // NOTE: AUX prefix and aux namespace mark "private" symbols that shall be used Chris@16: // only within this library; DETAIL prefix and detail namespace mark "protected" Chris@16: // symbols that can be used by other Boost libraries but not outside Boost. Chris@16: Chris@16: // WARNING: BOOST_SCOPE_EXIT_AUX_GCC also used by some regression test. Chris@16: #if defined(__GNUC__) && !defined(BOOST_INTEL) Chris@16: # define BOOST_SCOPE_EXIT_AUX_GCC (__GNUC__ * 100 + __GNUC_MINOR__) Chris@16: #else Chris@16: # define BOOST_SCOPE_EXIT_AUX_GCC 0 Chris@16: #endif Chris@16: Chris@16: #if BOOST_WORKAROUND(BOOST_SCOPE_EXIT_AUX_GCC, BOOST_TESTED_AT(413)) Chris@16: # define BOOST_SCOPE_EXIT_AUX_TPL_GCC_WORKAROUND_01 1 Chris@16: #else Chris@16: # define BOOST_SCOPE_EXIT_AUX_TPL_GCC_WORKAROUND_01 0 Chris@16: #endif Chris@16: Chris@16: #if BOOST_MSVC Chris@16: # define BOOST_SCOPE_EXIT_AUX_TYPEOF_THIS_MSVC_WORKAROUND_01 1 Chris@16: #else Chris@16: # define BOOST_SCOPE_EXIT_AUX_TYPEOF_THIS_MSVC_WORKAROUND_01 0 Chris@16: #endif Chris@16: Chris@101: // MSVC has problems expanding __LINE__ so use (the non standard) __COUNTER__. Chris@101: #ifdef BOOST_MSVC Chris@101: # define BOOST_SCOPE_EXIT_AUX_PP_LINE_COUNTER __COUNTER__ Chris@101: #else Chris@101: # define BOOST_SCOPE_EXIT_AUX_PP_LINE_COUNTER __LINE__ Chris@101: #endif Chris@101: Chris@101: // Preprocessor "keyword" detection. Chris@101: Chris@101: // These are not a local macros, do not #undefine them (these are used by the Chris@101: // ..._BACK macros below). Chris@101: #define this_BOOST_SCOPE_EXIT_AUX_PP_KEYWORD_THISUNDERSCORE_IS (1) /* unary */ Chris@101: #define void_BOOST_SCOPE_EXIT_AUX_PP_KEYWORD_VOID_IS (1) /* unary */ Chris@101: Chris@101: #define BOOST_SCOPE_EXIT_AUX_PP_KEYWORD_IS_BACK_(token, checking_postfix) \ Chris@101: BOOST_PP_IS_UNARY(BOOST_PP_CAT(token, checking_postfix)) Chris@101: Chris@101: #define BOOST_SCOPE_EXIT_AUX_PP_KEYWORD_IS_THISUNDERSCORE_BACK(token) \ Chris@101: BOOST_SCOPE_EXIT_AUX_PP_KEYWORD_IS_BACK_(token, \ Chris@101: BOOST_SCOPE_EXIT_AUX_PP_KEYWORD_THISUNDERSCORE_IS) Chris@101: Chris@101: #define BOOST_SCOPE_EXIT_AUX_PP_KEYWORD_IS_VOID_BACK(token) \ Chris@101: BOOST_SCOPE_EXIT_AUX_PP_KEYWORD_IS_BACK_(token, \ Chris@101: _BOOST_SCOPE_EXIT_AUX_PP_KEYWORD_VOID_IS) Chris@101: Chris@101: // Preprocessor "void-list". Chris@101: Chris@101: // NOTE: Empty list must always be represented as void (which is also a way to Chris@101: // specify no function parameter) and it can never be empty because (1) Chris@101: // IS_EMPTY(&var) fails (because of the leading non alphanumeric symbol) and Chris@101: // (2) some compilers (MSVC) fail to correctly pass empty macro parameters Chris@101: // even if they support variadic macros. Therefore, always using void to Chris@101: // represent is more portable. Chris@101: Chris@101: // Argument: (token1)... Chris@101: #define BOOST_SCOPE_EXIT_AUX_PP_VOID_LIST_FROM_SEQ_(unused, seq) \ Chris@101: BOOST_PP_TUPLE_TO_LIST(BOOST_PP_SEQ_SIZE(seq), BOOST_PP_SEQ_TO_TUPLE(seq)) Chris@101: Chris@101: // Token: void | token1 Chris@101: #define BOOST_SCOPE_EXIT_AUX_PP_VOID_LIST_HANDLE_VOID_( \ Chris@101: is_void_macro, token) \ Chris@101: BOOST_PP_IIF(is_void_macro(token), \ Chris@101: BOOST_PP_NIL \ Chris@101: , \ Chris@101: (token, BOOST_PP_NIL) \ Chris@101: ) Chris@101: Chris@101: // Token: (a)(b)... | empty | void | token Chris@101: #define BOOST_SCOPE_EXIT_AUX_PP_VOID_LIST_HANDLE_SEQ_( \ Chris@101: is_void_macro, token) \ Chris@101: BOOST_PP_IIF(BOOST_PP_IS_UNARY(token), /* unary paren (a)... */ \ Chris@101: BOOST_SCOPE_EXIT_AUX_PP_VOID_LIST_FROM_SEQ_ \ Chris@101: , \ Chris@101: BOOST_SCOPE_EXIT_AUX_PP_VOID_LIST_HANDLE_VOID_ \ Chris@101: )(is_void_macro, token) Chris@101: Chris@101: #define BOOST_SCOPE_EXIT_AUX_PP_VOID_LIST_NEVER_(tokens) \ Chris@101: 0 /* void check always returns false */ Chris@101: Chris@101: #ifdef BOOST_NO_CXX11_VARIADIC_MACROS Chris@101: Chris@101: #define BOOST_SCOPE_EXIT_AUX_PP_VOID_LIST_(is_void_macro, seq) \ Chris@101: BOOST_SCOPE_EXIT_AUX_PP_VOID_LIST_HANDLE_SEQ_(is_void_macro, seq) Chris@101: Chris@101: // Expand `void | (a)(b)...` to pp-list `NIL | (a, (b, NIL))`. Chris@101: #define BOOST_SCOPE_EXIT_AUX_PP_VOID_LIST(sign) \ Chris@101: BOOST_SCOPE_EXIT_AUX_PP_VOID_LIST_( \ Chris@101: BOOST_SCOPE_EXIT_AUX_PP_KEYWORD_IS_VOID_BACK, sign) Chris@101: Chris@101: // Expand `(a)(b)...` to pp-list `(a, (b, NIL))`. Chris@101: #define BOOST_SCOPE_EXIT_AUX_PP_NON_VOID_LIST(seq) \ Chris@101: BOOST_SCOPE_EXIT_AUX_PP_VOID_LIST_( \ Chris@101: BOOST_SCOPE_EXIT_AUX_PP_VOID_LIST_NEVER_, seq) Chris@101: Chris@101: #else // VARIADICS Chris@101: Chris@101: // FUTURE: Replace this with BOOST_PP_VARIADIC_SIZE when and if Chris@101: // BOOST_PP_VARIAIDCS detection will match !BOOST_NO_CXX11_VARIADIC_MACROS (for Chris@101: // now Boost.Preprocessor and Boost.Config disagree on detecting compiler Chris@101: // variadic support while this VARIADIC_SIZE works on compilers not detected by Chris@101: // PP). Chris@101: #if BOOST_MSVC Chris@101: # define BOOST_SCOPE_EXIT_AUX_PP_VOID_LIST_VARIADIC_SIZE_(...) \ Chris@101: BOOST_PP_CAT(BOOST_SCOPE_EXIT_AUX_PP_VOID_LIST_VARIADIC_SIZE_I_(__VA_ARGS__, 64, 63, 62, 61, 60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, 49, 48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1,),) Chris@101: #else // MSVC Chris@101: # define BOOST_SCOPE_EXIT_AUX_PP_VOID_LIST_VARIADIC_SIZE_(...) \ Chris@101: BOOST_SCOPE_EXIT_AUX_PP_VOID_LIST_VARIADIC_SIZE_I_(__VA_ARGS__, 64, 63, 62, 61, 60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, 49, 48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1,) Chris@101: #endif // MSVC Chris@101: #define BOOST_SCOPE_EXIT_AUX_PP_VOID_LIST_VARIADIC_SIZE_I_(e0, e1, e2, e3, e4, e5, e6, e7, e8, e9, e10, e11, e12, e13, e14, e15, e16, e17, e18, e19, e20, e21, e22, e23, e24, e25, e26, e27, e28, e29, e30, e31, e32, e33, e34, e35, e36, e37, e38, e39, e40, e41, e42, e43, e44, e45, e46, e47, e48, e49, e50, e51, e52, e53, e54, e55, e56, e57, e58, e59, e60, e61, e62, e63, size, ...) size Chris@101: Chris@101: // Argument: token1, ... Chris@101: #define BOOST_SCOPE_EXIT_AUX_PP_VOID_LIST_FROM_VARIADIC_(unused, ...) \ Chris@101: BOOST_PP_TUPLE_TO_LIST( \ Chris@101: BOOST_SCOPE_EXIT_AUX_PP_VOID_LIST_VARIADIC_SIZE_( \ Chris@101: __VA_ARGS__), (__VA_ARGS__)) Chris@101: Chris@101: #define BOOST_SCOPE_EXIT_AUX_PP_VOID_LIST_(is_void_macro, ...) \ Chris@101: BOOST_PP_IIF(BOOST_PP_EQUAL( \ Chris@101: BOOST_SCOPE_EXIT_AUX_PP_VOID_LIST_VARIADIC_SIZE_( \ Chris@101: __VA_ARGS__), 1), \ Chris@101: BOOST_SCOPE_EXIT_AUX_PP_VOID_LIST_HANDLE_SEQ_ \ Chris@101: , \ Chris@101: BOOST_SCOPE_EXIT_AUX_PP_VOID_LIST_FROM_VARIADIC_ \ Chris@101: )(is_void_macro, __VA_ARGS__) Chris@101: Chris@101: // Expand `void | (a)(b)... | a, b, ...` to pp-list `NIL | (a, (b, NIL))`. Chris@101: #define BOOST_SCOPE_EXIT_AUX_PP_VOID_LIST(...) \ Chris@101: BOOST_SCOPE_EXIT_AUX_PP_VOID_LIST_( \ Chris@101: BOOST_SCOPE_EXIT_AUX_PP_KEYWORD_IS_VOID_BACK, __VA_ARGS__) Chris@101: Chris@101: // Expand `(a)(b)... | a, b, ...` to pp-list `(a, (b, NIL))`. Chris@101: #define BOOST_SCOPE_EXIT_AUX_PP_NON_VOID_LIST(...) \ Chris@101: BOOST_SCOPE_EXIT_AUX_PP_VOID_LIST_( \ Chris@101: BOOST_SCOPE_EXIT_AUX_PP_VOID_LIST_NEVER_, __VA_ARGS__) Chris@101: Chris@101: #endif // VARIADICS Chris@101: Chris@16: // Steven Watanabe's trick with a modification suggested by Kim Barrett Chris@16: namespace boost { namespace scope_exit { namespace detail { Chris@16: Chris@16: // Type of a local BOOST_SCOPE_EXIT_AUX_ARGS variable. Chris@16: // First use in a local scope will declare the BOOST_SCOPE_EXIT_AUX_ARGS Chris@16: // variable, subsequent uses will be resolved as two comparisons Chris@16: // (cmp1 with 0 and cmp2 with BOOST_SCOPE_EXIT_AUX_ARGS). Chris@16: template Chris@16: struct declared Chris@16: { Chris@16: void* value; Chris@16: static int const cmp2 = 0; Chris@16: friend void operator>(int, declared const&) {} Chris@16: }; Chris@16: Chris@16: struct undeclared { declared<> dummy[2]; }; Chris@16: Chris@16: template struct resolve; Chris@16: Chris@16: template<> Chris@16: struct resolve)> Chris@16: { Chris@16: static const int cmp1 = 0; Chris@16: }; Chris@16: Chris@16: template<> Chris@16: struct resolve Chris@16: { Chris@16: template Chris@16: struct cmp1 Chris@16: { Chris@16: static int const cmp2 = 0; Chris@16: }; Chris@16: }; Chris@16: Chris@16: typedef void (*ref_tag)(int&); Chris@16: typedef void (*val_tag)(int ); Chris@16: Chris@16: template struct member; Chris@16: Chris@16: template Chris@16: struct member Chris@16: { Chris@16: T& value; Chris@16: #if !BOOST_SCOPE_EXIT_AUX_TPL_GCC_WORKAROUND_01 Chris@16: member(T& ref) : value(ref) {} Chris@16: #endif Chris@16: }; Chris@16: Chris@16: template Chris@16: struct member Chris@16: { Chris@16: T value; Chris@16: #if !BOOST_SCOPE_EXIT_AUX_TPL_GCC_WORKAROUND_01 Chris@16: member(T& val) : value(val) {} Chris@16: #endif Chris@16: }; Chris@16: Chris@16: template inline T& deref(T* p, ref_tag) { return *p; } Chris@16: template inline T& deref(T& r, val_tag) { return r; } Chris@16: Chris@16: template Chris@16: struct wrapper Chris@16: { Chris@16: typedef T type; Chris@16: }; Chris@16: Chris@16: template wrapper wrap(T&); Chris@16: Chris@16: } } } // namespace Chris@16: Chris@16: #include BOOST_TYPEOF_INCREMENT_REGISTRATION_GROUP() Chris@16: BOOST_TYPEOF_REGISTER_TEMPLATE(boost::scope_exit::detail::wrapper, 1) Chris@16: Chris@16: #define BOOST_SCOPE_EXIT_AUX_ARGS boost_scope_exit_aux_args Chris@16: extern boost::scope_exit::detail::undeclared BOOST_SCOPE_EXIT_AUX_ARGS; Chris@16: Chris@16: #define BOOST_SCOPE_EXIT_AUX_GUARD(id) \ Chris@16: BOOST_PP_CAT(boost_se_guard_, id) Chris@16: Chris@16: #define BOOST_SCOPE_EXIT_AUX_GUARD_T(id) \ Chris@16: BOOST_PP_CAT(boost_se_guard_t_, id) Chris@16: Chris@16: #define BOOST_SCOPE_EXIT_AUX_PARAMS(id) \ Chris@16: BOOST_PP_CAT(boost_se_params_, id) Chris@16: Chris@16: #define BOOST_SCOPE_EXIT_AUX_THIS_T(id) \ Chris@16: BOOST_PP_CAT(boost_se_this_t_, id) Chris@16: Chris@16: #define BOOST_SCOPE_EXIT_AUX_THIS_CAPTURE_T(id) \ Chris@16: BOOST_PP_CAT(boost_se_this_capture_t_, id) Chris@16: Chris@16: #define BOOST_SCOPE_EXIT_DETAIL_PARAMS_T(id) \ Chris@16: BOOST_PP_CAT(boost_se_params_t_, id) Chris@16: Chris@16: #define BOOST_SCOPE_EXIT_DETAIL_TAG(id, i) \ Chris@16: BOOST_PP_SEQ_CAT( (boost_se_tag_)(i)(_)(id) ) Chris@16: Chris@16: #define BOOST_SCOPE_EXIT_DETAIL_PARAM_THIS(id) \ Chris@16: BOOST_PP_SEQ_CAT( (boost_se_param_this_)(id) ) Chris@16: Chris@16: #define BOOST_SCOPE_EXIT_DETAIL_PARAM(id, i, var) \ Chris@16: BOOST_PP_SEQ_CAT( (boost_se_param_)(i)(_)(id) ) Chris@16: Chris@16: #define BOOST_SCOPE_EXIT_DETAIL_PARAM_T(id, i, var) \ Chris@16: BOOST_PP_SEQ_CAT( (boost_se_param_t_)(i)(_)(id) ) Chris@16: Chris@16: #define BOOST_SCOPE_EXIT_DETAIL_CAPTURE_T(id, i, var) \ Chris@16: BOOST_PP_SEQ_CAT( (boost_se_capture_t_)(i)(_)(id) ) Chris@16: Chris@16: #define BOOST_SCOPE_EXIT_AUX_WRAPPED(id, i) \ Chris@16: BOOST_PP_SEQ_CAT( (boost_se_wrapped_t_)(i)(_)(id) ) Chris@16: Chris@16: #define BOOST_SCOPE_EXIT_AUX_DEREF(id, i, var) \ Chris@16: ::boost::scope_exit::detail::deref(var, \ Chris@16: static_cast(0)) Chris@16: Chris@16: #define BOOST_SCOPE_EXIT_AUX_MEMBER(r, id, i, var) \ Chris@16: ::boost::scope_exit::detail::member< \ Chris@16: BOOST_SCOPE_EXIT_DETAIL_PARAM_T(id, i, var), \ Chris@16: BOOST_SCOPE_EXIT_DETAIL_TAG(id, i) \ Chris@16: > BOOST_SCOPE_EXIT_DETAIL_PARAM(id, i, var); Chris@16: Chris@16: #define BOOST_SCOPE_EXIT_AUX_ARG_DECL(r, id_ty, i, var) \ Chris@16: BOOST_PP_COMMA_IF(i) \ Chris@16: BOOST_PP_TUPLE_ELEM(2, 1, id_ty) \ Chris@16: BOOST_SCOPE_EXIT_DETAIL_PARAMS_T(BOOST_PP_TUPLE_ELEM(2, 0, id_ty)):: \ Chris@16: BOOST_SCOPE_EXIT_DETAIL_PARAM_T(BOOST_PP_TUPLE_ELEM(2, 0, id_ty), \ Chris@16: i, var) \ Chris@16: var Chris@16: Chris@16: #define BOOST_SCOPE_EXIT_AUX_ARG(r, id, i, var) \ Chris@16: BOOST_PP_COMMA_IF(i) \ Chris@16: boost_se_params_->BOOST_SCOPE_EXIT_DETAIL_PARAM(id, i, var).value Chris@16: Chris@16: #define BOOST_SCOPE_EXIT_DETAIL_TAG_DECL(r, id, i, var) \ Chris@16: typedef void (*BOOST_SCOPE_EXIT_DETAIL_TAG(id, i))(int var); Chris@16: Chris@16: // Adam Butcher's workaround to deduce `this` type on MSVC revision < 10. Chris@16: // Boost.Typeof for VC71's typeid-based workaround does not work to determine Chris@16: // `this` type due to error C2355 being incorrectly reported. The typical Chris@16: // avoidance strategy implemented below is to make an indirect compile-time Chris@16: // constant by assigning an enum and use that as type-index-- this only works Chris@16: // with the sizeof() approach and not with the typeid() approach. Lorenzo Chris@16: // Caminiti extended this approach to work in type-of emulation mode. This code Chris@16: // is very similar (and somewhat of a duplication) of the code in Chris@16: // boost/typeof/msvc/typeof_impl.hpp). However, this code cannot be integrated Chris@16: // into Boost.Typeof because its final API has to be a `typedef ...` and it Chris@16: // cannot be a `typeof(...)`. Chris@16: #if BOOST_SCOPE_EXIT_AUX_TYPEOF_THIS_MSVC_WORKAROUND_01 Chris@16: Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: Chris@101: #if defined(BOOST_MSVC) Chris@16: # include Chris@16: #endif Chris@16: Chris@16: namespace boost { namespace scope_exit { namespace aux { Chris@16: namespace msvc_typeof_this { Chris@16: Chris@16: // compile-time constant code Chris@101: #if defined(BOOST_MSVC) && defined(_MSC_EXTENSIONS) Chris@16: Chris@16: template struct the_counter; Chris@16: Chris@16: template Chris@16: struct encode_counter { Chris@16: __if_exists(the_counter) { Chris@16: BOOST_STATIC_CONSTANT(unsigned, Chris@16: count=(encode_counter::count)); Chris@16: } Chris@16: __if_not_exists(the_counter) { Chris@16: __if_exists(the_counter) { Chris@16: BOOST_STATIC_CONSTANT(unsigned, Chris@16: count=(encode_counter::count)); Chris@16: } Chris@16: __if_not_exists(the_counter) { Chris@16: __if_exists(the_counter) { Chris@16: BOOST_STATIC_CONSTANT(unsigned, Chris@16: count=(encode_counter::count)); Chris@16: } Chris@16: __if_not_exists(the_counter) { Chris@16: __if_exists(the_counter) { Chris@16: BOOST_STATIC_CONSTANT(unsigned, Chris@16: count=(encode_counter::count)); Chris@16: } Chris@16: __if_not_exists(the_counter) { Chris@16: __if_exists(the_counter) { Chris@16: BOOST_STATIC_CONSTANT(unsigned, Chris@16: count=(encode_counter::count)); Chris@16: } Chris@16: __if_not_exists(the_counter) { Chris@16: BOOST_STATIC_CONSTANT(unsigned,count=N); Chris@16: typedef the_counter type; Chris@16: } Chris@16: } Chris@16: } Chris@16: } Chris@16: } Chris@16: }; Chris@16: Chris@16: #else // compile-time constant code Chris@16: Chris@16: template struct encode_counter : encode_counter {}; Chris@16: Chris@16: template<> struct encode_counter<0> {}; Chris@16: Chris@16: #endif // compile-time constant code Chris@16: Chris@101: #if BOOST_WORKAROUND(BOOST_MSVC, >= 1400) // type-of code Chris@16: Chris@16: struct msvc_extract_type_default_param {}; Chris@16: Chris@16: template Chris@16: struct msvc_extract_type; Chris@16: Chris@16: template Chris@16: struct msvc_extract_type { Chris@16: template Chris@16: struct id2type_impl; Chris@16: Chris@16: typedef id2type_impl id2type; Chris@16: }; Chris@16: Chris@16: template Chris@16: struct msvc_extract_type Chris@16: : msvc_extract_type { Chris@16: template<> Chris@16: struct id2type_impl { // VC8.0 specific bug-feature. Chris@16: typedef T type; Chris@16: }; Chris@16: Chris@16: template Chris@16: struct id2type_impl; Chris@16: Chris@16: typedef id2type_impl id2type; Chris@16: }; Chris@16: Chris@16: template Chris@16: struct msvc_register_type : msvc_extract_type {}; Chris@16: Chris@16: #else // type-of code Chris@16: Chris@16: template Chris@16: struct msvc_extract_type { Chris@16: struct id2type; Chris@16: }; Chris@16: Chris@16: template Chris@16: struct msvc_register_type : msvc_extract_type { Chris@16: typedef msvc_extract_type base_type; Chris@16: struct base_type::id2type { // This uses nice VC6.5 and VC7.1 bug-features. Chris@16: typedef T type; Chris@16: }; Chris@16: }; Chris@16: Chris@16: #endif // typeof code Chris@16: Chris@16: template Chris@16: struct msvc_typeid_wrapper { Chris@16: typedef typename msvc_extract_type Chris@16: >::id2type id2type; Chris@16: typedef typename id2type::type type; Chris@16: }; Chris@16: Chris@16: template<> Chris@16: struct msvc_typeid_wrapper<4> { Chris@16: typedef msvc_typeid_wrapper<4> type; Chris@16: }; Chris@16: Chris@16: template Chris@16: struct encode_type { Chris@16: BOOST_STATIC_CONSTANT(unsigned, value = encode_counter::count); Chris@16: typedef typename msvc_register_type >::id2type type; Chris@16: BOOST_STATIC_CONSTANT(unsigned, next = value + 1); Chris@16: }; Chris@16: Chris@16: template Chris@16: struct sizer { Chris@16: typedef char(*type)[encode_type::value]; Chris@16: }; Chris@16: Chris@16: template Chris@16: typename boost::disable_if< Chris@16: typename boost::is_function::type Chris@16: , typename sizer::type Chris@16: >::type encode_start(T const&); Chris@16: Chris@16: template Chris@16: typename boost::enable_if< Chris@16: typename boost::is_function::type Chris@16: , typename sizer::type Chris@16: >::type encode_start(T&); Chris@16: Chris@16: template Chris@16: msvc_register_type typeof_register_type(const T&, Chris@16: Organizer* = 0); Chris@16: Chris@16: } } } } // namespace Chris@16: Chris@16: #define BOOST_SCOPE_EXIT_AUX_TYPEDEF_TYPEOF_THIS_INDEX_(id) \ Chris@16: BOOST_PP_CAT(boost_se_thistype_index_, id) Chris@16: Chris@16: #define BOOST_SCOPE_EXIT_DETAIL_TYPEDEF_TYPEOF_THIS(id, ty, new_type) \ Chris@16: /* unfortunately, we need to go via this enum which causes this to be */ \ Chris@16: /* a typedef construct and not a typeof (so this code cannot be */ \ Chris@16: /* integrated into Boost.Typeof) */ \ Chris@16: enum { \ Chris@16: BOOST_SCOPE_EXIT_AUX_TYPEDEF_TYPEOF_THIS_INDEX_(id) = sizeof( \ Chris@16: *::boost::scope_exit::aux::msvc_typeof_this::encode_start(this)) \ Chris@16: }; \ Chris@16: typedef \ Chris@16: ty ::boost::scope_exit::aux::msvc_typeof_this::msvc_typeid_wrapper< \ Chris@16: BOOST_SCOPE_EXIT_AUX_TYPEDEF_TYPEOF_THIS_INDEX_(id) \ Chris@16: >::type \ Chris@16: new_type \ Chris@16: ; Chris@16: Chris@16: #else // TYPEOF_THIS_MSVC_WORKAROUND Chris@16: Chris@16: #define BOOST_SCOPE_EXIT_DETAIL_TYPEDEF_TYPEOF_THIS(id, ty, new_type) \ Chris@16: typedef /* trailing `EMPTY()` handles empty `ty` */ \ Chris@16: BOOST_PP_IIF(BOOST_PP_IS_EMPTY(ty BOOST_PP_EMPTY()), \ Chris@16: BOOST_TYPEOF \ Chris@16: , \ Chris@16: BOOST_TYPEOF_TPL \ Chris@16: )(this) \ Chris@16: new_type \ Chris@16: ; Chris@16: Chris@16: #endif // TYPEOF_THIS_MSVC_WORKAROUND Chris@16: Chris@16: #if BOOST_SCOPE_EXIT_AUX_TPL_GCC_WORKAROUND_01 Chris@16: Chris@16: #define BOOST_SCOPE_EXIT_AUX_PARAMS_T_CTOR(id, ty, captures, has_this) \ Chris@16: /* expand to nothing */ Chris@16: Chris@16: #define BOOST_SCOPE_EXIT_DETAIL_PARAM_INIT(r, id, i, var) \ Chris@16: BOOST_PP_COMMA_IF(i) { BOOST_SCOPE_EXIT_AUX_DEREF(id, i, var) } Chris@16: Chris@16: #define BOOST_SCOPE_EXIT_AUX_PARAMS_INIT(id, captures, has_this) \ Chris@16: BOOST_PP_EXPR_IIF(BOOST_PP_BITOR(has_this, \ Chris@16: BOOST_PP_LIST_IS_CONS(captures)), \ Chris@16: = { \ Chris@16: ) \ Chris@16: BOOST_PP_LIST_FOR_EACH_I(BOOST_SCOPE_EXIT_DETAIL_PARAM_INIT, id, captures) \ Chris@16: BOOST_PP_COMMA_IF(BOOST_PP_BITAND(BOOST_PP_LIST_IS_CONS(captures), \ Chris@16: has_this)) \ Chris@16: BOOST_PP_EXPR_IIF(has_this, this) /* no extra {...} needed here */ \ Chris@16: BOOST_PP_EXPR_IIF(BOOST_PP_BITOR(has_this, \ Chris@16: BOOST_PP_LIST_IS_CONS(captures)), \ Chris@16: } /* trailing `;` will be added by the caller */ \ Chris@16: ) Chris@16: Chris@16: #else // TPL_GCC_WORKAROUND Chris@16: Chris@16: #define BOOST_SCOPE_EXIT_AUX_CTOR_ARG(r, id, i, var) \ Chris@16: BOOST_PP_COMMA_IF(i) \ Chris@16: BOOST_SCOPE_EXIT_DETAIL_PARAM_T(id, i, var) & BOOST_PP_CAT(a, i) Chris@16: Chris@16: #define BOOST_SCOPE_EXIT_AUX_MEMBER_INIT(r, id, i, var) \ Chris@16: BOOST_PP_COMMA_IF(i) \ Chris@16: BOOST_SCOPE_EXIT_DETAIL_PARAM(id, i, var) ( BOOST_PP_CAT(a, i) ) Chris@16: Chris@16: #define BOOST_SCOPE_EXIT_AUX_CTOR_ARG_THIS_NAME(id) \ Chris@16: BOOST_PP_CAT(boost_se_this_arg_, id) Chris@16: Chris@16: #define BOOST_SCOPE_EXIT_AUX_CTOR_ARG_THIS(id, ty, comma01) \ Chris@16: BOOST_PP_COMMA_IF(comma01) \ Chris@16: ty BOOST_SCOPE_EXIT_DETAIL_PARAMS_T(id)::BOOST_SCOPE_EXIT_AUX_THIS_T(id) \ Chris@16: BOOST_SCOPE_EXIT_AUX_CTOR_ARG_THIS_NAME(id) /* ptr so no & */ Chris@16: Chris@16: #define BOOST_SCOPE_EXIT_AUX_MEMBER_THIS_INIT(id, comma01) \ Chris@16: BOOST_PP_COMMA_IF(comma01) \ Chris@16: BOOST_SCOPE_EXIT_DETAIL_PARAM_THIS(id)( \ Chris@16: BOOST_SCOPE_EXIT_AUX_CTOR_ARG_THIS_NAME(id)) Chris@16: Chris@16: #define BOOST_SCOPE_EXIT_AUX_PARAMS_T_CTOR(id, ty, captures, has_this) \ Chris@16: BOOST_SCOPE_EXIT_DETAIL_PARAMS_T(id)( \ Chris@16: BOOST_PP_LIST_FOR_EACH_I(BOOST_SCOPE_EXIT_AUX_CTOR_ARG, id, captures) \ Chris@16: BOOST_PP_IIF(has_this, \ Chris@16: BOOST_SCOPE_EXIT_AUX_CTOR_ARG_THIS \ Chris@16: , \ Chris@16: BOOST_PP_TUPLE_EAT(3) \ Chris@16: )(id, ty, BOOST_PP_LIST_IS_CONS(captures)) \ Chris@16: ) \ Chris@16: BOOST_PP_EXPR_IIF(BOOST_PP_BITOR(BOOST_PP_LIST_IS_CONS(captures), \ Chris@16: has_this), \ Chris@16: : \ Chris@16: ) \ Chris@16: BOOST_PP_LIST_FOR_EACH_I(BOOST_SCOPE_EXIT_AUX_MEMBER_INIT, id, \ Chris@16: captures) \ Chris@16: BOOST_PP_IIF(has_this, \ Chris@16: BOOST_SCOPE_EXIT_AUX_MEMBER_THIS_INIT \ Chris@16: , \ Chris@16: BOOST_PP_TUPLE_EAT(2) \ Chris@16: )(id, BOOST_PP_LIST_IS_CONS(captures)) \ Chris@16: {} Chris@16: Chris@16: #define BOOST_SCOPE_EXIT_DETAIL_PARAM_INIT(r, id, i, var) \ Chris@16: BOOST_PP_COMMA_IF(i) BOOST_SCOPE_EXIT_AUX_DEREF(id,i,var) Chris@16: Chris@16: #define BOOST_SCOPE_EXIT_AUX_PARAMS_INIT(id, captures, has_this) \ Chris@16: BOOST_PP_LPAREN_IF(BOOST_PP_BITOR(has_this, \ Chris@16: BOOST_PP_LIST_IS_CONS(captures))) \ Chris@16: BOOST_PP_LIST_FOR_EACH_I(BOOST_SCOPE_EXIT_DETAIL_PARAM_INIT, id, captures) \ Chris@16: BOOST_PP_COMMA_IF(BOOST_PP_BITAND(BOOST_PP_LIST_IS_CONS(captures), \ Chris@16: has_this)) \ Chris@16: BOOST_PP_EXPR_IIF(has_this, this) \ Chris@16: BOOST_PP_RPAREN_IF(BOOST_PP_BITOR(has_this, \ Chris@16: BOOST_PP_LIST_IS_CONS(captures))) Chris@16: Chris@16: #endif // TPL_GCC_WORKAROUND Chris@16: Chris@16: #if defined(BOOST_TYPEOF_EMULATION) Chris@16: Chris@16: #define BOOST_SCOPE_EXIT_DETAIL_CAPTURE_DECL(r, id_ty, i, var) \ Chris@16: struct BOOST_SCOPE_EXIT_AUX_WRAPPED(BOOST_PP_TUPLE_ELEM(2, 0, id_ty), i) \ Chris@16: /* no need to use TYPEOF_TPL here because it's within inheritance */ \ Chris@16: : BOOST_TYPEOF(::boost::scope_exit::detail::wrap( \ Chris@16: BOOST_SCOPE_EXIT_AUX_DEREF(BOOST_PP_TUPLE_ELEM(2, 0, id_ty), \ Chris@16: i, var))) \ Chris@16: {}; \ Chris@16: typedef BOOST_PP_TUPLE_ELEM(2, 1, id_ty) \ Chris@16: BOOST_SCOPE_EXIT_AUX_WRAPPED(BOOST_PP_TUPLE_ELEM(2, 0, id_ty), i)::type\ Chris@16: BOOST_SCOPE_EXIT_DETAIL_CAPTURE_T(BOOST_PP_TUPLE_ELEM(2, 0, id_ty), \ Chris@16: i, var) \ Chris@16: ; Chris@16: Chris@16: #elif defined(BOOST_INTEL) Chris@16: Chris@16: #define BOOST_SCOPE_EXIT_DETAIL_CAPTURE_DECL(r, id_ty, i, var) \ Chris@16: typedef \ Chris@16: /* no TYPEOF_TPL here because uses TYPEOF_KEYWORD directly */ \ Chris@16: BOOST_TYPEOF_KEYWORD(BOOST_SCOPE_EXIT_AUX_DEREF( \ Chris@16: BOOST_PP_TUPLE_ELEM(2, 0, id_ty), i, var)) \ Chris@16: BOOST_SCOPE_EXIT_DETAIL_CAPTURE_T(BOOST_PP_TUPLE_ELEM(2, 0, id_ty), \ Chris@16: i, var) \ Chris@16: ; Chris@16: Chris@16: #else Chris@16: Chris@16: #define BOOST_SCOPE_EXIT_DETAIL_CAPTURE_DECL(r, id_ty, i, var) \ Chris@16: typedef \ Chris@16: /* no need to use TYPEOF_TPL here because it's a typedef */ \ Chris@16: BOOST_TYPEOF(::boost::scope_exit::detail::wrap( \ Chris@16: BOOST_SCOPE_EXIT_AUX_DEREF(BOOST_PP_TUPLE_ELEM(2, 0, id_ty), \ Chris@16: i, var))) \ Chris@16: BOOST_SCOPE_EXIT_AUX_WRAPPED(BOOST_PP_TUPLE_ELEM(2, 0, id_ty), i) \ Chris@16: ; \ Chris@16: typedef BOOST_PP_TUPLE_ELEM(2, 1, id_ty) \ Chris@16: BOOST_SCOPE_EXIT_AUX_WRAPPED(BOOST_PP_TUPLE_ELEM(2, 0, id_ty), i)::type\ Chris@16: BOOST_SCOPE_EXIT_DETAIL_CAPTURE_T(BOOST_PP_TUPLE_ELEM(2, 0, id_ty), \ Chris@16: i, var) \ Chris@16: ; Chris@16: Chris@16: #endif Chris@16: Chris@16: #define BOOST_SCOPE_EXIT_DETAIL_PARAM_DECL(r, id_ty, i, var) \ Chris@16: typedef \ Chris@16: BOOST_SCOPE_EXIT_DETAIL_CAPTURE_T(BOOST_PP_TUPLE_ELEM(2, 0, id_ty), \ Chris@16: i, var) \ Chris@16: BOOST_SCOPE_EXIT_DETAIL_PARAM_T(BOOST_PP_TUPLE_ELEM(2, 0, id_ty), \ Chris@16: i, var) \ Chris@16: ; Chris@16: Chris@16: // Traits. Chris@16: Chris@16: #define BOOST_SCOPE_EXIT_AUX_TRAITS_OP_CAPTURE(d, captures, this01, capture) \ Chris@16: (BOOST_PP_LIST_APPEND(captures, (capture, BOOST_PP_NIL)), this01) Chris@16: Chris@16: #define BOOST_SCOPE_EXIT_AUX_TRAITS_OP_THIS(d, captures, this01, this_) \ Chris@16: (captures, 1 /* has this (note, no error if multiple this_) */) Chris@16: Chris@16: #define BOOST_SCOPE_EXIT_AUX_TRAITS_OP(d, captures_this, capture) \ Chris@101: BOOST_PP_IIF(BOOST_SCOPE_EXIT_AUX_PP_KEYWORD_IS_THISUNDERSCORE_BACK(\ Chris@16: capture), \ Chris@16: BOOST_SCOPE_EXIT_AUX_TRAITS_OP_THIS \ Chris@16: , \ Chris@16: BOOST_SCOPE_EXIT_AUX_TRAITS_OP_CAPTURE \ Chris@16: )(d, BOOST_PP_TUPLE_ELEM(2, 0, captures_this), \ Chris@16: BOOST_PP_TUPLE_ELEM(2, 1, captures_this), capture) Chris@16: Chris@16: // ref_val: & | = Chris@16: #define BOOST_SCOPE_EXIT_AUX_TRAITS_ALL_OP(ref_val, traits) \ Chris@16: ( \ Chris@16: BOOST_PP_LIST_APPEND((ref_val, BOOST_PP_NIL), \ Chris@16: BOOST_SCOPE_EXIT_AUX_TRAITS_CAPTURES(traits)) \ Chris@16: , \ Chris@16: BOOST_SCOPE_EXIT_AUX_TRAITS_HAS_THIS(traits) \ Chris@16: ) Chris@16: Chris@16: #define BOOST_SCOPE_EXIT_AUX_TRAITS(captures) \ Chris@16: BOOST_PP_LIST_FOLD_LEFT(BOOST_SCOPE_EXIT_AUX_TRAITS_OP, \ Chris@16: (BOOST_PP_NIL, 0), captures) Chris@16: Chris@16: #define BOOST_SCOPE_EXIT_AUX_TRAITS_ALL(captures) \ Chris@16: BOOST_SCOPE_EXIT_AUX_TRAITS_ALL_OP(BOOST_PP_LIST_FIRST(captures), \ Chris@16: BOOST_SCOPE_EXIT_AUX_TRAITS(BOOST_PP_LIST_REST(captures))) Chris@16: Chris@16: #define BOOST_SCOPE_EXIT_AUX_TRAITS_CAPTURES(traits) \ Chris@16: BOOST_PP_TUPLE_ELEM(2, 0, traits) Chris@16: Chris@16: #define BOOST_SCOPE_EXIT_AUX_TRAITS_HAS_THIS(traits) \ Chris@16: BOOST_PP_TUPLE_ELEM(2, 1, traits) Chris@16: Chris@16: #ifndef BOOST_NO_CXX11_LAMBDAS Chris@16: Chris@16: namespace boost { namespace scope_exit { namespace aux { Chris@16: Chris@16: template Chris@16: struct guard { // With object `this_` (for backward compatibility). Chris@16: explicit guard(This _this) : this_(_this) {} Chris@16: ~guard() { if(f_) f_(this_); } Chris@16: template Chris@16: void operator=(Lambda f) { f_ = f; } Chris@16: private: Chris@16: This this_; Chris@16: boost::function f_; Chris@16: }; Chris@16: Chris@16: template<> Chris@16: struct guard { // Without object `this_` (could capture `this` directly). Chris@16: ~guard() { if(f_) f_(); } Chris@16: template Chris@16: void operator=(Lambda f) { f_ = f; } Chris@16: private: Chris@16: boost::function f_; Chris@16: }; Chris@16: Chris@16: } } } // namespace Chris@16: Chris@16: #define BOOST_SCOPE_EXIT_AUX_LAMBDA_PARAMS(id) \ Chris@16: BOOST_PP_CAT(boost_se_lambda_params_, id) Chris@16: Chris@16: #define BOOST_SCOPE_EXIT_AUX_LAMBDA_THIS_CAPTURE_TYPE(id) \ Chris@16: BOOST_PP_CAT(boost_se_lambda_this_t_, id) Chris@16: Chris@16: #define BOOST_SCOPE_EXIT_AUX_LAMBDA_THIS_PARAM_TYPE(id) \ Chris@16: BOOST_PP_CAT(boost_se_lambda_this_capture_t_, id) Chris@16: Chris@16: #define BOOST_SCOPE_EXIT_AUX_LAMBDA_THIS_TYPE(id, ty) \ Chris@16: ty BOOST_SCOPE_EXIT_AUX_LAMBDA_PARAMS(id):: \ Chris@16: BOOST_SCOPE_EXIT_AUX_LAMBDA_THIS_PARAM_TYPE(id) Chris@16: Chris@16: // Precondition: HAS_THIS(traits). Chris@16: #define BOOST_SCOPE_EXIT_AUX_LAMBDA_THIS_TYPEDEFS(id, ty, traits) \ Chris@16: BOOST_SCOPE_EXIT_DETAIL_TYPEDEF_TYPEOF_THIS(id, ty, \ Chris@16: BOOST_SCOPE_EXIT_AUX_LAMBDA_THIS_CAPTURE_TYPE(id)) \ Chris@16: /* capture type for workaround GCC internal error (even on later C++11) */ \ Chris@16: struct BOOST_SCOPE_EXIT_AUX_LAMBDA_PARAMS(id) { \ Chris@16: typedef BOOST_SCOPE_EXIT_AUX_LAMBDA_THIS_CAPTURE_TYPE(id) \ Chris@16: BOOST_SCOPE_EXIT_AUX_LAMBDA_THIS_PARAM_TYPE(id); \ Chris@16: }; Chris@16: Chris@16: #define BOOST_SCOPE_EXIT_AUX_IMPL_LAMBDA(id, ty, traits) \ Chris@16: BOOST_PP_IIF(BOOST_SCOPE_EXIT_AUX_TRAITS_HAS_THIS(traits), \ Chris@16: /* no need for TYPEDEF THIS MSVC workaround on C++11 */ \ Chris@16: BOOST_SCOPE_EXIT_AUX_LAMBDA_THIS_TYPEDEFS \ Chris@16: , \ Chris@16: BOOST_PP_TUPLE_EAT(3) \ Chris@16: )(id, ty, traits) \ Chris@16: ::boost::scope_exit::aux::guard< \ Chris@16: BOOST_PP_IIF(BOOST_SCOPE_EXIT_AUX_TRAITS_HAS_THIS(traits), \ Chris@16: BOOST_SCOPE_EXIT_AUX_LAMBDA_THIS_TYPE \ Chris@16: , \ Chris@16: BOOST_PP_TUPLE_EAT(2) \ Chris@16: )(id, ty) \ Chris@16: > BOOST_SCOPE_EXIT_AUX_GUARD(id) \ Chris@16: BOOST_PP_EXPR_IIF(BOOST_SCOPE_EXIT_AUX_TRAITS_HAS_THIS(traits), \ Chris@16: (this) \ Chris@16: ) \ Chris@16: ; \ Chris@16: BOOST_SCOPE_EXIT_AUX_GUARD(id) = [ \ Chris@16: BOOST_PP_LIST_ENUM(BOOST_SCOPE_EXIT_AUX_TRAITS_CAPTURES(traits)) \ Chris@16: ]( \ Chris@16: BOOST_PP_IIF(BOOST_SCOPE_EXIT_AUX_TRAITS_HAS_THIS(traits), \ Chris@16: BOOST_SCOPE_EXIT_AUX_LAMBDA_THIS_TYPE \ Chris@16: , \ Chris@16: BOOST_PP_TUPLE_EAT(2) \ Chris@16: )(id, ty) \ Chris@16: BOOST_PP_EXPR_IIF(BOOST_SCOPE_EXIT_AUX_TRAITS_HAS_THIS(traits), this_) \ Chris@16: ) mutable /* can change value captures (as with SCOPE_EXIT) */ -> void Chris@16: Chris@16: #endif // Lambdas. Chris@16: Chris@16: #if defined(BOOST_SCOPE_EXIT_CONFIG_USE_LAMBDAS) && \ Chris@16: !defined(BOOST_NO_CXX11_LAMBDAS) // Use lambda for SCOPE_EXIT (not just _ALL). Chris@16: Chris@16: #define BOOST_SCOPE_EXIT_AUX_IMPL(id, ty, traits) \ Chris@16: BOOST_SCOPE_EXIT_AUX_IMPL_LAMBDA(id, ty, traits) Chris@16: Chris@16: #else // Not using lambdas. Chris@16: Chris@16: // ty: EMPTY() | typename Chris@16: #define BOOST_SCOPE_EXIT_AUX_IMPL(id, ty, traits) \ Chris@16: BOOST_PP_LIST_FOR_EACH_I(BOOST_SCOPE_EXIT_DETAIL_TAG_DECL, id, \ Chris@16: BOOST_SCOPE_EXIT_AUX_TRAITS_CAPTURES(traits)) \ Chris@16: BOOST_PP_LIST_FOR_EACH_I(BOOST_SCOPE_EXIT_DETAIL_CAPTURE_DECL, (id, ty), \ Chris@16: BOOST_SCOPE_EXIT_AUX_TRAITS_CAPTURES(traits)) \ Chris@16: BOOST_PP_IIF(BOOST_SCOPE_EXIT_AUX_TRAITS_HAS_THIS(traits), \ Chris@16: BOOST_SCOPE_EXIT_DETAIL_TYPEDEF_TYPEOF_THIS \ Chris@16: , \ Chris@16: BOOST_PP_TUPLE_EAT(3) \ Chris@16: )(id, ty, BOOST_SCOPE_EXIT_AUX_THIS_CAPTURE_T(id)) \ Chris@16: struct BOOST_SCOPE_EXIT_DETAIL_PARAMS_T(id) { \ Chris@16: /* interim capture types to workaround internal errors on old GCC */ \ Chris@16: BOOST_PP_LIST_FOR_EACH_I(BOOST_SCOPE_EXIT_DETAIL_PARAM_DECL, (id, ty), \ Chris@16: BOOST_SCOPE_EXIT_AUX_TRAITS_CAPTURES(traits)) \ Chris@16: BOOST_PP_EXPR_IIF(BOOST_SCOPE_EXIT_AUX_TRAITS_HAS_THIS(traits), \ Chris@16: typedef BOOST_SCOPE_EXIT_AUX_THIS_CAPTURE_T(id) \ Chris@16: BOOST_SCOPE_EXIT_AUX_THIS_T(id) ; \ Chris@16: ) \ Chris@16: BOOST_PP_LIST_FOR_EACH_I(BOOST_SCOPE_EXIT_AUX_MEMBER, id, \ Chris@16: BOOST_SCOPE_EXIT_AUX_TRAITS_CAPTURES(traits)) \ Chris@16: BOOST_PP_EXPR_IIF(BOOST_SCOPE_EXIT_AUX_TRAITS_HAS_THIS(traits), \ Chris@16: BOOST_SCOPE_EXIT_AUX_THIS_T(id) \ Chris@16: BOOST_SCOPE_EXIT_DETAIL_PARAM_THIS(id) ; \ Chris@16: ) \ Chris@16: BOOST_SCOPE_EXIT_AUX_PARAMS_T_CTOR(id, ty, \ Chris@16: BOOST_SCOPE_EXIT_AUX_TRAITS_CAPTURES(traits), \ Chris@16: BOOST_SCOPE_EXIT_AUX_TRAITS_HAS_THIS(traits)) \ Chris@16: } BOOST_SCOPE_EXIT_AUX_PARAMS(id) \ Chris@16: BOOST_SCOPE_EXIT_AUX_PARAMS_INIT(id, \ Chris@16: BOOST_SCOPE_EXIT_AUX_TRAITS_CAPTURES(traits), \ Chris@16: BOOST_SCOPE_EXIT_AUX_TRAITS_HAS_THIS(traits)) \ Chris@16: ; \ Chris@16: ::boost::scope_exit::detail::declared< \ Chris@16: ::boost::scope_exit::detail::resolve< \ Chris@16: sizeof(BOOST_SCOPE_EXIT_AUX_ARGS) \ Chris@16: >::cmp1<0>::cmp2 \ Chris@16: > BOOST_SCOPE_EXIT_AUX_ARGS; \ Chris@16: BOOST_SCOPE_EXIT_AUX_ARGS.value = &BOOST_SCOPE_EXIT_AUX_PARAMS(id); \ Chris@16: struct BOOST_SCOPE_EXIT_AUX_GUARD_T(id) { \ Chris@16: BOOST_SCOPE_EXIT_DETAIL_PARAMS_T(id)* boost_se_params_; \ Chris@16: BOOST_SCOPE_EXIT_AUX_GUARD_T(id) (void* boost_se_params) \ Chris@16: : boost_se_params_( \ Chris@16: (BOOST_SCOPE_EXIT_DETAIL_PARAMS_T(id)*)boost_se_params) \ Chris@16: {} \ Chris@16: ~BOOST_SCOPE_EXIT_AUX_GUARD_T(id)() { \ Chris@16: boost_se_body( \ Chris@16: BOOST_PP_LIST_FOR_EACH_I(BOOST_SCOPE_EXIT_AUX_ARG, id, \ Chris@16: BOOST_SCOPE_EXIT_AUX_TRAITS_CAPTURES(traits)) \ Chris@16: BOOST_PP_COMMA_IF(BOOST_PP_BITAND(BOOST_PP_LIST_IS_CONS( \ Chris@16: BOOST_SCOPE_EXIT_AUX_TRAITS_CAPTURES(traits)), \ Chris@16: BOOST_SCOPE_EXIT_AUX_TRAITS_HAS_THIS(traits))) \ Chris@16: BOOST_PP_EXPR_IIF(BOOST_SCOPE_EXIT_AUX_TRAITS_HAS_THIS( \ Chris@16: traits), \ Chris@16: boost_se_params_->BOOST_SCOPE_EXIT_DETAIL_PARAM_THIS(id) \ Chris@16: ) \ Chris@16: ); \ Chris@16: } \ Chris@16: static void boost_se_body( \ Chris@16: BOOST_PP_LIST_FOR_EACH_I(BOOST_SCOPE_EXIT_AUX_ARG_DECL, (id, ty), \ Chris@16: BOOST_SCOPE_EXIT_AUX_TRAITS_CAPTURES(traits)) \ Chris@16: BOOST_PP_COMMA_IF(BOOST_PP_BITAND(BOOST_PP_LIST_IS_CONS( \ Chris@16: BOOST_SCOPE_EXIT_AUX_TRAITS_CAPTURES(traits)), \ Chris@16: BOOST_SCOPE_EXIT_AUX_TRAITS_HAS_THIS(traits))) \ Chris@16: BOOST_PP_EXPR_IIF(BOOST_SCOPE_EXIT_AUX_TRAITS_HAS_THIS(traits), \ Chris@16: ty BOOST_SCOPE_EXIT_DETAIL_PARAMS_T(id):: \ Chris@16: BOOST_SCOPE_EXIT_AUX_THIS_T(id) this_ \ Chris@16: ) \ Chris@16: ) Chris@16: Chris@16: #endif // Using lambdas. Chris@16: Chris@16: // PUBLIC // Chris@16: Chris@16: #if defined(BOOST_NO_CXX11_VARIADIC_MACROS) // No variadic macros (sequences only). Chris@16: # define BOOST_SCOPE_EXIT_ID(id, void_or_seq) \ Chris@16: BOOST_SCOPE_EXIT_AUX_IMPL(id, BOOST_PP_EMPTY(), \ Chris@16: BOOST_SCOPE_EXIT_AUX_TRAITS( \ Chris@101: BOOST_SCOPE_EXIT_AUX_PP_VOID_LIST(void_or_seq))) Chris@16: # define BOOST_SCOPE_EXIT_ID_TPL(id, void_or_seq) \ Chris@16: BOOST_SCOPE_EXIT_AUX_IMPL(id, typename, \ Chris@16: BOOST_SCOPE_EXIT_AUX_TRAITS( \ Chris@101: BOOST_SCOPE_EXIT_AUX_PP_VOID_LIST(void_or_seq))) Chris@16: # define BOOST_SCOPE_EXIT(void_or_seq) \ Chris@101: BOOST_SCOPE_EXIT_ID(BOOST_SCOPE_EXIT_AUX_PP_LINE_COUNTER, \ Chris@16: void_or_seq) Chris@16: # define BOOST_SCOPE_EXIT_TPL(void_or_seq) \ Chris@101: BOOST_SCOPE_EXIT_ID_TPL(BOOST_SCOPE_EXIT_AUX_PP_LINE_COUNTER, \ Chris@16: void_or_seq) Chris@16: # if !defined(BOOST_NO_CXX11_LAMBDAS) Chris@16: # define BOOST_SCOPE_EXIT_ALL_ID(id, seq) \ Chris@16: BOOST_SCOPE_EXIT_AUX_IMPL_LAMBDA(id, \ Chris@16: /* C++11 allows to use typename outside templates so */ \ Chris@16: /* always typename here and no need for ..._ALL_TPL */ \ Chris@16: /* (if a C++11 compiler does not implement this use of */ \ Chris@16: /* typename, always use `this` instead of `this_`) */ \ Chris@16: typename, \ Chris@16: BOOST_SCOPE_EXIT_AUX_TRAITS_ALL( \ Chris@101: BOOST_SCOPE_EXIT_AUX_PP_NON_VOID_LIST(seq))) Chris@16: # define BOOST_SCOPE_EXIT_ALL(seq) \ Chris@16: BOOST_SCOPE_EXIT_ALL_ID( \ Chris@101: BOOST_SCOPE_EXIT_AUX_PP_LINE_COUNTER, seq) Chris@16: # endif Chris@16: #else // Variadic macros (both sequences and variadic tuples). Chris@16: # define BOOST_SCOPE_EXIT_ID(id, ...) \ Chris@16: BOOST_SCOPE_EXIT_AUX_IMPL(id, BOOST_PP_EMPTY(), \ Chris@16: BOOST_SCOPE_EXIT_AUX_TRAITS( \ Chris@101: BOOST_SCOPE_EXIT_AUX_PP_VOID_LIST(__VA_ARGS__))) Chris@16: # define BOOST_SCOPE_EXIT_ID_TPL(id, ...) \ Chris@16: BOOST_SCOPE_EXIT_AUX_IMPL(id, typename, \ Chris@16: BOOST_SCOPE_EXIT_AUX_TRAITS( \ Chris@101: BOOST_SCOPE_EXIT_AUX_PP_VOID_LIST(__VA_ARGS__))) Chris@16: # define BOOST_SCOPE_EXIT(...) \ Chris@101: BOOST_SCOPE_EXIT_ID(BOOST_SCOPE_EXIT_AUX_PP_LINE_COUNTER, \ Chris@16: __VA_ARGS__) Chris@16: # define BOOST_SCOPE_EXIT_TPL(...) \ Chris@101: BOOST_SCOPE_EXIT_ID_TPL(BOOST_SCOPE_EXIT_AUX_PP_LINE_COUNTER, \ Chris@16: __VA_ARGS__) Chris@16: # if !defined(BOOST_NO_CXX11_LAMBDAS) Chris@16: # define BOOST_SCOPE_EXIT_ALL_ID(id, ...) \ Chris@16: BOOST_SCOPE_EXIT_AUX_IMPL_LAMBDA(id, \ Chris@16: /* C++11 allows to use typename outside templates so */ \ Chris@16: /* always typename here and no need for ..._ALL_TPL */ \ Chris@16: /* (if a C++11 compiler does not implement this use of */ \ Chris@16: /* typename, always use `this` instead of `this_`) */ \ Chris@16: typename, \ Chris@16: BOOST_SCOPE_EXIT_AUX_TRAITS_ALL( \ Chris@101: BOOST_SCOPE_EXIT_AUX_PP_NON_VOID_LIST( \ Chris@16: __VA_ARGS__))) Chris@16: # define BOOST_SCOPE_EXIT_ALL(...) \ Chris@16: BOOST_SCOPE_EXIT_ALL_ID( \ Chris@101: BOOST_SCOPE_EXIT_AUX_PP_LINE_COUNTER, __VA_ARGS__) Chris@16: # endif Chris@16: #endif // Variadics. Chris@16: Chris@16: #if defined(BOOST_SCOPE_EXIT_CONFIG_USE_LAMBDAS) && \ Chris@16: !defined(BOOST_NO_CXX11_LAMBDAS) // Use lambdas for SCOPE_EXIT (not just ALL). Chris@16: # define BOOST_SCOPE_EXIT_END_ID(id) \ Chris@16: ; /* lambdas ended with just `;` */ Chris@16: #else // Not using lambdas. Chris@16: # define BOOST_SCOPE_EXIT_END_ID(id) \ Chris@16: } BOOST_SCOPE_EXIT_AUX_GUARD(id)(BOOST_SCOPE_EXIT_AUX_ARGS.value); Chris@16: #endif // Using lambdas. Chris@16: #define BOOST_SCOPE_EXIT_END \ Chris@101: BOOST_SCOPE_EXIT_END_ID(BOOST_SCOPE_EXIT_AUX_PP_LINE_COUNTER) Chris@16: Chris@16: // DOCUMENTATION // Chris@16: Chris@16: #else // DOXYGEN Chris@16: Chris@16: /** @file Chris@16: @brief Scope exits allow to execute arbitrary code when the enclosing scope Chris@16: exits. Chris@16: */ Chris@16: Chris@16: /** Chris@16: @brief This macro declares a scope exit. Chris@16: Chris@16: The scope exit declaration schedules the execution of the scope exit body at Chris@16: the exit of the enclosing scope: Chris@16: Chris@16: @code Chris@16: { // Some local scope. Chris@16: ... Chris@16: BOOST_SCOPE_EXIT(capture_list) { Chris@16: ... // Body code. Chris@16: } BOOST_SCOPE_EXIT_END Chris@16: ... Chris@16: } Chris@16: @endcode Chris@16: Chris@16: The enclosing scope must be local. Chris@16: If multiple scope exits are declared within the same enclosing scope, the scope Chris@16: exit bodies are executed in the reversed order of their declarations. Chris@16: Note how the end of the scope exit body must be marked by Chris@16: @RefMacro{BOOST_SCOPE_EXIT_END}. Chris@16: Chris@16: @Params Chris@16: @Param{capture_list, Chris@16: On compilers that support variadic macros (see also Boost.Config Chris@16: BOOST_NO_CXX11_VARIADIC_MACROS)\, the capture list syntax is defined by the Chris@16: following grammar: Chris@16: @code Chris@16: capture_list: Chris@16: void | capture_tuple | capture_sequence Chris@16: capture_tuple: Chris@16: capture\, capture\, ... Chris@16: capture_sequence: Chris@16: (capture) (capture) ... Chris@16: capture: Chris@16: [&]variable | this_ Chris@16: @endcode Chris@16: On compilers that do not support variadic macros\, capture_tuple cannot Chris@16: be used: Chris@16: @code Chris@16: capture_list: Chris@16: void | capture_sequence Chris@16: @endcode Chris@16: Furthermore\, if @RefMacro{BOOST_SCOPE_EXIT_CONFIG_USE_LAMBDAS} is defined on Chris@16: C++11 compilers that support lambda functions (i.e.\, Boost.Config's BOOST_NO_CXX11_LAMBDAS is not defined) then a semicolon ; can be used instead of Chris@16: @RefMacro{BOOST_SCOPE_EXIT_END} and this can be used instead of Chris@16: this_: Chris@16: @code Chris@16: capture: Chris@16: [&]variable | this_ | this Chris@16: @endcode Chris@16: Chris@16: (Lexical conventions: token1 | token2 means either token1 or Chris@16: token2; [token] means either token or nothing; Chris@16: {expression} means the tokens resulting from the expression.) Chris@16: } Chris@16: @EndParams Chris@16: Chris@16: Note that on compilers that support variadic macros (most of moder compliers Chris@16: and all C++11 compilers), the capture list can be specified as a Chris@16: comma-separated list of tokens (this is the preferred syntax). Chris@16: However, on all compilers the same macro @RefMacro{BOOST_SCOPE_EXIT} also Chris@16: allows to specify the capture list as a Boost.Preprocessor sequence of tokens Chris@16: (for supporting compilers without variadic macros and for backward compatibility with older versions of this library). Chris@16: Chris@16: The name variable of each captured variable must be a valid name in the Chris@16: enclosing scope and it must appear exactly once in the capture list. Chris@16: If a capture starts with the ampersand sign &, the corresponding Chris@16: variable will be available by reference within the scope exit body; otherwise, Chris@16: a copy of the variable will be made at the point of the scope exit declaration Chris@16: and that copy will be available inside the scope exit body (in this case, the Chris@16: variable's type must be CopyConstructible). Chris@16: Chris@16: From within a member function, the object this can be captured using the Chris@16: special name this_ in both the capture list and the scope exit body Chris@16: (using this instead of this_ in the scope exit body leads to Chris@16: undefined behaviour). Chris@16: Chris@16: It is possible to capture no variable by specifying the capture list as Chris@16: void (regardless of variadic macro support). Chris@16: Chris@16: Only variables listed in the capture list, static variables, extern Chris@16: variables, global variables, functions, and enumerations from the enclosing Chris@16: scope can be used inside the scope exit body. Chris@16: Chris@16: On various GCC versions the special macro @RefMacro{BOOST_SCOPE_EXIT_TPL} must Chris@16: be used instead of @RefMacro{BOOST_SCOPE_EXIT} within templates (to maximize Chris@16: portability, it is recommended to always use @RefMacro{BOOST_SCOPE_EXIT_TPL} Chris@16: within templates). Chris@16: Chris@16: On C++11, it is possible capture all variables in scope without listing their Chris@16: names one-by-one using the macro @RefMacro{BOOST_SCOPE_EXIT_ALL}. Chris@16: Chris@16: In general, the special macro @RefMacro{BOOST_SCOPE_EXIT_ID} must be used Chris@16: instead of @RefMacro{BOOST_SCOPE_EXIT} when it is necessary to expand multiple Chris@16: scope exit declarations on the same line. Chris@16: Chris@16: @Warning The implementation executes the scope exit body within a destructor Chris@16: thus the scope exit body must never throw in order to comply with STL exception Chris@16: safety requirements. Chris@16: Chris@16: @Note The implementation uses Boost.Typeof to automatically deduce the types of Chris@16: the captured variables. Chris@16: In order to compile code in type-of emulation mode, all types must be properly Chris@16: registered with Boost.Typeof (see the Chris@16: @RefSect{getting_started, Getting Started} section). Chris@16: Chris@16: @See @RefSect{tutorial, Tutorial} section, Chris@16: @RefSect{getting_started, Getting Started} section, Chris@16: @RefSect{no_variadic_macros, No Variadic Macros} section, Chris@16: @RefMacro{BOOST_SCOPE_EXIT_TPL}, @RefMacro{BOOST_SCOPE_EXIT_ALL}, Chris@16: @RefMacro{BOOST_SCOPE_EXIT_END}, @RefMacro{BOOST_SCOPE_EXIT_ID}. Chris@16: */ Chris@16: #define BOOST_SCOPE_EXIT(capture_list) Chris@16: Chris@16: /** Chris@16: @brief This macro is a workaround for various versions of GCC to declare scope Chris@16: exits within templates. Chris@16: Chris@16: Various versions of the GCC compiler do not compile @RefMacro{BOOST_SCOPE_EXIT} Chris@16: inside function templates. Chris@16: As a workaround, @RefMacro{BOOST_SCOPE_EXIT_TPL} should be used instead of Chris@16: @RefMacro{BOOST_SCOPE_EXIT} in these cases: Chris@16: Chris@16: @code Chris@16: { // Some local scope. Chris@16: ... Chris@16: BOOST_SCOPE_EXIT_TPL(capture_list) { Chris@16: ... // Body code. Chris@16: } BOOST_SCOPE_EXIT_END Chris@16: ... Chris@16: } Chris@16: @endcode Chris@16: Chris@16: The syntax of @RefMacro{BOOST_SCOPE_EXIT_TPL} is the exact same as the one of Chris@16: @RefMacro{BOOST_SCOPE_EXIT} (see @RefMacro{BOOST_SCOPE_EXIT} for more Chris@16: information). Chris@16: Chris@16: On C++11 compilers, @RefMacro{BOOST_SCOPE_EXIT_TPL} is not needed because Chris@16: @RefMacro{BOOST_SCOPE_EXIT} always compiles on GCC versions that support C++11. Chris@16: However, @RefMacro{BOOST_SCOPE_EXIT_TPL} is still provided on C++11 so to write code that is portable between C++03 and C++11 compilers. Chris@16: It is recommended to always use @RefMacro{BOOST_SCOPE_EXIT_TPL} within Chris@16: templates so to maximize portability. Chris@16: Chris@16: In general, the special macro @RefMacro{BOOST_SCOPE_EXIT_ID_TPL} must be used Chris@16: instead of @RefMacro{BOOST_SCOPE_EXIT_TPL} when it is necessary to expand Chris@16: multiple scope exit declarations on the same line within templates. Chris@16: Chris@16: @Note The issue in compiling scope exit declarations that some GCC versions Chris@16: have is illustrated by the following code (see also Chris@16: GCC bug 37920): Chris@16: @code Chris@16: template Chris@16: void f(T const& x) { Chris@16: int i = 0; Chris@16: struct local { Chris@16: typedef __typeof__(i) typeof_i; Chris@16: typedef __typeof__(x) typeof_x; Chris@16: }; Chris@16: typedef local::typeof_i i_type; Chris@16: typedef local::typeof_x x_type; Chris@16: } Chris@16: Chris@16: int main(void) { f(0); } Chris@16: @endcode Chris@16: This can be fixed by adding typename in front of local::typeof_i Chris@16: and local::typeof_x (which is the approach followed by the Chris@16: implementation of the @RefMacro{BOOST_SCOPE_EXIT_TPL} macro). Chris@16: Chris@16: @Note Although @RefMacro{BOOST_SCOPE_EXIT_TPL} has the same suffix as Chris@16: BOOST_TYPEOF_TPL, it does not follow the Boost.Typeof convention. Chris@16: Chris@16: @See @RefSect{tutorial, Tutorial} section, @RefMacro{BOOST_SCOPE_EXIT}, Chris@16: @RefMacro{BOOST_SCOPE_EXIT_END}, @RefMacro{BOOST_SCOPE_EXIT_ID_TPL}. Chris@16: */ Chris@16: #define BOOST_SCOPE_EXIT_TPL(capture_list) Chris@16: Chris@16: /** Chris@16: @brief This macro allows to expand multiple scope exit declarations on the same Chris@16: line. Chris@16: Chris@16: This macro is equivalent to @RefMacro{BOOST_SCOPE_EXIT} but it can be expanded Chris@16: multiple times on the same line if different identifiers id are provided Chris@16: for each expansion (see @RefMacro{BOOST_SCOPE_EXIT} for more information). Chris@16: Chris@16: @Params Chris@16: @Param{id, Chris@16: A unique identifier token which can be concatenated by the preprocessor Chris@16: (__LINE__\, scope_exit_number_1_on_line_123\, a combination of Chris@16: alphanumeric tokens\, etc). Chris@16: } Chris@16: @Param{capture_list, Chris@16: Same as the capture_list parameter of the @RefMacro{BOOST_SCOPE_EXIT} Chris@16: macro. Chris@16: } Chris@16: @EndParams Chris@16: Chris@16: @Note This macro can be useful when the scope exit macros are expanded Chris@16: within user-defined macros (because nested macros expand on the same line). Chris@16: On some compilers (e.g., MSVC which supports the non standard Chris@16: __COUNTER__ macro) it might not be necessary to use this macro but Chris@16: the use of this macro is always necessary to ensure portability when expanding Chris@16: multiple scope exit declarations on the same line. Chris@16: Chris@16: @See @RefSect{tutorial, Tutorial} section, @RefMacro{BOOST_SCOPE_EXIT}, Chris@16: @RefMacro{BOOST_SCOPE_EXIT_END_ID}, @RefMacro{BOOST_SCOPE_EXIT_ALL_ID}, Chris@16: @RefMacro{BOOST_SCOPE_EXIT_ID_TPL}. Chris@16: */ Chris@16: #define BOOST_SCOPE_EXIT_ID(id, capture_list) Chris@16: Chris@16: /** Chris@16: @brief This macro is required to expand multiple scope exit declarations on the Chris@16: same line within templates on various versions of GCC. Chris@16: Chris@16: This macro is equivalent to @RefMacro{BOOST_SCOPE_EXIT_TPL} but it can be Chris@16: expanded multiple times on the same line if different identifiers id are Chris@16: provided for each expansion (see @RefMacro{BOOST_SCOPE_EXIT_TPL} for more Chris@16: information). Chris@16: As with @RefMacro{BOOST_SCOPE_EXIT_TPL}, it is recommended to always use this Chris@16: macro when expanding scope exits multiple times on the same line within Chris@16: templates. Chris@16: Chris@16: @Params Chris@16: @Param{id, Chris@16: A unique identifier token which can be concatenated by the preprocessor Chris@16: (__LINE__\, scope_exit_number_1_on_line_123\, a combination of Chris@16: alphanumeric tokens\, etc). Chris@16: } Chris@16: @Param{capture_list, Chris@16: Same as the capture_list parameter of the Chris@16: @RefMacro{BOOST_SCOPE_EXIT_TPL} macro. Chris@16: } Chris@16: @EndParams Chris@16: Chris@16: @Note This macro can be useful when the scope exit macros are expanded Chris@16: within user-defined macros (because nested macros expand on the same line). Chris@16: On some compilers (e.g., MSVC which supports the non standard Chris@16: __COUNTER__ macro) it might not be necessary to use this macro but Chris@16: the use of this macro is always necessary to ensure portability when expanding Chris@16: multiple scope exit declarations on the same line. Chris@16: Chris@16: @See @RefSect{tutorial, Tutorial} section, @RefMacro{BOOST_SCOPE_EXIT_TPL}, Chris@16: @RefMacro{BOOST_SCOPE_EXIT_END_ID}, @RefMacro{BOOST_SCOPE_EXIT_ID}, Chris@16: @RefMacro{BOOST_SCOPE_EXIT_ALL_ID}. Chris@16: */ Chris@16: #define BOOST_SCOPE_EXIT_ID_TPL(id, capture_list) Chris@16: Chris@16: /** Chris@16: @brief This macro declares a scope exit that captures all variables in scope Chris@16: (C++11 only). Chris@16: Chris@16: This macro accepts a capture list starting with either & or = to capture all variables in scope by reference or value respectively (following the same syntax of C++11 lambdas). Chris@16: A part from that, this macro works like @RefMacro{BOOST_SCOPE_EXIT} (see @RefMacro{BOOST_SCOPE_EXIT} for more information): Chris@16: Chris@16: @code Chris@16: { // Some local scope. Chris@16: ... Chris@16: BOOST_SCOPE_EXIT_ALL(capture_list) { // C++11 only. Chris@16: ... // Body code. Chris@16: }; // Use `;` instead of `BOOST_SCOPE_EXIT_END` (C++11 only). Chris@16: ... Chris@16: } Chris@16: @endcode Chris@16: Chris@16: Note how the end of the scope exit body declared by this macro must be marked Chris@16: by a semi-column ; (and not by @RefMacro{BOOST_SCOPE_EXIT_END}). Chris@16: Chris@16: @Warning This macro is only available on C++11 compilers (specifically, on Chris@16: C++11 compilers that do not define the Boost.Config BOOST_NO_CXX11_LAMBDAS Chris@16: macro). Chris@16: It is not defined on non-C++11 compilers so its use on non-C++11 compilers will generate a compiler error. Chris@16: Chris@16: @Params Chris@16: @Param{capture_list, Chris@16: On compilers that support variadic macros (see also Boost.Config Chris@16: BOOST_NO_CXX11_VARIADIC_MACROS)\, the capture list syntax is defined by the Chris@16: following grammar: Chris@16: @code Chris@16: capture_list: Chris@16: capture_tuple | capture_sequence Chris@16: capture_tuple: Chris@16: {& | =} [\, capture\, capture\, ...] Chris@16: capture_sequence: Chris@16: {(&) | (=)} [(capture) (capture) ...] Chris@16: capture: Chris@16: [&]variable | this_ Chris@16: @endcode Chris@16: On compilers that do not support variadic macros\, capture_tuple cannot Chris@16: be used: Chris@16: @code Chris@16: capture_list: Chris@16: void | capture_sequence Chris@16: @endcode Chris@16: Furthermore\, on C++11 compilers that support the use of typename Chris@16: outside templates\, also this can be used to capture the object at member Chris@16: function scope: Chris@16: @code Chris@16: capture: Chris@16: [&]variable | this_ | this Chris@16: @endcode Chris@16: Chris@16: (Lexical conventions: token1 | token2 means either token1 or Chris@16: token2; [token] means either token or nothing; Chris@16: {expression} means the token resulting from the expression.) Chris@16: } Chris@16: @EndParams Chris@16: Chris@16: Note that on compilers with variadic macro support (which should be all C++11 Chris@16: compilers), the capture list can be specified as a comma-separated list. Chris@16: On all compilers, the same macro @RefMacro{BOOST_SCOPE_EXIT_ALL} also allows to Chris@16: specify the capture list as a Boost.Preprocessor sequence. Chris@16: Chris@16: The capture list must always contain at least the leading & or = Chris@16: so it can never be void (BOOST_SCOPE_EXIT(void) should be used Chris@16: to program scope exits with an empty capture list). Chris@16: Chris@16: In general, the special macro @RefMacro{BOOST_SCOPE_EXIT_ALL_ID} must be used Chris@16: instead of @RefMacro{BOOST_SCOPE_EXIT_ALL} when it is necessary to expand Chris@16: multiple scope exit declarations on the same line. Chris@16: Chris@16: @Warning This macro capture list follows the exact same syntax of C++11 lambda Chris@16: captures which is unfortunately different from the syntax of Chris@16: @RefMacro{BOOST_SCOPE_EXIT} captures (unless programmers define the Chris@16: @RefMacro{BOOST_SCOPE_EXIT_CONFIG_USE_LAMBDAS} macro). Chris@16: For example, like C++11 lambda functions, @RefMacro{BOOST_SCOPE_EXIT_ALL} Chris@16: requires to capture data members by capturing the object this while Chris@16: @RefMacro{BOOST_SCOPE_EXIT} allows to capture data members directly and without Chris@16: capturing the object. Chris@16: Chris@16: @Warning The implementation executes the scope exit body within a destructor Chris@16: thus the scope exit body must never throw in order to comply with STL exception Chris@16: safety requirements. Chris@16: Chris@16: @Note This macro can always be used also within templates (so there is no need Chris@16: for a BOOST_SCOPE_EXIT_ALL_TPL macro). Chris@16: Chris@16: @See @RefSect{tutorial, Tutorial} section, Chris@16: @RefSect{no_variadic_macros, No Variadic Macros} section, Chris@16: @RefMacro{BOOST_SCOPE_EXIT}, @RefMacro{BOOST_SCOPE_EXIT_ALL_ID}. Chris@16: */ Chris@16: #define BOOST_SCOPE_EXIT_ALL(capture_list) Chris@16: Chris@16: /** Chris@16: @brief This macro allows to expand on the same line multiple scope exits that Chris@16: capture all variables in scope (C++11 only). Chris@16: Chris@16: This macro is equivalent to @RefMacro{BOOST_SCOPE_EXIT_ALL} but it can be Chris@16: expanded multiple times on the same line if different identifiers id are Chris@16: provided for each expansion (see @RefMacro{BOOST_SCOPE_EXIT_ALL} for more Chris@16: information). Chris@16: As with @RefMacro{BOOST_SCOPE_EXIT_ALL}, this macro is only available on C++11 Chris@16: compilers (specifically, on C++11 compilers that do not define the Chris@16: Boost.Config BOOST_NO_CXX11_LAMBDAS macro). Chris@16: Chris@16: @Params Chris@16: @Param{id, Chris@16: A unique identifier token which can be concatenated by the preprocessor Chris@16: (__LINE__\, scope_exit_number_1_on_line_123\, a combination of Chris@16: alphanumeric tokens\, etc). Chris@16: } Chris@16: @Param{capture_list, Chris@16: Same as the capture_list parameter of the Chris@16: @RefMacro{BOOST_SCOPE_EXIT_ALL} macro. Chris@16: } Chris@16: @EndParams Chris@16: Chris@16: @Note This macro can be useful when the scope exit macros are expanded Chris@16: within user-defined macros (because nested macros expand on the same line). Chris@16: On some compilers (e.g., MSVC which supports the non standard Chris@16: __COUNTER__ macro) it might not be necessary to use this macro but Chris@16: the use of this macro is always necessary to ensure portability when expanding Chris@16: multiple scope exit declarations on the same line. Chris@16: Chris@16: @See @RefSect{tutorial, Tutorial} section, @RefMacro{BOOST_SCOPE_EXIT_ALL}, Chris@16: @RefMacro{BOOST_SCOPE_EXIT_ID}. Chris@16: */ Chris@16: #define BOOST_SCOPE_EXIT_ALL_ID(id, capture_list) Chris@16: Chris@16: /** Chris@16: @brief This macro marks the end of a scope exit body. Chris@16: Chris@16: This macro must follow the closing curly bracket } that ends the body of Chris@16: either @RefMacro{BOOST_SCOPE_EXIT} or @RefMacro{BOOST_SCOPE_EXIT_TPL}: Chris@16: Chris@16: @code Chris@16: { // Some local scope. Chris@16: ... Chris@16: BOOST_SCOPE_EXIT(capture_list) { Chris@16: ... // Body code. Chris@16: } BOOST_SCOPE_EXIT_END Chris@16: ... Chris@16: } Chris@16: @endcode Chris@16: Chris@16: In general, the special macro @RefMacro{BOOST_SCOPE_EXIT_END_ID} must be used Chris@16: instead of @RefMacro{BOOST_SCOPE_EXIT_END} when it is necessary to expand Chris@16: multiple scope exit bodies on the same line. Chris@16: Chris@16: @Note If programmers define the @RefMacro{BOOST_SCOPE_EXIT_CONFIG_USE_LAMBDAS} Chris@16: macro on C++11 compilers, a semicolon ; can be used instead of this Chris@16: macro. Chris@16: However, to maximize portability, it is recommended to always use Chris@16: @RefMacro{BOOST_SCOPE_EXIT_END}. Chris@16: Chris@16: @See @RefSect{tutorial, Tutorial} section, @RefMacro{BOOST_SCOPE_EXIT}, Chris@16: @RefMacro{BOOST_SCOPE_EXIT_TPL}, @RefMacro{BOOST_SCOPE_EXIT_END_ID}. Chris@16: */ Chris@16: #define BOOST_SCOPE_EXIT_END Chris@16: Chris@16: /** Chris@16: @brief This macro allows to terminate multiple scope exit bodies on the same Chris@16: line. Chris@16: Chris@16: This macro is equivalent to @RefMacro{BOOST_SCOPE_EXIT_END} but it can be Chris@16: expanded multiple times on the same line if different identifiers id are Chris@16: provided for each expansion (see @RefMacro{BOOST_SCOPE_EXIT_END} for more Chris@16: information). Chris@16: Chris@16: @Params Chris@16: @Param{id, Chris@16: A unique identifier token which can be concatenated by the preprocessor Chris@16: (__LINE__\, scope_exit_number_1_on_line_123\, a combination of Chris@16: alphanumeric tokens\, etc). Chris@16: } Chris@16: @EndParams Chris@16: Chris@16: @Note This macro can be useful when the scope exit macros are expanded Chris@16: within user-defined macros (because macros all expand on the same line). Chris@16: On some compilers (e.g., MSVC which supports the non standard Chris@16: __COUNTER__ macro) it might not be necessary to use this macro but Chris@16: the use of this macro is always necessary to ensure portability when expanding Chris@16: multiple scope exit macros on the same line (because this library can only Chris@16: portably use __LINE__ to internally generate unique identifiers). Chris@16: Chris@16: @See @RefMacro{BOOST_SCOPE_EXIT_ID}, @RefMacro{BOOST_SCOPE_EXIT_ID_TPL}, Chris@16: @RefMacro{BOOST_SCOPE_EXIT_END}. Chris@16: */ Chris@16: #define BOOST_SCOPE_EXIT_END_ID(id) Chris@16: Chris@16: /** Chris@16: @brief Force to use C++11 lambda functions to implement scope exits. Chris@16: Chris@16: If programmers define this configuration macro on a C++11 compiler for which Chris@16: the Boost.Config macro BOOST_NO_CXX11_LAMBDAS is not defined, the Chris@16: @RefMacro{BOOST_SCOPE_EXIT} and @RefMacro{BOOST_SCOPE_EXIT_TPL} macros will use Chris@16: C++11 lambda functions to declare scope exits. Chris@16: By default this macro is not defined. Chris@16: Chris@16: @Warning When scope exits are implemented using lambda functions, the syntax of Chris@16: the capture list follows the exact same syntax of C++11 lambda captures Chris@16: which is in general different from the legacy capture syntax of this library. Chris@16: For example, C++11 lambdas require to capture data members by capturing the Chris@16: object this while this library always allowed to capture data members Chris@16: directly. Chris@16: Therefore, when this configuration macro is defined, Chris@16: @RefMacro{BOOST_SCOPE_EXIT} and @RefMacro{BOOST_SCOPE_EXIT_TPL} are no longer Chris@16: backward compatible (and this is why this macro is not defined by default). Chris@16: Chris@16: A semicolon ; can be used instead of @RefMacro{BOOST_SCOPE_EXIT_END} Chris@16: when this configuration macro is defined (but it is recommended to always use Chris@16: @RefMacro{BOOST_SCOPE_EXIT_END} so to maximize portability). Chris@16: Chris@16: @Note This configuration macro does not control the definition of Chris@16: @RefMacro{BOOST_SCOPE_EXIT_ALL} which is always and automatically defined on Chris@16: compilers that support C++11 lambda functions. Chris@16: Chris@16: @See @RefMacro{BOOST_SCOPE_EXIT}, @RefMacro{BOOST_SCOPE_EXIT_TPL}, Chris@16: @RefMacro{BOOST_SCOPE_EXIT_END}. Chris@16: */ Chris@16: #define BOOST_SCOPE_EXIT_CONFIG_USE_LAMBDAS Chris@16: Chris@16: #endif // DOXYGEN Chris@16: Chris@16: #endif // #ifndef FILE_boost_scope_exit_hpp_INCLUDED Chris@16: