annotate DEPENDENCIES/generic/include/boost/scope_exit.hpp @ 133:4acb5d8d80b6 tip

Don't fail environmental check if README.md exists (but .txt and no-suffix don't)
author Chris Cannam
date Tue, 30 Jul 2019 12:25:44 +0100
parents c530137014c0
children
rev   line source
Chris@16 1
Chris@16 2 // Copyright (C) 2006-2009, 2012 Alexander Nasonov
Chris@16 3 // Copyright (C) 2012 Lorenzo Caminiti
Chris@16 4 // Distributed under the Boost Software License, Version 1.0
Chris@16 5 // (see accompanying file LICENSE_1_0.txt or a copy at
Chris@16 6 // http://www.boost.org/LICENSE_1_0.txt)
Chris@16 7 // Home at http://www.boost.org/libs/scope_exit
Chris@16 8
Chris@16 9 #ifndef FILE_boost_scope_exit_hpp_INCLUDED
Chris@16 10 #define FILE_boost_scope_exit_hpp_INCLUDED
Chris@16 11
Chris@16 12 #ifndef DOXYGEN
Chris@16 13
Chris@16 14 #include <boost/detail/workaround.hpp>
Chris@16 15 #include <boost/mpl/assert.hpp>
Chris@16 16 #include <boost/mpl/int.hpp>
Chris@16 17 #include <boost/utility/enable_if.hpp>
Chris@16 18 #include <boost/function.hpp>
Chris@16 19 #include <boost/typeof/typeof.hpp>
Chris@16 20 #include <boost/config.hpp>
Chris@16 21 #include <boost/preprocessor/cat.hpp>
Chris@16 22 #include <boost/preprocessor/control/iif.hpp>
Chris@16 23 #include <boost/preprocessor/control/expr_iif.hpp>
Chris@101 24 #include <boost/preprocessor/comparison/equal.hpp>
Chris@16 25 #include <boost/preprocessor/logical/bitor.hpp>
Chris@16 26 #include <boost/preprocessor/logical/bitand.hpp>
Chris@16 27 #include <boost/preprocessor/facilities/empty.hpp>
Chris@16 28 #include <boost/preprocessor/facilities/is_empty.hpp>
Chris@16 29 #include <boost/preprocessor/facilities/identity.hpp>
Chris@16 30 #include <boost/preprocessor/punctuation/comma_if.hpp>
Chris@16 31 #include <boost/preprocessor/punctuation/paren_if.hpp>
Chris@16 32 #include <boost/preprocessor/seq/cat.hpp>
Chris@101 33 #include <boost/preprocessor/seq/size.hpp>
Chris@101 34 #include <boost/preprocessor/seq/to_tuple.hpp>
Chris@16 35 #include <boost/preprocessor/tuple/elem.hpp>
Chris@16 36 #include <boost/preprocessor/tuple/eat.hpp>
Chris@101 37 #include <boost/preprocessor/tuple/to_list.hpp>
Chris@16 38 #include <boost/preprocessor/list/append.hpp>
Chris@16 39 #include <boost/preprocessor/list/fold_left.hpp>
Chris@16 40 #include <boost/preprocessor/list/enum.hpp>
Chris@16 41 #include <boost/preprocessor/list/adt.hpp>
Chris@16 42 #include <boost/preprocessor/list/for_each_i.hpp>
Chris@101 43 #include <boost/preprocessor/detail/is_unary.hpp>
Chris@16 44
Chris@16 45 // PRIVATE/PROTECTED //
Chris@16 46
Chris@16 47 // NOTE: AUX prefix and aux namespace mark "private" symbols that shall be used
Chris@16 48 // only within this library; DETAIL prefix and detail namespace mark "protected"
Chris@16 49 // symbols that can be used by other Boost libraries but not outside Boost.
Chris@16 50
Chris@16 51 // WARNING: BOOST_SCOPE_EXIT_AUX_GCC also used by some regression test.
Chris@16 52 #if defined(__GNUC__) && !defined(BOOST_INTEL)
Chris@16 53 # define BOOST_SCOPE_EXIT_AUX_GCC (__GNUC__ * 100 + __GNUC_MINOR__)
Chris@16 54 #else
Chris@16 55 # define BOOST_SCOPE_EXIT_AUX_GCC 0
Chris@16 56 #endif
Chris@16 57
Chris@16 58 #if BOOST_WORKAROUND(BOOST_SCOPE_EXIT_AUX_GCC, BOOST_TESTED_AT(413))
Chris@16 59 # define BOOST_SCOPE_EXIT_AUX_TPL_GCC_WORKAROUND_01 1
Chris@16 60 #else
Chris@16 61 # define BOOST_SCOPE_EXIT_AUX_TPL_GCC_WORKAROUND_01 0
Chris@16 62 #endif
Chris@16 63
Chris@16 64 #if BOOST_MSVC
Chris@16 65 # define BOOST_SCOPE_EXIT_AUX_TYPEOF_THIS_MSVC_WORKAROUND_01 1
Chris@16 66 #else
Chris@16 67 # define BOOST_SCOPE_EXIT_AUX_TYPEOF_THIS_MSVC_WORKAROUND_01 0
Chris@16 68 #endif
Chris@16 69
Chris@101 70 // MSVC has problems expanding __LINE__ so use (the non standard) __COUNTER__.
Chris@101 71 #ifdef BOOST_MSVC
Chris@101 72 # define BOOST_SCOPE_EXIT_AUX_PP_LINE_COUNTER __COUNTER__
Chris@101 73 #else
Chris@101 74 # define BOOST_SCOPE_EXIT_AUX_PP_LINE_COUNTER __LINE__
Chris@101 75 #endif
Chris@101 76
Chris@101 77 // Preprocessor "keyword" detection.
Chris@101 78
Chris@101 79 // These are not a local macros, do not #undefine them (these are used by the
Chris@101 80 // ..._BACK macros below).
Chris@101 81 #define this_BOOST_SCOPE_EXIT_AUX_PP_KEYWORD_THISUNDERSCORE_IS (1) /* unary */
Chris@101 82 #define void_BOOST_SCOPE_EXIT_AUX_PP_KEYWORD_VOID_IS (1) /* unary */
Chris@101 83
Chris@101 84 #define BOOST_SCOPE_EXIT_AUX_PP_KEYWORD_IS_BACK_(token, checking_postfix) \
Chris@101 85 BOOST_PP_IS_UNARY(BOOST_PP_CAT(token, checking_postfix))
Chris@101 86
Chris@101 87 #define BOOST_SCOPE_EXIT_AUX_PP_KEYWORD_IS_THISUNDERSCORE_BACK(token) \
Chris@101 88 BOOST_SCOPE_EXIT_AUX_PP_KEYWORD_IS_BACK_(token, \
Chris@101 89 BOOST_SCOPE_EXIT_AUX_PP_KEYWORD_THISUNDERSCORE_IS)
Chris@101 90
Chris@101 91 #define BOOST_SCOPE_EXIT_AUX_PP_KEYWORD_IS_VOID_BACK(token) \
Chris@101 92 BOOST_SCOPE_EXIT_AUX_PP_KEYWORD_IS_BACK_(token, \
Chris@101 93 _BOOST_SCOPE_EXIT_AUX_PP_KEYWORD_VOID_IS)
Chris@101 94
Chris@101 95 // Preprocessor "void-list".
Chris@101 96
Chris@101 97 // NOTE: Empty list must always be represented as void (which is also a way to
Chris@101 98 // specify no function parameter) and it can never be empty because (1)
Chris@101 99 // IS_EMPTY(&var) fails (because of the leading non alphanumeric symbol) and
Chris@101 100 // (2) some compilers (MSVC) fail to correctly pass empty macro parameters
Chris@101 101 // even if they support variadic macros. Therefore, always using void to
Chris@101 102 // represent is more portable.
Chris@101 103
Chris@101 104 // Argument: (token1)...
Chris@101 105 #define BOOST_SCOPE_EXIT_AUX_PP_VOID_LIST_FROM_SEQ_(unused, seq) \
Chris@101 106 BOOST_PP_TUPLE_TO_LIST(BOOST_PP_SEQ_SIZE(seq), BOOST_PP_SEQ_TO_TUPLE(seq))
Chris@101 107
Chris@101 108 // Token: void | token1
Chris@101 109 #define BOOST_SCOPE_EXIT_AUX_PP_VOID_LIST_HANDLE_VOID_( \
Chris@101 110 is_void_macro, token) \
Chris@101 111 BOOST_PP_IIF(is_void_macro(token), \
Chris@101 112 BOOST_PP_NIL \
Chris@101 113 , \
Chris@101 114 (token, BOOST_PP_NIL) \
Chris@101 115 )
Chris@101 116
Chris@101 117 // Token: (a)(b)... | empty | void | token
Chris@101 118 #define BOOST_SCOPE_EXIT_AUX_PP_VOID_LIST_HANDLE_SEQ_( \
Chris@101 119 is_void_macro, token) \
Chris@101 120 BOOST_PP_IIF(BOOST_PP_IS_UNARY(token), /* unary paren (a)... */ \
Chris@101 121 BOOST_SCOPE_EXIT_AUX_PP_VOID_LIST_FROM_SEQ_ \
Chris@101 122 , \
Chris@101 123 BOOST_SCOPE_EXIT_AUX_PP_VOID_LIST_HANDLE_VOID_ \
Chris@101 124 )(is_void_macro, token)
Chris@101 125
Chris@101 126 #define BOOST_SCOPE_EXIT_AUX_PP_VOID_LIST_NEVER_(tokens) \
Chris@101 127 0 /* void check always returns false */
Chris@101 128
Chris@101 129 #ifdef BOOST_NO_CXX11_VARIADIC_MACROS
Chris@101 130
Chris@101 131 #define BOOST_SCOPE_EXIT_AUX_PP_VOID_LIST_(is_void_macro, seq) \
Chris@101 132 BOOST_SCOPE_EXIT_AUX_PP_VOID_LIST_HANDLE_SEQ_(is_void_macro, seq)
Chris@101 133
Chris@101 134 // Expand `void | (a)(b)...` to pp-list `NIL | (a, (b, NIL))`.
Chris@101 135 #define BOOST_SCOPE_EXIT_AUX_PP_VOID_LIST(sign) \
Chris@101 136 BOOST_SCOPE_EXIT_AUX_PP_VOID_LIST_( \
Chris@101 137 BOOST_SCOPE_EXIT_AUX_PP_KEYWORD_IS_VOID_BACK, sign)
Chris@101 138
Chris@101 139 // Expand `(a)(b)...` to pp-list `(a, (b, NIL))`.
Chris@101 140 #define BOOST_SCOPE_EXIT_AUX_PP_NON_VOID_LIST(seq) \
Chris@101 141 BOOST_SCOPE_EXIT_AUX_PP_VOID_LIST_( \
Chris@101 142 BOOST_SCOPE_EXIT_AUX_PP_VOID_LIST_NEVER_, seq)
Chris@101 143
Chris@101 144 #else // VARIADICS
Chris@101 145
Chris@101 146 // FUTURE: Replace this with BOOST_PP_VARIADIC_SIZE when and if
Chris@101 147 // BOOST_PP_VARIAIDCS detection will match !BOOST_NO_CXX11_VARIADIC_MACROS (for
Chris@101 148 // now Boost.Preprocessor and Boost.Config disagree on detecting compiler
Chris@101 149 // variadic support while this VARIADIC_SIZE works on compilers not detected by
Chris@101 150 // PP).
Chris@101 151 #if BOOST_MSVC
Chris@101 152 # define BOOST_SCOPE_EXIT_AUX_PP_VOID_LIST_VARIADIC_SIZE_(...) \
Chris@101 153 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 154 #else // MSVC
Chris@101 155 # define BOOST_SCOPE_EXIT_AUX_PP_VOID_LIST_VARIADIC_SIZE_(...) \
Chris@101 156 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 157 #endif // MSVC
Chris@101 158 #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 159
Chris@101 160 // Argument: token1, ...
Chris@101 161 #define BOOST_SCOPE_EXIT_AUX_PP_VOID_LIST_FROM_VARIADIC_(unused, ...) \
Chris@101 162 BOOST_PP_TUPLE_TO_LIST( \
Chris@101 163 BOOST_SCOPE_EXIT_AUX_PP_VOID_LIST_VARIADIC_SIZE_( \
Chris@101 164 __VA_ARGS__), (__VA_ARGS__))
Chris@101 165
Chris@101 166 #define BOOST_SCOPE_EXIT_AUX_PP_VOID_LIST_(is_void_macro, ...) \
Chris@101 167 BOOST_PP_IIF(BOOST_PP_EQUAL( \
Chris@101 168 BOOST_SCOPE_EXIT_AUX_PP_VOID_LIST_VARIADIC_SIZE_( \
Chris@101 169 __VA_ARGS__), 1), \
Chris@101 170 BOOST_SCOPE_EXIT_AUX_PP_VOID_LIST_HANDLE_SEQ_ \
Chris@101 171 , \
Chris@101 172 BOOST_SCOPE_EXIT_AUX_PP_VOID_LIST_FROM_VARIADIC_ \
Chris@101 173 )(is_void_macro, __VA_ARGS__)
Chris@101 174
Chris@101 175 // Expand `void | (a)(b)... | a, b, ...` to pp-list `NIL | (a, (b, NIL))`.
Chris@101 176 #define BOOST_SCOPE_EXIT_AUX_PP_VOID_LIST(...) \
Chris@101 177 BOOST_SCOPE_EXIT_AUX_PP_VOID_LIST_( \
Chris@101 178 BOOST_SCOPE_EXIT_AUX_PP_KEYWORD_IS_VOID_BACK, __VA_ARGS__)
Chris@101 179
Chris@101 180 // Expand `(a)(b)... | a, b, ...` to pp-list `(a, (b, NIL))`.
Chris@101 181 #define BOOST_SCOPE_EXIT_AUX_PP_NON_VOID_LIST(...) \
Chris@101 182 BOOST_SCOPE_EXIT_AUX_PP_VOID_LIST_( \
Chris@101 183 BOOST_SCOPE_EXIT_AUX_PP_VOID_LIST_NEVER_, __VA_ARGS__)
Chris@101 184
Chris@101 185 #endif // VARIADICS
Chris@101 186
Chris@16 187 // Steven Watanabe's trick with a modification suggested by Kim Barrett
Chris@16 188 namespace boost { namespace scope_exit { namespace detail {
Chris@16 189
Chris@16 190 // Type of a local BOOST_SCOPE_EXIT_AUX_ARGS variable.
Chris@16 191 // First use in a local scope will declare the BOOST_SCOPE_EXIT_AUX_ARGS
Chris@16 192 // variable, subsequent uses will be resolved as two comparisons
Chris@16 193 // (cmp1 with 0 and cmp2 with BOOST_SCOPE_EXIT_AUX_ARGS).
Chris@16 194 template<int Dummy = 0>
Chris@16 195 struct declared
Chris@16 196 {
Chris@16 197 void* value;
Chris@16 198 static int const cmp2 = 0;
Chris@16 199 friend void operator>(int, declared const&) {}
Chris@16 200 };
Chris@16 201
Chris@16 202 struct undeclared { declared<> dummy[2]; };
Chris@16 203
Chris@16 204 template<int> struct resolve;
Chris@16 205
Chris@16 206 template<>
Chris@16 207 struct resolve<sizeof(declared<>)>
Chris@16 208 {
Chris@16 209 static const int cmp1 = 0;
Chris@16 210 };
Chris@16 211
Chris@16 212 template<>
Chris@16 213 struct resolve<sizeof(undeclared)>
Chris@16 214 {
Chris@16 215 template<int>
Chris@16 216 struct cmp1
Chris@16 217 {
Chris@16 218 static int const cmp2 = 0;
Chris@16 219 };
Chris@16 220 };
Chris@16 221
Chris@16 222 typedef void (*ref_tag)(int&);
Chris@16 223 typedef void (*val_tag)(int );
Chris@16 224
Chris@16 225 template<class T, class Tag> struct member;
Chris@16 226
Chris@16 227 template<class T>
Chris@16 228 struct member<T,ref_tag>
Chris@16 229 {
Chris@16 230 T& value;
Chris@16 231 #if !BOOST_SCOPE_EXIT_AUX_TPL_GCC_WORKAROUND_01
Chris@16 232 member(T& ref) : value(ref) {}
Chris@16 233 #endif
Chris@16 234 };
Chris@16 235
Chris@16 236 template<class T>
Chris@16 237 struct member<T,val_tag>
Chris@16 238 {
Chris@16 239 T value;
Chris@16 240 #if !BOOST_SCOPE_EXIT_AUX_TPL_GCC_WORKAROUND_01
Chris@16 241 member(T& val) : value(val) {}
Chris@16 242 #endif
Chris@16 243 };
Chris@16 244
Chris@16 245 template<class T> inline T& deref(T* p, ref_tag) { return *p; }
Chris@16 246 template<class T> inline T& deref(T& r, val_tag) { return r; }
Chris@16 247
Chris@16 248 template<class T>
Chris@16 249 struct wrapper
Chris@16 250 {
Chris@16 251 typedef T type;
Chris@16 252 };
Chris@16 253
Chris@16 254 template<class T> wrapper<T> wrap(T&);
Chris@16 255
Chris@16 256 } } } // namespace
Chris@16 257
Chris@16 258 #include BOOST_TYPEOF_INCREMENT_REGISTRATION_GROUP()
Chris@16 259 BOOST_TYPEOF_REGISTER_TEMPLATE(boost::scope_exit::detail::wrapper, 1)
Chris@16 260
Chris@16 261 #define BOOST_SCOPE_EXIT_AUX_ARGS boost_scope_exit_aux_args
Chris@16 262 extern boost::scope_exit::detail::undeclared BOOST_SCOPE_EXIT_AUX_ARGS;
Chris@16 263
Chris@16 264 #define BOOST_SCOPE_EXIT_AUX_GUARD(id) \
Chris@16 265 BOOST_PP_CAT(boost_se_guard_, id)
Chris@16 266
Chris@16 267 #define BOOST_SCOPE_EXIT_AUX_GUARD_T(id) \
Chris@16 268 BOOST_PP_CAT(boost_se_guard_t_, id)
Chris@16 269
Chris@16 270 #define BOOST_SCOPE_EXIT_AUX_PARAMS(id) \
Chris@16 271 BOOST_PP_CAT(boost_se_params_, id)
Chris@16 272
Chris@16 273 #define BOOST_SCOPE_EXIT_AUX_THIS_T(id) \
Chris@16 274 BOOST_PP_CAT(boost_se_this_t_, id)
Chris@16 275
Chris@16 276 #define BOOST_SCOPE_EXIT_AUX_THIS_CAPTURE_T(id) \
Chris@16 277 BOOST_PP_CAT(boost_se_this_capture_t_, id)
Chris@16 278
Chris@16 279 #define BOOST_SCOPE_EXIT_DETAIL_PARAMS_T(id) \
Chris@16 280 BOOST_PP_CAT(boost_se_params_t_, id)
Chris@16 281
Chris@16 282 #define BOOST_SCOPE_EXIT_DETAIL_TAG(id, i) \
Chris@16 283 BOOST_PP_SEQ_CAT( (boost_se_tag_)(i)(_)(id) )
Chris@16 284
Chris@16 285 #define BOOST_SCOPE_EXIT_DETAIL_PARAM_THIS(id) \
Chris@16 286 BOOST_PP_SEQ_CAT( (boost_se_param_this_)(id) )
Chris@16 287
Chris@16 288 #define BOOST_SCOPE_EXIT_DETAIL_PARAM(id, i, var) \
Chris@16 289 BOOST_PP_SEQ_CAT( (boost_se_param_)(i)(_)(id) )
Chris@16 290
Chris@16 291 #define BOOST_SCOPE_EXIT_DETAIL_PARAM_T(id, i, var) \
Chris@16 292 BOOST_PP_SEQ_CAT( (boost_se_param_t_)(i)(_)(id) )
Chris@16 293
Chris@16 294 #define BOOST_SCOPE_EXIT_DETAIL_CAPTURE_T(id, i, var) \
Chris@16 295 BOOST_PP_SEQ_CAT( (boost_se_capture_t_)(i)(_)(id) )
Chris@16 296
Chris@16 297 #define BOOST_SCOPE_EXIT_AUX_WRAPPED(id, i) \
Chris@16 298 BOOST_PP_SEQ_CAT( (boost_se_wrapped_t_)(i)(_)(id) )
Chris@16 299
Chris@16 300 #define BOOST_SCOPE_EXIT_AUX_DEREF(id, i, var) \
Chris@16 301 ::boost::scope_exit::detail::deref(var, \
Chris@16 302 static_cast<BOOST_SCOPE_EXIT_DETAIL_TAG(id, i)>(0))
Chris@16 303
Chris@16 304 #define BOOST_SCOPE_EXIT_AUX_MEMBER(r, id, i, var) \
Chris@16 305 ::boost::scope_exit::detail::member< \
Chris@16 306 BOOST_SCOPE_EXIT_DETAIL_PARAM_T(id, i, var), \
Chris@16 307 BOOST_SCOPE_EXIT_DETAIL_TAG(id, i) \
Chris@16 308 > BOOST_SCOPE_EXIT_DETAIL_PARAM(id, i, var);
Chris@16 309
Chris@16 310 #define BOOST_SCOPE_EXIT_AUX_ARG_DECL(r, id_ty, i, var) \
Chris@16 311 BOOST_PP_COMMA_IF(i) \
Chris@16 312 BOOST_PP_TUPLE_ELEM(2, 1, id_ty) \
Chris@16 313 BOOST_SCOPE_EXIT_DETAIL_PARAMS_T(BOOST_PP_TUPLE_ELEM(2, 0, id_ty)):: \
Chris@16 314 BOOST_SCOPE_EXIT_DETAIL_PARAM_T(BOOST_PP_TUPLE_ELEM(2, 0, id_ty), \
Chris@16 315 i, var) \
Chris@16 316 var
Chris@16 317
Chris@16 318 #define BOOST_SCOPE_EXIT_AUX_ARG(r, id, i, var) \
Chris@16 319 BOOST_PP_COMMA_IF(i) \
Chris@16 320 boost_se_params_->BOOST_SCOPE_EXIT_DETAIL_PARAM(id, i, var).value
Chris@16 321
Chris@16 322 #define BOOST_SCOPE_EXIT_DETAIL_TAG_DECL(r, id, i, var) \
Chris@16 323 typedef void (*BOOST_SCOPE_EXIT_DETAIL_TAG(id, i))(int var);
Chris@16 324
Chris@16 325 // Adam Butcher's workaround to deduce `this` type on MSVC revision < 10.
Chris@16 326 // Boost.Typeof for VC71's typeid-based workaround does not work to determine
Chris@16 327 // `this` type due to error C2355 being incorrectly reported. The typical
Chris@16 328 // avoidance strategy implemented below is to make an indirect compile-time
Chris@16 329 // constant by assigning an enum and use that as type-index-- this only works
Chris@16 330 // with the sizeof() approach and not with the typeid() approach. Lorenzo
Chris@16 331 // Caminiti extended this approach to work in type-of emulation mode. This code
Chris@16 332 // is very similar (and somewhat of a duplication) of the code in
Chris@16 333 // boost/typeof/msvc/typeof_impl.hpp). However, this code cannot be integrated
Chris@16 334 // into Boost.Typeof because its final API has to be a `typedef ...` and it
Chris@16 335 // cannot be a `typeof(...)`.
Chris@16 336 #if BOOST_SCOPE_EXIT_AUX_TYPEOF_THIS_MSVC_WORKAROUND_01
Chris@16 337
Chris@16 338 #include <boost/config.hpp>
Chris@16 339 #include <boost/detail/workaround.hpp>
Chris@16 340 #include <boost/mpl/int.hpp>
Chris@16 341 #include <boost/type_traits/is_function.hpp>
Chris@16 342 #include <boost/utility/enable_if.hpp>
Chris@16 343
Chris@101 344 #if defined(BOOST_MSVC)
Chris@16 345 # include <typeinfo>
Chris@16 346 #endif
Chris@16 347
Chris@16 348 namespace boost { namespace scope_exit { namespace aux {
Chris@16 349 namespace msvc_typeof_this {
Chris@16 350
Chris@16 351 // compile-time constant code
Chris@101 352 #if defined(BOOST_MSVC) && defined(_MSC_EXTENSIONS)
Chris@16 353
Chris@16 354 template<int N> struct the_counter;
Chris@16 355
Chris@16 356 template<typename T,int N = 5 /* for similarity */>
Chris@16 357 struct encode_counter {
Chris@16 358 __if_exists(the_counter<N + 256>) {
Chris@16 359 BOOST_STATIC_CONSTANT(unsigned,
Chris@16 360 count=(encode_counter<T,N + 257>::count));
Chris@16 361 }
Chris@16 362 __if_not_exists(the_counter<N + 256>) {
Chris@16 363 __if_exists(the_counter<N + 64>) {
Chris@16 364 BOOST_STATIC_CONSTANT(unsigned,
Chris@16 365 count=(encode_counter<T,N + 65>::count));
Chris@16 366 }
Chris@16 367 __if_not_exists(the_counter<N + 64>) {
Chris@16 368 __if_exists(the_counter<N + 16>) {
Chris@16 369 BOOST_STATIC_CONSTANT(unsigned,
Chris@16 370 count=(encode_counter<T,N + 17>::count));
Chris@16 371 }
Chris@16 372 __if_not_exists(the_counter<N + 16>) {
Chris@16 373 __if_exists(the_counter<N + 4>) {
Chris@16 374 BOOST_STATIC_CONSTANT(unsigned,
Chris@16 375 count=(encode_counter<T,N + 5>::count));
Chris@16 376 }
Chris@16 377 __if_not_exists(the_counter<N + 4>) {
Chris@16 378 __if_exists(the_counter<N>) {
Chris@16 379 BOOST_STATIC_CONSTANT(unsigned,
Chris@16 380 count=(encode_counter<T,N + 1>::count));
Chris@16 381 }
Chris@16 382 __if_not_exists(the_counter<N>) {
Chris@16 383 BOOST_STATIC_CONSTANT(unsigned,count=N);
Chris@16 384 typedef the_counter<N> type;
Chris@16 385 }
Chris@16 386 }
Chris@16 387 }
Chris@16 388 }
Chris@16 389 }
Chris@16 390 };
Chris@16 391
Chris@16 392 #else // compile-time constant code
Chris@16 393
Chris@16 394 template<int N> struct encode_counter : encode_counter<N - 1> {};
Chris@16 395
Chris@16 396 template<> struct encode_counter<0> {};
Chris@16 397
Chris@16 398 #endif // compile-time constant code
Chris@16 399
Chris@101 400 #if BOOST_WORKAROUND(BOOST_MSVC, >= 1400) // type-of code
Chris@16 401
Chris@16 402 struct msvc_extract_type_default_param {};
Chris@16 403
Chris@16 404 template<typename ID, typename T = msvc_extract_type_default_param>
Chris@16 405 struct msvc_extract_type;
Chris@16 406
Chris@16 407 template<typename ID>
Chris@16 408 struct msvc_extract_type<ID, msvc_extract_type_default_param> {
Chris@16 409 template<bool>
Chris@16 410 struct id2type_impl;
Chris@16 411
Chris@16 412 typedef id2type_impl<true> id2type;
Chris@16 413 };
Chris@16 414
Chris@16 415 template<typename ID, typename T>
Chris@16 416 struct msvc_extract_type
Chris@16 417 : msvc_extract_type<ID, msvc_extract_type_default_param> {
Chris@16 418 template<>
Chris@16 419 struct id2type_impl<true> { // VC8.0 specific bug-feature.
Chris@16 420 typedef T type;
Chris@16 421 };
Chris@16 422
Chris@16 423 template<bool>
Chris@16 424 struct id2type_impl;
Chris@16 425
Chris@16 426 typedef id2type_impl<true> id2type;
Chris@16 427 };
Chris@16 428
Chris@16 429 template<typename T, typename ID>
Chris@16 430 struct msvc_register_type : msvc_extract_type<ID, T> {};
Chris@16 431
Chris@16 432 #else // type-of code
Chris@16 433
Chris@16 434 template<typename ID>
Chris@16 435 struct msvc_extract_type {
Chris@16 436 struct id2type;
Chris@16 437 };
Chris@16 438
Chris@16 439 template<typename T, typename ID>
Chris@16 440 struct msvc_register_type : msvc_extract_type<ID> {
Chris@16 441 typedef msvc_extract_type<ID> base_type;
Chris@16 442 struct base_type::id2type { // This uses nice VC6.5 and VC7.1 bug-features.
Chris@16 443 typedef T type;
Chris@16 444 };
Chris@16 445 };
Chris@16 446
Chris@16 447 #endif // typeof code
Chris@16 448
Chris@16 449 template<int Id>
Chris@16 450 struct msvc_typeid_wrapper {
Chris@16 451 typedef typename msvc_extract_type<boost::mpl::int_<Id>
Chris@16 452 >::id2type id2type;
Chris@16 453 typedef typename id2type::type type;
Chris@16 454 };
Chris@16 455
Chris@16 456 template<>
Chris@16 457 struct msvc_typeid_wrapper<4> {
Chris@16 458 typedef msvc_typeid_wrapper<4> type;
Chris@16 459 };
Chris@16 460
Chris@16 461 template<typename T>
Chris@16 462 struct encode_type {
Chris@16 463 BOOST_STATIC_CONSTANT(unsigned, value = encode_counter<T>::count);
Chris@16 464 typedef typename msvc_register_type<T,
Chris@16 465 boost::mpl::int_<value> >::id2type type;
Chris@16 466 BOOST_STATIC_CONSTANT(unsigned, next = value + 1);
Chris@16 467 };
Chris@16 468
Chris@16 469 template<class T>
Chris@16 470 struct sizer {
Chris@16 471 typedef char(*type)[encode_type<T>::value];
Chris@16 472 };
Chris@16 473
Chris@16 474 template<typename T>
Chris@16 475 typename boost::disable_if<
Chris@16 476 typename boost::is_function<T>::type
Chris@16 477 , typename sizer<T>::type
Chris@16 478 >::type encode_start(T const&);
Chris@16 479
Chris@16 480 template<typename T>
Chris@16 481 typename boost::enable_if<
Chris@16 482 typename boost::is_function<T>::type
Chris@16 483 , typename sizer<T>::type
Chris@16 484 >::type encode_start(T&);
Chris@16 485
Chris@16 486 template<typename Organizer, typename T>
Chris@16 487 msvc_register_type<T, Organizer> typeof_register_type(const T&,
Chris@16 488 Organizer* = 0);
Chris@16 489
Chris@16 490 } } } } // namespace
Chris@16 491
Chris@16 492 #define BOOST_SCOPE_EXIT_AUX_TYPEDEF_TYPEOF_THIS_INDEX_(id) \
Chris@16 493 BOOST_PP_CAT(boost_se_thistype_index_, id)
Chris@16 494
Chris@16 495 #define BOOST_SCOPE_EXIT_DETAIL_TYPEDEF_TYPEOF_THIS(id, ty, new_type) \
Chris@16 496 /* unfortunately, we need to go via this enum which causes this to be */ \
Chris@16 497 /* a typedef construct and not a typeof (so this code cannot be */ \
Chris@16 498 /* integrated into Boost.Typeof) */ \
Chris@16 499 enum { \
Chris@16 500 BOOST_SCOPE_EXIT_AUX_TYPEDEF_TYPEOF_THIS_INDEX_(id) = sizeof( \
Chris@16 501 *::boost::scope_exit::aux::msvc_typeof_this::encode_start(this)) \
Chris@16 502 }; \
Chris@16 503 typedef \
Chris@16 504 ty ::boost::scope_exit::aux::msvc_typeof_this::msvc_typeid_wrapper< \
Chris@16 505 BOOST_SCOPE_EXIT_AUX_TYPEDEF_TYPEOF_THIS_INDEX_(id) \
Chris@16 506 >::type \
Chris@16 507 new_type \
Chris@16 508 ;
Chris@16 509
Chris@16 510 #else // TYPEOF_THIS_MSVC_WORKAROUND
Chris@16 511
Chris@16 512 #define BOOST_SCOPE_EXIT_DETAIL_TYPEDEF_TYPEOF_THIS(id, ty, new_type) \
Chris@16 513 typedef /* trailing `EMPTY()` handles empty `ty` */ \
Chris@16 514 BOOST_PP_IIF(BOOST_PP_IS_EMPTY(ty BOOST_PP_EMPTY()), \
Chris@16 515 BOOST_TYPEOF \
Chris@16 516 , \
Chris@16 517 BOOST_TYPEOF_TPL \
Chris@16 518 )(this) \
Chris@16 519 new_type \
Chris@16 520 ;
Chris@16 521
Chris@16 522 #endif // TYPEOF_THIS_MSVC_WORKAROUND
Chris@16 523
Chris@16 524 #if BOOST_SCOPE_EXIT_AUX_TPL_GCC_WORKAROUND_01
Chris@16 525
Chris@16 526 #define BOOST_SCOPE_EXIT_AUX_PARAMS_T_CTOR(id, ty, captures, has_this) \
Chris@16 527 /* expand to nothing */
Chris@16 528
Chris@16 529 #define BOOST_SCOPE_EXIT_DETAIL_PARAM_INIT(r, id, i, var) \
Chris@16 530 BOOST_PP_COMMA_IF(i) { BOOST_SCOPE_EXIT_AUX_DEREF(id, i, var) }
Chris@16 531
Chris@16 532 #define BOOST_SCOPE_EXIT_AUX_PARAMS_INIT(id, captures, has_this) \
Chris@16 533 BOOST_PP_EXPR_IIF(BOOST_PP_BITOR(has_this, \
Chris@16 534 BOOST_PP_LIST_IS_CONS(captures)), \
Chris@16 535 = { \
Chris@16 536 ) \
Chris@16 537 BOOST_PP_LIST_FOR_EACH_I(BOOST_SCOPE_EXIT_DETAIL_PARAM_INIT, id, captures) \
Chris@16 538 BOOST_PP_COMMA_IF(BOOST_PP_BITAND(BOOST_PP_LIST_IS_CONS(captures), \
Chris@16 539 has_this)) \
Chris@16 540 BOOST_PP_EXPR_IIF(has_this, this) /* no extra {...} needed here */ \
Chris@16 541 BOOST_PP_EXPR_IIF(BOOST_PP_BITOR(has_this, \
Chris@16 542 BOOST_PP_LIST_IS_CONS(captures)), \
Chris@16 543 } /* trailing `;` will be added by the caller */ \
Chris@16 544 )
Chris@16 545
Chris@16 546 #else // TPL_GCC_WORKAROUND
Chris@16 547
Chris@16 548 #define BOOST_SCOPE_EXIT_AUX_CTOR_ARG(r, id, i, var) \
Chris@16 549 BOOST_PP_COMMA_IF(i) \
Chris@16 550 BOOST_SCOPE_EXIT_DETAIL_PARAM_T(id, i, var) & BOOST_PP_CAT(a, i)
Chris@16 551
Chris@16 552 #define BOOST_SCOPE_EXIT_AUX_MEMBER_INIT(r, id, i, var) \
Chris@16 553 BOOST_PP_COMMA_IF(i) \
Chris@16 554 BOOST_SCOPE_EXIT_DETAIL_PARAM(id, i, var) ( BOOST_PP_CAT(a, i) )
Chris@16 555
Chris@16 556 #define BOOST_SCOPE_EXIT_AUX_CTOR_ARG_THIS_NAME(id) \
Chris@16 557 BOOST_PP_CAT(boost_se_this_arg_, id)
Chris@16 558
Chris@16 559 #define BOOST_SCOPE_EXIT_AUX_CTOR_ARG_THIS(id, ty, comma01) \
Chris@16 560 BOOST_PP_COMMA_IF(comma01) \
Chris@16 561 ty BOOST_SCOPE_EXIT_DETAIL_PARAMS_T(id)::BOOST_SCOPE_EXIT_AUX_THIS_T(id) \
Chris@16 562 BOOST_SCOPE_EXIT_AUX_CTOR_ARG_THIS_NAME(id) /* ptr so no & */
Chris@16 563
Chris@16 564 #define BOOST_SCOPE_EXIT_AUX_MEMBER_THIS_INIT(id, comma01) \
Chris@16 565 BOOST_PP_COMMA_IF(comma01) \
Chris@16 566 BOOST_SCOPE_EXIT_DETAIL_PARAM_THIS(id)( \
Chris@16 567 BOOST_SCOPE_EXIT_AUX_CTOR_ARG_THIS_NAME(id))
Chris@16 568
Chris@16 569 #define BOOST_SCOPE_EXIT_AUX_PARAMS_T_CTOR(id, ty, captures, has_this) \
Chris@16 570 BOOST_SCOPE_EXIT_DETAIL_PARAMS_T(id)( \
Chris@16 571 BOOST_PP_LIST_FOR_EACH_I(BOOST_SCOPE_EXIT_AUX_CTOR_ARG, id, captures) \
Chris@16 572 BOOST_PP_IIF(has_this, \
Chris@16 573 BOOST_SCOPE_EXIT_AUX_CTOR_ARG_THIS \
Chris@16 574 , \
Chris@16 575 BOOST_PP_TUPLE_EAT(3) \
Chris@16 576 )(id, ty, BOOST_PP_LIST_IS_CONS(captures)) \
Chris@16 577 ) \
Chris@16 578 BOOST_PP_EXPR_IIF(BOOST_PP_BITOR(BOOST_PP_LIST_IS_CONS(captures), \
Chris@16 579 has_this), \
Chris@16 580 : \
Chris@16 581 ) \
Chris@16 582 BOOST_PP_LIST_FOR_EACH_I(BOOST_SCOPE_EXIT_AUX_MEMBER_INIT, id, \
Chris@16 583 captures) \
Chris@16 584 BOOST_PP_IIF(has_this, \
Chris@16 585 BOOST_SCOPE_EXIT_AUX_MEMBER_THIS_INIT \
Chris@16 586 , \
Chris@16 587 BOOST_PP_TUPLE_EAT(2) \
Chris@16 588 )(id, BOOST_PP_LIST_IS_CONS(captures)) \
Chris@16 589 {}
Chris@16 590
Chris@16 591 #define BOOST_SCOPE_EXIT_DETAIL_PARAM_INIT(r, id, i, var) \
Chris@16 592 BOOST_PP_COMMA_IF(i) BOOST_SCOPE_EXIT_AUX_DEREF(id,i,var)
Chris@16 593
Chris@16 594 #define BOOST_SCOPE_EXIT_AUX_PARAMS_INIT(id, captures, has_this) \
Chris@16 595 BOOST_PP_LPAREN_IF(BOOST_PP_BITOR(has_this, \
Chris@16 596 BOOST_PP_LIST_IS_CONS(captures))) \
Chris@16 597 BOOST_PP_LIST_FOR_EACH_I(BOOST_SCOPE_EXIT_DETAIL_PARAM_INIT, id, captures) \
Chris@16 598 BOOST_PP_COMMA_IF(BOOST_PP_BITAND(BOOST_PP_LIST_IS_CONS(captures), \
Chris@16 599 has_this)) \
Chris@16 600 BOOST_PP_EXPR_IIF(has_this, this) \
Chris@16 601 BOOST_PP_RPAREN_IF(BOOST_PP_BITOR(has_this, \
Chris@16 602 BOOST_PP_LIST_IS_CONS(captures)))
Chris@16 603
Chris@16 604 #endif // TPL_GCC_WORKAROUND
Chris@16 605
Chris@16 606 #if defined(BOOST_TYPEOF_EMULATION)
Chris@16 607
Chris@16 608 #define BOOST_SCOPE_EXIT_DETAIL_CAPTURE_DECL(r, id_ty, i, var) \
Chris@16 609 struct BOOST_SCOPE_EXIT_AUX_WRAPPED(BOOST_PP_TUPLE_ELEM(2, 0, id_ty), i) \
Chris@16 610 /* no need to use TYPEOF_TPL here because it's within inheritance */ \
Chris@16 611 : BOOST_TYPEOF(::boost::scope_exit::detail::wrap( \
Chris@16 612 BOOST_SCOPE_EXIT_AUX_DEREF(BOOST_PP_TUPLE_ELEM(2, 0, id_ty), \
Chris@16 613 i, var))) \
Chris@16 614 {}; \
Chris@16 615 typedef BOOST_PP_TUPLE_ELEM(2, 1, id_ty) \
Chris@16 616 BOOST_SCOPE_EXIT_AUX_WRAPPED(BOOST_PP_TUPLE_ELEM(2, 0, id_ty), i)::type\
Chris@16 617 BOOST_SCOPE_EXIT_DETAIL_CAPTURE_T(BOOST_PP_TUPLE_ELEM(2, 0, id_ty), \
Chris@16 618 i, var) \
Chris@16 619 ;
Chris@16 620
Chris@16 621 #elif defined(BOOST_INTEL)
Chris@16 622
Chris@16 623 #define BOOST_SCOPE_EXIT_DETAIL_CAPTURE_DECL(r, id_ty, i, var) \
Chris@16 624 typedef \
Chris@16 625 /* no TYPEOF_TPL here because uses TYPEOF_KEYWORD directly */ \
Chris@16 626 BOOST_TYPEOF_KEYWORD(BOOST_SCOPE_EXIT_AUX_DEREF( \
Chris@16 627 BOOST_PP_TUPLE_ELEM(2, 0, id_ty), i, var)) \
Chris@16 628 BOOST_SCOPE_EXIT_DETAIL_CAPTURE_T(BOOST_PP_TUPLE_ELEM(2, 0, id_ty), \
Chris@16 629 i, var) \
Chris@16 630 ;
Chris@16 631
Chris@16 632 #else
Chris@16 633
Chris@16 634 #define BOOST_SCOPE_EXIT_DETAIL_CAPTURE_DECL(r, id_ty, i, var) \
Chris@16 635 typedef \
Chris@16 636 /* no need to use TYPEOF_TPL here because it's a typedef */ \
Chris@16 637 BOOST_TYPEOF(::boost::scope_exit::detail::wrap( \
Chris@16 638 BOOST_SCOPE_EXIT_AUX_DEREF(BOOST_PP_TUPLE_ELEM(2, 0, id_ty), \
Chris@16 639 i, var))) \
Chris@16 640 BOOST_SCOPE_EXIT_AUX_WRAPPED(BOOST_PP_TUPLE_ELEM(2, 0, id_ty), i) \
Chris@16 641 ; \
Chris@16 642 typedef BOOST_PP_TUPLE_ELEM(2, 1, id_ty) \
Chris@16 643 BOOST_SCOPE_EXIT_AUX_WRAPPED(BOOST_PP_TUPLE_ELEM(2, 0, id_ty), i)::type\
Chris@16 644 BOOST_SCOPE_EXIT_DETAIL_CAPTURE_T(BOOST_PP_TUPLE_ELEM(2, 0, id_ty), \
Chris@16 645 i, var) \
Chris@16 646 ;
Chris@16 647
Chris@16 648 #endif
Chris@16 649
Chris@16 650 #define BOOST_SCOPE_EXIT_DETAIL_PARAM_DECL(r, id_ty, i, var) \
Chris@16 651 typedef \
Chris@16 652 BOOST_SCOPE_EXIT_DETAIL_CAPTURE_T(BOOST_PP_TUPLE_ELEM(2, 0, id_ty), \
Chris@16 653 i, var) \
Chris@16 654 BOOST_SCOPE_EXIT_DETAIL_PARAM_T(BOOST_PP_TUPLE_ELEM(2, 0, id_ty), \
Chris@16 655 i, var) \
Chris@16 656 ;
Chris@16 657
Chris@16 658 // Traits.
Chris@16 659
Chris@16 660 #define BOOST_SCOPE_EXIT_AUX_TRAITS_OP_CAPTURE(d, captures, this01, capture) \
Chris@16 661 (BOOST_PP_LIST_APPEND(captures, (capture, BOOST_PP_NIL)), this01)
Chris@16 662
Chris@16 663 #define BOOST_SCOPE_EXIT_AUX_TRAITS_OP_THIS(d, captures, this01, this_) \
Chris@16 664 (captures, 1 /* has this (note, no error if multiple this_) */)
Chris@16 665
Chris@16 666 #define BOOST_SCOPE_EXIT_AUX_TRAITS_OP(d, captures_this, capture) \
Chris@101 667 BOOST_PP_IIF(BOOST_SCOPE_EXIT_AUX_PP_KEYWORD_IS_THISUNDERSCORE_BACK(\
Chris@16 668 capture), \
Chris@16 669 BOOST_SCOPE_EXIT_AUX_TRAITS_OP_THIS \
Chris@16 670 , \
Chris@16 671 BOOST_SCOPE_EXIT_AUX_TRAITS_OP_CAPTURE \
Chris@16 672 )(d, BOOST_PP_TUPLE_ELEM(2, 0, captures_this), \
Chris@16 673 BOOST_PP_TUPLE_ELEM(2, 1, captures_this), capture)
Chris@16 674
Chris@16 675 // ref_val: & | =
Chris@16 676 #define BOOST_SCOPE_EXIT_AUX_TRAITS_ALL_OP(ref_val, traits) \
Chris@16 677 ( \
Chris@16 678 BOOST_PP_LIST_APPEND((ref_val, BOOST_PP_NIL), \
Chris@16 679 BOOST_SCOPE_EXIT_AUX_TRAITS_CAPTURES(traits)) \
Chris@16 680 , \
Chris@16 681 BOOST_SCOPE_EXIT_AUX_TRAITS_HAS_THIS(traits) \
Chris@16 682 )
Chris@16 683
Chris@16 684 #define BOOST_SCOPE_EXIT_AUX_TRAITS(captures) \
Chris@16 685 BOOST_PP_LIST_FOLD_LEFT(BOOST_SCOPE_EXIT_AUX_TRAITS_OP, \
Chris@16 686 (BOOST_PP_NIL, 0), captures)
Chris@16 687
Chris@16 688 #define BOOST_SCOPE_EXIT_AUX_TRAITS_ALL(captures) \
Chris@16 689 BOOST_SCOPE_EXIT_AUX_TRAITS_ALL_OP(BOOST_PP_LIST_FIRST(captures), \
Chris@16 690 BOOST_SCOPE_EXIT_AUX_TRAITS(BOOST_PP_LIST_REST(captures)))
Chris@16 691
Chris@16 692 #define BOOST_SCOPE_EXIT_AUX_TRAITS_CAPTURES(traits) \
Chris@16 693 BOOST_PP_TUPLE_ELEM(2, 0, traits)
Chris@16 694
Chris@16 695 #define BOOST_SCOPE_EXIT_AUX_TRAITS_HAS_THIS(traits) \
Chris@16 696 BOOST_PP_TUPLE_ELEM(2, 1, traits)
Chris@16 697
Chris@16 698 #ifndef BOOST_NO_CXX11_LAMBDAS
Chris@16 699
Chris@16 700 namespace boost { namespace scope_exit { namespace aux {
Chris@16 701
Chris@16 702 template<typename This = void>
Chris@16 703 struct guard { // With object `this_` (for backward compatibility).
Chris@16 704 explicit guard(This _this) : this_(_this) {}
Chris@16 705 ~guard() { if(f_) f_(this_); }
Chris@16 706 template<typename Lambda>
Chris@16 707 void operator=(Lambda f) { f_ = f; }
Chris@16 708 private:
Chris@16 709 This this_;
Chris@16 710 boost::function<void (This)> f_;
Chris@16 711 };
Chris@16 712
Chris@16 713 template<>
Chris@16 714 struct guard<void> { // Without object `this_` (could capture `this` directly).
Chris@16 715 ~guard() { if(f_) f_(); }
Chris@16 716 template<typename Lambda>
Chris@16 717 void operator=(Lambda f) { f_ = f; }
Chris@16 718 private:
Chris@16 719 boost::function<void (void)> f_;
Chris@16 720 };
Chris@16 721
Chris@16 722 } } } // namespace
Chris@16 723
Chris@16 724 #define BOOST_SCOPE_EXIT_AUX_LAMBDA_PARAMS(id) \
Chris@16 725 BOOST_PP_CAT(boost_se_lambda_params_, id)
Chris@16 726
Chris@16 727 #define BOOST_SCOPE_EXIT_AUX_LAMBDA_THIS_CAPTURE_TYPE(id) \
Chris@16 728 BOOST_PP_CAT(boost_se_lambda_this_t_, id)
Chris@16 729
Chris@16 730 #define BOOST_SCOPE_EXIT_AUX_LAMBDA_THIS_PARAM_TYPE(id) \
Chris@16 731 BOOST_PP_CAT(boost_se_lambda_this_capture_t_, id)
Chris@16 732
Chris@16 733 #define BOOST_SCOPE_EXIT_AUX_LAMBDA_THIS_TYPE(id, ty) \
Chris@16 734 ty BOOST_SCOPE_EXIT_AUX_LAMBDA_PARAMS(id):: \
Chris@16 735 BOOST_SCOPE_EXIT_AUX_LAMBDA_THIS_PARAM_TYPE(id)
Chris@16 736
Chris@16 737 // Precondition: HAS_THIS(traits).
Chris@16 738 #define BOOST_SCOPE_EXIT_AUX_LAMBDA_THIS_TYPEDEFS(id, ty, traits) \
Chris@16 739 BOOST_SCOPE_EXIT_DETAIL_TYPEDEF_TYPEOF_THIS(id, ty, \
Chris@16 740 BOOST_SCOPE_EXIT_AUX_LAMBDA_THIS_CAPTURE_TYPE(id)) \
Chris@16 741 /* capture type for workaround GCC internal error (even on later C++11) */ \
Chris@16 742 struct BOOST_SCOPE_EXIT_AUX_LAMBDA_PARAMS(id) { \
Chris@16 743 typedef BOOST_SCOPE_EXIT_AUX_LAMBDA_THIS_CAPTURE_TYPE(id) \
Chris@16 744 BOOST_SCOPE_EXIT_AUX_LAMBDA_THIS_PARAM_TYPE(id); \
Chris@16 745 };
Chris@16 746
Chris@16 747 #define BOOST_SCOPE_EXIT_AUX_IMPL_LAMBDA(id, ty, traits) \
Chris@16 748 BOOST_PP_IIF(BOOST_SCOPE_EXIT_AUX_TRAITS_HAS_THIS(traits), \
Chris@16 749 /* no need for TYPEDEF THIS MSVC workaround on C++11 */ \
Chris@16 750 BOOST_SCOPE_EXIT_AUX_LAMBDA_THIS_TYPEDEFS \
Chris@16 751 , \
Chris@16 752 BOOST_PP_TUPLE_EAT(3) \
Chris@16 753 )(id, ty, traits) \
Chris@16 754 ::boost::scope_exit::aux::guard< \
Chris@16 755 BOOST_PP_IIF(BOOST_SCOPE_EXIT_AUX_TRAITS_HAS_THIS(traits), \
Chris@16 756 BOOST_SCOPE_EXIT_AUX_LAMBDA_THIS_TYPE \
Chris@16 757 , \
Chris@16 758 BOOST_PP_TUPLE_EAT(2) \
Chris@16 759 )(id, ty) \
Chris@16 760 > BOOST_SCOPE_EXIT_AUX_GUARD(id) \
Chris@16 761 BOOST_PP_EXPR_IIF(BOOST_SCOPE_EXIT_AUX_TRAITS_HAS_THIS(traits), \
Chris@16 762 (this) \
Chris@16 763 ) \
Chris@16 764 ; \
Chris@16 765 BOOST_SCOPE_EXIT_AUX_GUARD(id) = [ \
Chris@16 766 BOOST_PP_LIST_ENUM(BOOST_SCOPE_EXIT_AUX_TRAITS_CAPTURES(traits)) \
Chris@16 767 ]( \
Chris@16 768 BOOST_PP_IIF(BOOST_SCOPE_EXIT_AUX_TRAITS_HAS_THIS(traits), \
Chris@16 769 BOOST_SCOPE_EXIT_AUX_LAMBDA_THIS_TYPE \
Chris@16 770 , \
Chris@16 771 BOOST_PP_TUPLE_EAT(2) \
Chris@16 772 )(id, ty) \
Chris@16 773 BOOST_PP_EXPR_IIF(BOOST_SCOPE_EXIT_AUX_TRAITS_HAS_THIS(traits), this_) \
Chris@16 774 ) mutable /* can change value captures (as with SCOPE_EXIT) */ -> void
Chris@16 775
Chris@16 776 #endif // Lambdas.
Chris@16 777
Chris@16 778 #if defined(BOOST_SCOPE_EXIT_CONFIG_USE_LAMBDAS) && \
Chris@16 779 !defined(BOOST_NO_CXX11_LAMBDAS) // Use lambda for SCOPE_EXIT (not just _ALL).
Chris@16 780
Chris@16 781 #define BOOST_SCOPE_EXIT_AUX_IMPL(id, ty, traits) \
Chris@16 782 BOOST_SCOPE_EXIT_AUX_IMPL_LAMBDA(id, ty, traits)
Chris@16 783
Chris@16 784 #else // Not using lambdas.
Chris@16 785
Chris@16 786 // ty: EMPTY() | typename
Chris@16 787 #define BOOST_SCOPE_EXIT_AUX_IMPL(id, ty, traits) \
Chris@16 788 BOOST_PP_LIST_FOR_EACH_I(BOOST_SCOPE_EXIT_DETAIL_TAG_DECL, id, \
Chris@16 789 BOOST_SCOPE_EXIT_AUX_TRAITS_CAPTURES(traits)) \
Chris@16 790 BOOST_PP_LIST_FOR_EACH_I(BOOST_SCOPE_EXIT_DETAIL_CAPTURE_DECL, (id, ty), \
Chris@16 791 BOOST_SCOPE_EXIT_AUX_TRAITS_CAPTURES(traits)) \
Chris@16 792 BOOST_PP_IIF(BOOST_SCOPE_EXIT_AUX_TRAITS_HAS_THIS(traits), \
Chris@16 793 BOOST_SCOPE_EXIT_DETAIL_TYPEDEF_TYPEOF_THIS \
Chris@16 794 , \
Chris@16 795 BOOST_PP_TUPLE_EAT(3) \
Chris@16 796 )(id, ty, BOOST_SCOPE_EXIT_AUX_THIS_CAPTURE_T(id)) \
Chris@16 797 struct BOOST_SCOPE_EXIT_DETAIL_PARAMS_T(id) { \
Chris@16 798 /* interim capture types to workaround internal errors on old GCC */ \
Chris@16 799 BOOST_PP_LIST_FOR_EACH_I(BOOST_SCOPE_EXIT_DETAIL_PARAM_DECL, (id, ty), \
Chris@16 800 BOOST_SCOPE_EXIT_AUX_TRAITS_CAPTURES(traits)) \
Chris@16 801 BOOST_PP_EXPR_IIF(BOOST_SCOPE_EXIT_AUX_TRAITS_HAS_THIS(traits), \
Chris@16 802 typedef BOOST_SCOPE_EXIT_AUX_THIS_CAPTURE_T(id) \
Chris@16 803 BOOST_SCOPE_EXIT_AUX_THIS_T(id) ; \
Chris@16 804 ) \
Chris@16 805 BOOST_PP_LIST_FOR_EACH_I(BOOST_SCOPE_EXIT_AUX_MEMBER, id, \
Chris@16 806 BOOST_SCOPE_EXIT_AUX_TRAITS_CAPTURES(traits)) \
Chris@16 807 BOOST_PP_EXPR_IIF(BOOST_SCOPE_EXIT_AUX_TRAITS_HAS_THIS(traits), \
Chris@16 808 BOOST_SCOPE_EXIT_AUX_THIS_T(id) \
Chris@16 809 BOOST_SCOPE_EXIT_DETAIL_PARAM_THIS(id) ; \
Chris@16 810 ) \
Chris@16 811 BOOST_SCOPE_EXIT_AUX_PARAMS_T_CTOR(id, ty, \
Chris@16 812 BOOST_SCOPE_EXIT_AUX_TRAITS_CAPTURES(traits), \
Chris@16 813 BOOST_SCOPE_EXIT_AUX_TRAITS_HAS_THIS(traits)) \
Chris@16 814 } BOOST_SCOPE_EXIT_AUX_PARAMS(id) \
Chris@16 815 BOOST_SCOPE_EXIT_AUX_PARAMS_INIT(id, \
Chris@16 816 BOOST_SCOPE_EXIT_AUX_TRAITS_CAPTURES(traits), \
Chris@16 817 BOOST_SCOPE_EXIT_AUX_TRAITS_HAS_THIS(traits)) \
Chris@16 818 ; \
Chris@16 819 ::boost::scope_exit::detail::declared< \
Chris@16 820 ::boost::scope_exit::detail::resolve< \
Chris@16 821 sizeof(BOOST_SCOPE_EXIT_AUX_ARGS) \
Chris@16 822 >::cmp1<0>::cmp2 \
Chris@16 823 > BOOST_SCOPE_EXIT_AUX_ARGS; \
Chris@16 824 BOOST_SCOPE_EXIT_AUX_ARGS.value = &BOOST_SCOPE_EXIT_AUX_PARAMS(id); \
Chris@16 825 struct BOOST_SCOPE_EXIT_AUX_GUARD_T(id) { \
Chris@16 826 BOOST_SCOPE_EXIT_DETAIL_PARAMS_T(id)* boost_se_params_; \
Chris@16 827 BOOST_SCOPE_EXIT_AUX_GUARD_T(id) (void* boost_se_params) \
Chris@16 828 : boost_se_params_( \
Chris@16 829 (BOOST_SCOPE_EXIT_DETAIL_PARAMS_T(id)*)boost_se_params) \
Chris@16 830 {} \
Chris@16 831 ~BOOST_SCOPE_EXIT_AUX_GUARD_T(id)() { \
Chris@16 832 boost_se_body( \
Chris@16 833 BOOST_PP_LIST_FOR_EACH_I(BOOST_SCOPE_EXIT_AUX_ARG, id, \
Chris@16 834 BOOST_SCOPE_EXIT_AUX_TRAITS_CAPTURES(traits)) \
Chris@16 835 BOOST_PP_COMMA_IF(BOOST_PP_BITAND(BOOST_PP_LIST_IS_CONS( \
Chris@16 836 BOOST_SCOPE_EXIT_AUX_TRAITS_CAPTURES(traits)), \
Chris@16 837 BOOST_SCOPE_EXIT_AUX_TRAITS_HAS_THIS(traits))) \
Chris@16 838 BOOST_PP_EXPR_IIF(BOOST_SCOPE_EXIT_AUX_TRAITS_HAS_THIS( \
Chris@16 839 traits), \
Chris@16 840 boost_se_params_->BOOST_SCOPE_EXIT_DETAIL_PARAM_THIS(id) \
Chris@16 841 ) \
Chris@16 842 ); \
Chris@16 843 } \
Chris@16 844 static void boost_se_body( \
Chris@16 845 BOOST_PP_LIST_FOR_EACH_I(BOOST_SCOPE_EXIT_AUX_ARG_DECL, (id, ty), \
Chris@16 846 BOOST_SCOPE_EXIT_AUX_TRAITS_CAPTURES(traits)) \
Chris@16 847 BOOST_PP_COMMA_IF(BOOST_PP_BITAND(BOOST_PP_LIST_IS_CONS( \
Chris@16 848 BOOST_SCOPE_EXIT_AUX_TRAITS_CAPTURES(traits)), \
Chris@16 849 BOOST_SCOPE_EXIT_AUX_TRAITS_HAS_THIS(traits))) \
Chris@16 850 BOOST_PP_EXPR_IIF(BOOST_SCOPE_EXIT_AUX_TRAITS_HAS_THIS(traits), \
Chris@16 851 ty BOOST_SCOPE_EXIT_DETAIL_PARAMS_T(id):: \
Chris@16 852 BOOST_SCOPE_EXIT_AUX_THIS_T(id) this_ \
Chris@16 853 ) \
Chris@16 854 )
Chris@16 855
Chris@16 856 #endif // Using lambdas.
Chris@16 857
Chris@16 858 // PUBLIC //
Chris@16 859
Chris@16 860 #if defined(BOOST_NO_CXX11_VARIADIC_MACROS) // No variadic macros (sequences only).
Chris@16 861 # define BOOST_SCOPE_EXIT_ID(id, void_or_seq) \
Chris@16 862 BOOST_SCOPE_EXIT_AUX_IMPL(id, BOOST_PP_EMPTY(), \
Chris@16 863 BOOST_SCOPE_EXIT_AUX_TRAITS( \
Chris@101 864 BOOST_SCOPE_EXIT_AUX_PP_VOID_LIST(void_or_seq)))
Chris@16 865 # define BOOST_SCOPE_EXIT_ID_TPL(id, void_or_seq) \
Chris@16 866 BOOST_SCOPE_EXIT_AUX_IMPL(id, typename, \
Chris@16 867 BOOST_SCOPE_EXIT_AUX_TRAITS( \
Chris@101 868 BOOST_SCOPE_EXIT_AUX_PP_VOID_LIST(void_or_seq)))
Chris@16 869 # define BOOST_SCOPE_EXIT(void_or_seq) \
Chris@101 870 BOOST_SCOPE_EXIT_ID(BOOST_SCOPE_EXIT_AUX_PP_LINE_COUNTER, \
Chris@16 871 void_or_seq)
Chris@16 872 # define BOOST_SCOPE_EXIT_TPL(void_or_seq) \
Chris@101 873 BOOST_SCOPE_EXIT_ID_TPL(BOOST_SCOPE_EXIT_AUX_PP_LINE_COUNTER, \
Chris@16 874 void_or_seq)
Chris@16 875 # if !defined(BOOST_NO_CXX11_LAMBDAS)
Chris@16 876 # define BOOST_SCOPE_EXIT_ALL_ID(id, seq) \
Chris@16 877 BOOST_SCOPE_EXIT_AUX_IMPL_LAMBDA(id, \
Chris@16 878 /* C++11 allows to use typename outside templates so */ \
Chris@16 879 /* always typename here and no need for ..._ALL_TPL */ \
Chris@16 880 /* (if a C++11 compiler does not implement this use of */ \
Chris@16 881 /* typename, always use `this` instead of `this_`) */ \
Chris@16 882 typename, \
Chris@16 883 BOOST_SCOPE_EXIT_AUX_TRAITS_ALL( \
Chris@101 884 BOOST_SCOPE_EXIT_AUX_PP_NON_VOID_LIST(seq)))
Chris@16 885 # define BOOST_SCOPE_EXIT_ALL(seq) \
Chris@16 886 BOOST_SCOPE_EXIT_ALL_ID( \
Chris@101 887 BOOST_SCOPE_EXIT_AUX_PP_LINE_COUNTER, seq)
Chris@16 888 # endif
Chris@16 889 #else // Variadic macros (both sequences and variadic tuples).
Chris@16 890 # define BOOST_SCOPE_EXIT_ID(id, ...) \
Chris@16 891 BOOST_SCOPE_EXIT_AUX_IMPL(id, BOOST_PP_EMPTY(), \
Chris@16 892 BOOST_SCOPE_EXIT_AUX_TRAITS( \
Chris@101 893 BOOST_SCOPE_EXIT_AUX_PP_VOID_LIST(__VA_ARGS__)))
Chris@16 894 # define BOOST_SCOPE_EXIT_ID_TPL(id, ...) \
Chris@16 895 BOOST_SCOPE_EXIT_AUX_IMPL(id, typename, \
Chris@16 896 BOOST_SCOPE_EXIT_AUX_TRAITS( \
Chris@101 897 BOOST_SCOPE_EXIT_AUX_PP_VOID_LIST(__VA_ARGS__)))
Chris@16 898 # define BOOST_SCOPE_EXIT(...) \
Chris@101 899 BOOST_SCOPE_EXIT_ID(BOOST_SCOPE_EXIT_AUX_PP_LINE_COUNTER, \
Chris@16 900 __VA_ARGS__)
Chris@16 901 # define BOOST_SCOPE_EXIT_TPL(...) \
Chris@101 902 BOOST_SCOPE_EXIT_ID_TPL(BOOST_SCOPE_EXIT_AUX_PP_LINE_COUNTER, \
Chris@16 903 __VA_ARGS__)
Chris@16 904 # if !defined(BOOST_NO_CXX11_LAMBDAS)
Chris@16 905 # define BOOST_SCOPE_EXIT_ALL_ID(id, ...) \
Chris@16 906 BOOST_SCOPE_EXIT_AUX_IMPL_LAMBDA(id, \
Chris@16 907 /* C++11 allows to use typename outside templates so */ \
Chris@16 908 /* always typename here and no need for ..._ALL_TPL */ \
Chris@16 909 /* (if a C++11 compiler does not implement this use of */ \
Chris@16 910 /* typename, always use `this` instead of `this_`) */ \
Chris@16 911 typename, \
Chris@16 912 BOOST_SCOPE_EXIT_AUX_TRAITS_ALL( \
Chris@101 913 BOOST_SCOPE_EXIT_AUX_PP_NON_VOID_LIST( \
Chris@16 914 __VA_ARGS__)))
Chris@16 915 # define BOOST_SCOPE_EXIT_ALL(...) \
Chris@16 916 BOOST_SCOPE_EXIT_ALL_ID( \
Chris@101 917 BOOST_SCOPE_EXIT_AUX_PP_LINE_COUNTER, __VA_ARGS__)
Chris@16 918 # endif
Chris@16 919 #endif // Variadics.
Chris@16 920
Chris@16 921 #if defined(BOOST_SCOPE_EXIT_CONFIG_USE_LAMBDAS) && \
Chris@16 922 !defined(BOOST_NO_CXX11_LAMBDAS) // Use lambdas for SCOPE_EXIT (not just ALL).
Chris@16 923 # define BOOST_SCOPE_EXIT_END_ID(id) \
Chris@16 924 ; /* lambdas ended with just `;` */
Chris@16 925 #else // Not using lambdas.
Chris@16 926 # define BOOST_SCOPE_EXIT_END_ID(id) \
Chris@16 927 } BOOST_SCOPE_EXIT_AUX_GUARD(id)(BOOST_SCOPE_EXIT_AUX_ARGS.value);
Chris@16 928 #endif // Using lambdas.
Chris@16 929 #define BOOST_SCOPE_EXIT_END \
Chris@101 930 BOOST_SCOPE_EXIT_END_ID(BOOST_SCOPE_EXIT_AUX_PP_LINE_COUNTER)
Chris@16 931
Chris@16 932 // DOCUMENTATION //
Chris@16 933
Chris@16 934 #else // DOXYGEN
Chris@16 935
Chris@16 936 /** @file
Chris@16 937 @brief Scope exits allow to execute arbitrary code when the enclosing scope
Chris@16 938 exits.
Chris@16 939 */
Chris@16 940
Chris@16 941 /**
Chris@16 942 @brief This macro declares a scope exit.
Chris@16 943
Chris@16 944 The scope exit declaration schedules the execution of the scope exit body at
Chris@16 945 the exit of the enclosing scope:
Chris@16 946
Chris@16 947 @code
Chris@16 948 { // Some local scope.
Chris@16 949 ...
Chris@16 950 BOOST_SCOPE_EXIT(capture_list) {
Chris@16 951 ... // Body code.
Chris@16 952 } BOOST_SCOPE_EXIT_END
Chris@16 953 ...
Chris@16 954 }
Chris@16 955 @endcode
Chris@16 956
Chris@16 957 The enclosing scope must be local.
Chris@16 958 If multiple scope exits are declared within the same enclosing scope, the scope
Chris@16 959 exit bodies are executed in the reversed order of their declarations.
Chris@16 960 Note how the end of the scope exit body must be marked by
Chris@16 961 @RefMacro{BOOST_SCOPE_EXIT_END}.
Chris@16 962
Chris@16 963 @Params
Chris@16 964 @Param{capture_list,
Chris@16 965 On compilers that support variadic macros (see also Boost.Config
Chris@16 966 <c>BOOST_NO_CXX11_VARIADIC_MACROS</c>)\, the capture list syntax is defined by the
Chris@16 967 following grammar:
Chris@16 968 @code
Chris@16 969 capture_list:
Chris@16 970 void | capture_tuple | capture_sequence
Chris@16 971 capture_tuple:
Chris@16 972 capture\, capture\, ...
Chris@16 973 capture_sequence:
Chris@16 974 (capture) (capture) ...
Chris@16 975 capture:
Chris@16 976 [&]variable | this_
Chris@16 977 @endcode
Chris@16 978 On compilers that do not support variadic macros\, <c>capture_tuple</c> cannot
Chris@16 979 be used:
Chris@16 980 @code
Chris@16 981 capture_list:
Chris@16 982 void | capture_sequence
Chris@16 983 @endcode
Chris@16 984 Furthermore\, if @RefMacro{BOOST_SCOPE_EXIT_CONFIG_USE_LAMBDAS} is defined on
Chris@16 985 C++11 compilers that support lambda functions (i.e.\, Boost.Config's <c>BOOST_NO_CXX11_LAMBDAS</c> is not defined) then a semicolon <c>;</c> can be used instead of
Chris@16 986 @RefMacro{BOOST_SCOPE_EXIT_END} and <c>this</c> can be used instead of
Chris@16 987 <c>this_</c>:
Chris@16 988 @code
Chris@16 989 capture:
Chris@16 990 [&]variable | this_ | this
Chris@16 991 @endcode
Chris@16 992
Chris@16 993 (Lexical conventions: <c>token1 | token2</c> means either <c>token1</c> or
Chris@16 994 <c>token2</c>; <c>[token]</c> means either <c>token</c> or nothing;
Chris@16 995 <c>{expression}</c> means the tokens resulting from the expression.)
Chris@16 996 }
Chris@16 997 @EndParams
Chris@16 998
Chris@16 999 Note that on compilers that support variadic macros (most of moder compliers
Chris@16 1000 and all C++11 compilers), the capture list can be specified as a
Chris@16 1001 comma-separated list of tokens (this is the preferred syntax).
Chris@16 1002 However, on all compilers the same macro @RefMacro{BOOST_SCOPE_EXIT} also
Chris@16 1003 allows to specify the capture list as a Boost.Preprocessor sequence of tokens
Chris@16 1004 (for supporting compilers without variadic macros and for backward compatibility with older versions of this library).
Chris@16 1005
Chris@16 1006 The name <c>variable</c> of each captured variable must be a valid name in the
Chris@16 1007 enclosing scope and it must appear exactly once in the capture list.
Chris@16 1008 If a capture starts with the ampersand sign <c>&</c>, the corresponding
Chris@16 1009 variable will be available by reference within the scope exit body; otherwise,
Chris@16 1010 a copy of the variable will be made at the point of the scope exit declaration
Chris@16 1011 and that copy will be available inside the scope exit body (in this case, the
Chris@16 1012 variable's type must be <c>CopyConstructible</c>).
Chris@16 1013
Chris@16 1014 From within a member function, the object <c>this</c> can be captured using the
Chris@16 1015 special name <c>this_</c> in both the capture list and the scope exit body
Chris@16 1016 (using <c>this</c> instead of <c>this_</c> in the scope exit body leads to
Chris@16 1017 undefined behaviour).
Chris@16 1018
Chris@16 1019 It is possible to capture no variable by specifying the capture list as
Chris@16 1020 <c>void</c> (regardless of variadic macro support).
Chris@16 1021
Chris@16 1022 Only variables listed in the capture list, static variables, <c>extern</c>
Chris@16 1023 variables, global variables, functions, and enumerations from the enclosing
Chris@16 1024 scope can be used inside the scope exit body.
Chris@16 1025
Chris@16 1026 On various GCC versions the special macro @RefMacro{BOOST_SCOPE_EXIT_TPL} must
Chris@16 1027 be used instead of @RefMacro{BOOST_SCOPE_EXIT} within templates (to maximize
Chris@16 1028 portability, it is recommended to always use @RefMacro{BOOST_SCOPE_EXIT_TPL}
Chris@16 1029 within templates).
Chris@16 1030
Chris@16 1031 On C++11, it is possible capture all variables in scope without listing their
Chris@16 1032 names one-by-one using the macro @RefMacro{BOOST_SCOPE_EXIT_ALL}.
Chris@16 1033
Chris@16 1034 In general, the special macro @RefMacro{BOOST_SCOPE_EXIT_ID} must be used
Chris@16 1035 instead of @RefMacro{BOOST_SCOPE_EXIT} when it is necessary to expand multiple
Chris@16 1036 scope exit declarations on the same line.
Chris@16 1037
Chris@16 1038 @Warning The implementation executes the scope exit body within a destructor
Chris@16 1039 thus the scope exit body must never throw in order to comply with STL exception
Chris@16 1040 safety requirements.
Chris@16 1041
Chris@16 1042 @Note The implementation uses Boost.Typeof to automatically deduce the types of
Chris@16 1043 the captured variables.
Chris@16 1044 In order to compile code in type-of emulation mode, all types must be properly
Chris@16 1045 registered with Boost.Typeof (see the
Chris@16 1046 @RefSect{getting_started, Getting Started} section).
Chris@16 1047
Chris@16 1048 @See @RefSect{tutorial, Tutorial} section,
Chris@16 1049 @RefSect{getting_started, Getting Started} section,
Chris@16 1050 @RefSect{no_variadic_macros, No Variadic Macros} section,
Chris@16 1051 @RefMacro{BOOST_SCOPE_EXIT_TPL}, @RefMacro{BOOST_SCOPE_EXIT_ALL},
Chris@16 1052 @RefMacro{BOOST_SCOPE_EXIT_END}, @RefMacro{BOOST_SCOPE_EXIT_ID}.
Chris@16 1053 */
Chris@16 1054 #define BOOST_SCOPE_EXIT(capture_list)
Chris@16 1055
Chris@16 1056 /**
Chris@16 1057 @brief This macro is a workaround for various versions of GCC to declare scope
Chris@16 1058 exits within templates.
Chris@16 1059
Chris@16 1060 Various versions of the GCC compiler do not compile @RefMacro{BOOST_SCOPE_EXIT}
Chris@16 1061 inside function templates.
Chris@16 1062 As a workaround, @RefMacro{BOOST_SCOPE_EXIT_TPL} should be used instead of
Chris@16 1063 @RefMacro{BOOST_SCOPE_EXIT} in these cases:
Chris@16 1064
Chris@16 1065 @code
Chris@16 1066 { // Some local scope.
Chris@16 1067 ...
Chris@16 1068 BOOST_SCOPE_EXIT_TPL(capture_list) {
Chris@16 1069 ... // Body code.
Chris@16 1070 } BOOST_SCOPE_EXIT_END
Chris@16 1071 ...
Chris@16 1072 }
Chris@16 1073 @endcode
Chris@16 1074
Chris@16 1075 The syntax of @RefMacro{BOOST_SCOPE_EXIT_TPL} is the exact same as the one of
Chris@16 1076 @RefMacro{BOOST_SCOPE_EXIT} (see @RefMacro{BOOST_SCOPE_EXIT} for more
Chris@16 1077 information).
Chris@16 1078
Chris@16 1079 On C++11 compilers, @RefMacro{BOOST_SCOPE_EXIT_TPL} is not needed because
Chris@16 1080 @RefMacro{BOOST_SCOPE_EXIT} always compiles on GCC versions that support C++11.
Chris@16 1081 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 1082 It is recommended to always use @RefMacro{BOOST_SCOPE_EXIT_TPL} within
Chris@16 1083 templates so to maximize portability.
Chris@16 1084
Chris@16 1085 In general, the special macro @RefMacro{BOOST_SCOPE_EXIT_ID_TPL} must be used
Chris@16 1086 instead of @RefMacro{BOOST_SCOPE_EXIT_TPL} when it is necessary to expand
Chris@16 1087 multiple scope exit declarations on the same line within templates.
Chris@16 1088
Chris@16 1089 @Note The issue in compiling scope exit declarations that some GCC versions
Chris@16 1090 have is illustrated by the following code (see also
Chris@16 1091 <a href="http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37920">GCC bug 37920</a>):
Chris@16 1092 @code
Chris@16 1093 template<class T>
Chris@16 1094 void f(T const& x) {
Chris@16 1095 int i = 0;
Chris@16 1096 struct local {
Chris@16 1097 typedef __typeof__(i) typeof_i;
Chris@16 1098 typedef __typeof__(x) typeof_x;
Chris@16 1099 };
Chris@16 1100 typedef local::typeof_i i_type;
Chris@16 1101 typedef local::typeof_x x_type;
Chris@16 1102 }
Chris@16 1103
Chris@16 1104 int main(void) { f(0); }
Chris@16 1105 @endcode
Chris@16 1106 This can be fixed by adding <c>typename</c> in front of <c>local::typeof_i</c>
Chris@16 1107 and <c>local::typeof_x</c> (which is the approach followed by the
Chris@16 1108 implementation of the @RefMacro{BOOST_SCOPE_EXIT_TPL} macro).
Chris@16 1109
Chris@16 1110 @Note Although @RefMacro{BOOST_SCOPE_EXIT_TPL} has the same suffix as
Chris@16 1111 <c>BOOST_TYPEOF_TPL</c>, it does not follow the Boost.Typeof convention.
Chris@16 1112
Chris@16 1113 @See @RefSect{tutorial, Tutorial} section, @RefMacro{BOOST_SCOPE_EXIT},
Chris@16 1114 @RefMacro{BOOST_SCOPE_EXIT_END}, @RefMacro{BOOST_SCOPE_EXIT_ID_TPL}.
Chris@16 1115 */
Chris@16 1116 #define BOOST_SCOPE_EXIT_TPL(capture_list)
Chris@16 1117
Chris@16 1118 /**
Chris@16 1119 @brief This macro allows to expand multiple scope exit declarations on the same
Chris@16 1120 line.
Chris@16 1121
Chris@16 1122 This macro is equivalent to @RefMacro{BOOST_SCOPE_EXIT} but it can be expanded
Chris@16 1123 multiple times on the same line if different identifiers <c>id</c> are provided
Chris@16 1124 for each expansion (see @RefMacro{BOOST_SCOPE_EXIT} for more information).
Chris@16 1125
Chris@16 1126 @Params
Chris@16 1127 @Param{id,
Chris@16 1128 A unique identifier token which can be concatenated by the preprocessor
Chris@16 1129 (<c>__LINE__</c>\, <c>scope_exit_number_1_on_line_123</c>\, a combination of
Chris@16 1130 alphanumeric tokens\, etc).
Chris@16 1131 }
Chris@16 1132 @Param{capture_list,
Chris@16 1133 Same as the <c>capture_list</c> parameter of the @RefMacro{BOOST_SCOPE_EXIT}
Chris@16 1134 macro.
Chris@16 1135 }
Chris@16 1136 @EndParams
Chris@16 1137
Chris@16 1138 @Note This macro can be useful when the scope exit macros are expanded
Chris@16 1139 within user-defined macros (because nested macros expand on the same line).
Chris@16 1140 On some compilers (e.g., MSVC which supports the non standard
Chris@16 1141 <c>__COUNTER__</c> macro) it might not be necessary to use this macro but
Chris@16 1142 the use of this macro is always necessary to ensure portability when expanding
Chris@16 1143 multiple scope exit declarations on the same line.
Chris@16 1144
Chris@16 1145 @See @RefSect{tutorial, Tutorial} section, @RefMacro{BOOST_SCOPE_EXIT},
Chris@16 1146 @RefMacro{BOOST_SCOPE_EXIT_END_ID}, @RefMacro{BOOST_SCOPE_EXIT_ALL_ID},
Chris@16 1147 @RefMacro{BOOST_SCOPE_EXIT_ID_TPL}.
Chris@16 1148 */
Chris@16 1149 #define BOOST_SCOPE_EXIT_ID(id, capture_list)
Chris@16 1150
Chris@16 1151 /**
Chris@16 1152 @brief This macro is required to expand multiple scope exit declarations on the
Chris@16 1153 same line within templates on various versions of GCC.
Chris@16 1154
Chris@16 1155 This macro is equivalent to @RefMacro{BOOST_SCOPE_EXIT_TPL} but it can be
Chris@16 1156 expanded multiple times on the same line if different identifiers <c>id</c> are
Chris@16 1157 provided for each expansion (see @RefMacro{BOOST_SCOPE_EXIT_TPL} for more
Chris@16 1158 information).
Chris@16 1159 As with @RefMacro{BOOST_SCOPE_EXIT_TPL}, it is recommended to always use this
Chris@16 1160 macro when expanding scope exits multiple times on the same line within
Chris@16 1161 templates.
Chris@16 1162
Chris@16 1163 @Params
Chris@16 1164 @Param{id,
Chris@16 1165 A unique identifier token which can be concatenated by the preprocessor
Chris@16 1166 (<c>__LINE__</c>\, <c>scope_exit_number_1_on_line_123</c>\, a combination of
Chris@16 1167 alphanumeric tokens\, etc).
Chris@16 1168 }
Chris@16 1169 @Param{capture_list,
Chris@16 1170 Same as the <c>capture_list</c> parameter of the
Chris@16 1171 @RefMacro{BOOST_SCOPE_EXIT_TPL} macro.
Chris@16 1172 }
Chris@16 1173 @EndParams
Chris@16 1174
Chris@16 1175 @Note This macro can be useful when the scope exit macros are expanded
Chris@16 1176 within user-defined macros (because nested macros expand on the same line).
Chris@16 1177 On some compilers (e.g., MSVC which supports the non standard
Chris@16 1178 <c>__COUNTER__</c> macro) it might not be necessary to use this macro but
Chris@16 1179 the use of this macro is always necessary to ensure portability when expanding
Chris@16 1180 multiple scope exit declarations on the same line.
Chris@16 1181
Chris@16 1182 @See @RefSect{tutorial, Tutorial} section, @RefMacro{BOOST_SCOPE_EXIT_TPL},
Chris@16 1183 @RefMacro{BOOST_SCOPE_EXIT_END_ID}, @RefMacro{BOOST_SCOPE_EXIT_ID},
Chris@16 1184 @RefMacro{BOOST_SCOPE_EXIT_ALL_ID}.
Chris@16 1185 */
Chris@16 1186 #define BOOST_SCOPE_EXIT_ID_TPL(id, capture_list)
Chris@16 1187
Chris@16 1188 /**
Chris@16 1189 @brief This macro declares a scope exit that captures all variables in scope
Chris@16 1190 (C++11 only).
Chris@16 1191
Chris@16 1192 This macro accepts a capture list starting with either <c>&</c> or <c>=</c> to capture all variables in scope by reference or value respectively (following the same syntax of C++11 lambdas).
Chris@16 1193 A part from that, this macro works like @RefMacro{BOOST_SCOPE_EXIT} (see @RefMacro{BOOST_SCOPE_EXIT} for more information):
Chris@16 1194
Chris@16 1195 @code
Chris@16 1196 { // Some local scope.
Chris@16 1197 ...
Chris@16 1198 BOOST_SCOPE_EXIT_ALL(capture_list) { // C++11 only.
Chris@16 1199 ... // Body code.
Chris@16 1200 }; // Use `;` instead of `BOOST_SCOPE_EXIT_END` (C++11 only).
Chris@16 1201 ...
Chris@16 1202 }
Chris@16 1203 @endcode
Chris@16 1204
Chris@16 1205 Note how the end of the scope exit body declared by this macro must be marked
Chris@16 1206 by a semi-column <c>;</c> (and not by @RefMacro{BOOST_SCOPE_EXIT_END}).
Chris@16 1207
Chris@16 1208 @Warning This macro is only available on C++11 compilers (specifically, on
Chris@16 1209 C++11 compilers that do not define the Boost.Config <c>BOOST_NO_CXX11_LAMBDAS</c>
Chris@16 1210 macro).
Chris@16 1211 It is not defined on non-C++11 compilers so its use on non-C++11 compilers will generate a compiler error.
Chris@16 1212
Chris@16 1213 @Params
Chris@16 1214 @Param{capture_list,
Chris@16 1215 On compilers that support variadic macros (see also Boost.Config
Chris@16 1216 <c>BOOST_NO_CXX11_VARIADIC_MACROS</c>)\, the capture list syntax is defined by the
Chris@16 1217 following grammar:
Chris@16 1218 @code
Chris@16 1219 capture_list:
Chris@16 1220 capture_tuple | capture_sequence
Chris@16 1221 capture_tuple:
Chris@16 1222 {& | =} [\, capture\, capture\, ...]
Chris@16 1223 capture_sequence:
Chris@16 1224 {(&) | (=)} [(capture) (capture) ...]
Chris@16 1225 capture:
Chris@16 1226 [&]variable | this_
Chris@16 1227 @endcode
Chris@16 1228 On compilers that do not support variadic macros\, <c>capture_tuple</c> cannot
Chris@16 1229 be used:
Chris@16 1230 @code
Chris@16 1231 capture_list:
Chris@16 1232 void | capture_sequence
Chris@16 1233 @endcode
Chris@16 1234 Furthermore\, on C++11 compilers that support the use of <c>typename</c>
Chris@16 1235 outside templates\, also <c>this</c> can be used to capture the object at member
Chris@16 1236 function scope:
Chris@16 1237 @code
Chris@16 1238 capture:
Chris@16 1239 [&]variable | this_ | this
Chris@16 1240 @endcode
Chris@16 1241
Chris@16 1242 (Lexical conventions: <c>token1 | token2</c> means either <c>token1</c> or
Chris@16 1243 <c>token2</c>; <c>[token]</c> means either <c>token</c> or nothing;
Chris@16 1244 <c>{expression}</c> means the token resulting from the expression.)
Chris@16 1245 }
Chris@16 1246 @EndParams
Chris@16 1247
Chris@16 1248 Note that on compilers with variadic macro support (which should be all C++11
Chris@16 1249 compilers), the capture list can be specified as a comma-separated list.
Chris@16 1250 On all compilers, the same macro @RefMacro{BOOST_SCOPE_EXIT_ALL} also allows to
Chris@16 1251 specify the capture list as a Boost.Preprocessor sequence.
Chris@16 1252
Chris@16 1253 The capture list must always contain at least the leading <c>&</c> or <c>=</c>
Chris@16 1254 so it can never be <c>void</c> (<c>BOOST_SCOPE_EXIT(void)</c> should be used
Chris@16 1255 to program scope exits with an empty capture list).
Chris@16 1256
Chris@16 1257 In general, the special macro @RefMacro{BOOST_SCOPE_EXIT_ALL_ID} must be used
Chris@16 1258 instead of @RefMacro{BOOST_SCOPE_EXIT_ALL} when it is necessary to expand
Chris@16 1259 multiple scope exit declarations on the same line.
Chris@16 1260
Chris@16 1261 @Warning This macro capture list follows the exact same syntax of C++11 lambda
Chris@16 1262 captures which is unfortunately different from the syntax of
Chris@16 1263 @RefMacro{BOOST_SCOPE_EXIT} captures (unless programmers define the
Chris@16 1264 @RefMacro{BOOST_SCOPE_EXIT_CONFIG_USE_LAMBDAS} macro).
Chris@16 1265 For example, like C++11 lambda functions, @RefMacro{BOOST_SCOPE_EXIT_ALL}
Chris@16 1266 requires to capture data members by capturing the object <c>this</c> while
Chris@16 1267 @RefMacro{BOOST_SCOPE_EXIT} allows to capture data members directly and without
Chris@16 1268 capturing the object.
Chris@16 1269
Chris@16 1270 @Warning The implementation executes the scope exit body within a destructor
Chris@16 1271 thus the scope exit body must never throw in order to comply with STL exception
Chris@16 1272 safety requirements.
Chris@16 1273
Chris@16 1274 @Note This macro can always be used also within templates (so there is no need
Chris@16 1275 for a <c>BOOST_SCOPE_EXIT_ALL_TPL</c> macro).
Chris@16 1276
Chris@16 1277 @See @RefSect{tutorial, Tutorial} section,
Chris@16 1278 @RefSect{no_variadic_macros, No Variadic Macros} section,
Chris@16 1279 @RefMacro{BOOST_SCOPE_EXIT}, @RefMacro{BOOST_SCOPE_EXIT_ALL_ID}.
Chris@16 1280 */
Chris@16 1281 #define BOOST_SCOPE_EXIT_ALL(capture_list)
Chris@16 1282
Chris@16 1283 /**
Chris@16 1284 @brief This macro allows to expand on the same line multiple scope exits that
Chris@16 1285 capture all variables in scope (C++11 only).
Chris@16 1286
Chris@16 1287 This macro is equivalent to @RefMacro{BOOST_SCOPE_EXIT_ALL} but it can be
Chris@16 1288 expanded multiple times on the same line if different identifiers <c>id</c> are
Chris@16 1289 provided for each expansion (see @RefMacro{BOOST_SCOPE_EXIT_ALL} for more
Chris@16 1290 information).
Chris@16 1291 As with @RefMacro{BOOST_SCOPE_EXIT_ALL}, this macro is only available on C++11
Chris@16 1292 compilers (specifically, on C++11 compilers that do not define the
Chris@16 1293 Boost.Config <c>BOOST_NO_CXX11_LAMBDAS</c> macro).
Chris@16 1294
Chris@16 1295 @Params
Chris@16 1296 @Param{id,
Chris@16 1297 A unique identifier token which can be concatenated by the preprocessor
Chris@16 1298 (<c>__LINE__</c>\, <c>scope_exit_number_1_on_line_123</c>\, a combination of
Chris@16 1299 alphanumeric tokens\, etc).
Chris@16 1300 }
Chris@16 1301 @Param{capture_list,
Chris@16 1302 Same as the <c>capture_list</c> parameter of the
Chris@16 1303 @RefMacro{BOOST_SCOPE_EXIT_ALL} macro.
Chris@16 1304 }
Chris@16 1305 @EndParams
Chris@16 1306
Chris@16 1307 @Note This macro can be useful when the scope exit macros are expanded
Chris@16 1308 within user-defined macros (because nested macros expand on the same line).
Chris@16 1309 On some compilers (e.g., MSVC which supports the non standard
Chris@16 1310 <c>__COUNTER__</c> macro) it might not be necessary to use this macro but
Chris@16 1311 the use of this macro is always necessary to ensure portability when expanding
Chris@16 1312 multiple scope exit declarations on the same line.
Chris@16 1313
Chris@16 1314 @See @RefSect{tutorial, Tutorial} section, @RefMacro{BOOST_SCOPE_EXIT_ALL},
Chris@16 1315 @RefMacro{BOOST_SCOPE_EXIT_ID}.
Chris@16 1316 */
Chris@16 1317 #define BOOST_SCOPE_EXIT_ALL_ID(id, capture_list)
Chris@16 1318
Chris@16 1319 /**
Chris@16 1320 @brief This macro marks the end of a scope exit body.
Chris@16 1321
Chris@16 1322 This macro must follow the closing curly bracket <c>}</c> that ends the body of
Chris@16 1323 either @RefMacro{BOOST_SCOPE_EXIT} or @RefMacro{BOOST_SCOPE_EXIT_TPL}:
Chris@16 1324
Chris@16 1325 @code
Chris@16 1326 { // Some local scope.
Chris@16 1327 ...
Chris@16 1328 BOOST_SCOPE_EXIT(capture_list) {
Chris@16 1329 ... // Body code.
Chris@16 1330 } BOOST_SCOPE_EXIT_END
Chris@16 1331 ...
Chris@16 1332 }
Chris@16 1333 @endcode
Chris@16 1334
Chris@16 1335 In general, the special macro @RefMacro{BOOST_SCOPE_EXIT_END_ID} must be used
Chris@16 1336 instead of @RefMacro{BOOST_SCOPE_EXIT_END} when it is necessary to expand
Chris@16 1337 multiple scope exit bodies on the same line.
Chris@16 1338
Chris@16 1339 @Note If programmers define the @RefMacro{BOOST_SCOPE_EXIT_CONFIG_USE_LAMBDAS}
Chris@16 1340 macro on C++11 compilers, a semicolon <c>;</c> can be used instead of this
Chris@16 1341 macro.
Chris@16 1342 However, to maximize portability, it is recommended to always use
Chris@16 1343 @RefMacro{BOOST_SCOPE_EXIT_END}.
Chris@16 1344
Chris@16 1345 @See @RefSect{tutorial, Tutorial} section, @RefMacro{BOOST_SCOPE_EXIT},
Chris@16 1346 @RefMacro{BOOST_SCOPE_EXIT_TPL}, @RefMacro{BOOST_SCOPE_EXIT_END_ID}.
Chris@16 1347 */
Chris@16 1348 #define BOOST_SCOPE_EXIT_END
Chris@16 1349
Chris@16 1350 /**
Chris@16 1351 @brief This macro allows to terminate multiple scope exit bodies on the same
Chris@16 1352 line.
Chris@16 1353
Chris@16 1354 This macro is equivalent to @RefMacro{BOOST_SCOPE_EXIT_END} but it can be
Chris@16 1355 expanded multiple times on the same line if different identifiers <c>id</c> are
Chris@16 1356 provided for each expansion (see @RefMacro{BOOST_SCOPE_EXIT_END} for more
Chris@16 1357 information).
Chris@16 1358
Chris@16 1359 @Params
Chris@16 1360 @Param{id,
Chris@16 1361 A unique identifier token which can be concatenated by the preprocessor
Chris@16 1362 (<c>__LINE__</c>\, <c>scope_exit_number_1_on_line_123</c>\, a combination of
Chris@16 1363 alphanumeric tokens\, etc).
Chris@16 1364 }
Chris@16 1365 @EndParams
Chris@16 1366
Chris@16 1367 @Note This macro can be useful when the scope exit macros are expanded
Chris@16 1368 within user-defined macros (because macros all expand on the same line).
Chris@16 1369 On some compilers (e.g., MSVC which supports the non standard
Chris@16 1370 <c>__COUNTER__</c> macro) it might not be necessary to use this macro but
Chris@16 1371 the use of this macro is always necessary to ensure portability when expanding
Chris@16 1372 multiple scope exit macros on the same line (because this library can only
Chris@16 1373 portably use <c>__LINE__</c> to internally generate unique identifiers).
Chris@16 1374
Chris@16 1375 @See @RefMacro{BOOST_SCOPE_EXIT_ID}, @RefMacro{BOOST_SCOPE_EXIT_ID_TPL},
Chris@16 1376 @RefMacro{BOOST_SCOPE_EXIT_END}.
Chris@16 1377 */
Chris@16 1378 #define BOOST_SCOPE_EXIT_END_ID(id)
Chris@16 1379
Chris@16 1380 /**
Chris@16 1381 @brief Force to use C++11 lambda functions to implement scope exits.
Chris@16 1382
Chris@16 1383 If programmers define this configuration macro on a C++11 compiler for which
Chris@16 1384 the Boost.Config macro <c>BOOST_NO_CXX11_LAMBDAS</c> is not defined, the
Chris@16 1385 @RefMacro{BOOST_SCOPE_EXIT} and @RefMacro{BOOST_SCOPE_EXIT_TPL} macros will use
Chris@16 1386 C++11 lambda functions to declare scope exits.
Chris@16 1387 By default this macro is not defined.
Chris@16 1388
Chris@16 1389 @Warning When scope exits are implemented using lambda functions, the syntax of
Chris@16 1390 the capture list follows the exact same syntax of C++11 lambda captures
Chris@16 1391 which is in general different from the legacy capture syntax of this library.
Chris@16 1392 For example, C++11 lambdas require to capture data members by capturing the
Chris@16 1393 object <c>this</c> while this library always allowed to capture data members
Chris@16 1394 directly.
Chris@16 1395 Therefore, when this configuration macro is defined,
Chris@16 1396 @RefMacro{BOOST_SCOPE_EXIT} and @RefMacro{BOOST_SCOPE_EXIT_TPL} are no longer
Chris@16 1397 backward compatible (and this is why this macro is not defined by default).
Chris@16 1398
Chris@16 1399 A semicolon <c>;</c> can be used instead of @RefMacro{BOOST_SCOPE_EXIT_END}
Chris@16 1400 when this configuration macro is defined (but it is recommended to always use
Chris@16 1401 @RefMacro{BOOST_SCOPE_EXIT_END} so to maximize portability).
Chris@16 1402
Chris@16 1403 @Note This configuration macro does not control the definition of
Chris@16 1404 @RefMacro{BOOST_SCOPE_EXIT_ALL} which is always and automatically defined on
Chris@16 1405 compilers that support C++11 lambda functions.
Chris@16 1406
Chris@16 1407 @See @RefMacro{BOOST_SCOPE_EXIT}, @RefMacro{BOOST_SCOPE_EXIT_TPL},
Chris@16 1408 @RefMacro{BOOST_SCOPE_EXIT_END}.
Chris@16 1409 */
Chris@16 1410 #define BOOST_SCOPE_EXIT_CONFIG_USE_LAMBDAS
Chris@16 1411
Chris@16 1412 #endif // DOXYGEN
Chris@16 1413
Chris@16 1414 #endif // #ifndef FILE_boost_scope_exit_hpp_INCLUDED
Chris@16 1415