2 // Copyright (C) 2006-2009, 2012 Alexander Nasonov
3 // Copyright (C) 2012 Lorenzo Caminiti
4 // Distributed under the Boost Software License, Version 1.0
5 // (see accompanying file LICENSE_1_0.txt or a copy at
6 // http://www.boost.org/LICENSE_1_0.txt)
7 // Home at http://www.boost.org/libs/scope_exit
9 #include <boost/scope_exit.hpp>
10 #include <boost/preprocessor/cat.hpp>
11 #include <boost/config.hpp>
12 #include <boost/detail/lightweight_test.hpp>
14 #define SCOPE_EXIT_INC_DEC(variable, offset) \
15 BOOST_SCOPE_EXIT_ID(BOOST_PP_CAT(inc, __LINE__), /* unique ID */ \
16 (&variable) (offset) ) { \
18 } BOOST_SCOPE_EXIT_END_ID(BOOST_PP_CAT(inc, __LINE__)) \
20 BOOST_SCOPE_EXIT_ID(BOOST_PP_CAT(dec, __LINE__), \
21 (&variable) (offset) ) { \
23 } BOOST_SCOPE_EXIT_END_ID(BOOST_PP_CAT(dec, __LINE__))
25 #define SCOPE_EXIT_INC_DEC_TPL(variable, offset) \
26 BOOST_SCOPE_EXIT_ID_TPL(BOOST_PP_CAT(inc, __LINE__), \
27 (&variable) (offset) ) { \
29 } BOOST_SCOPE_EXIT_END_ID(BOOST_PP_CAT(inc, __LINE__)) \
31 BOOST_SCOPE_EXIT_ID_TPL(BOOST_PP_CAT(dec, __LINE__), \
32 (&variable) (offset) ) { \
34 } BOOST_SCOPE_EXIT_END_ID(BOOST_PP_CAT(dec, __LINE__))
36 #define SCOPE_EXIT_ALL_INC_DEC(variable, offset) \
37 BOOST_SCOPE_EXIT_ALL_ID(BOOST_PP_CAT(inc, __LINE__), \
41 BOOST_SCOPE_EXIT_ALL_ID(BOOST_PP_CAT(dec, __LINE__), \
47 void f(T& x, T& delta) {
48 SCOPE_EXIT_INC_DEC_TPL(x, delta)
53 int x = 0, delta = 10;
56 SCOPE_EXIT_INC_DEC(x, delta)
62 #ifndef BOOST_NO_CXX11_LAMBDAS
64 SCOPE_EXIT_ALL_INC_DEC(x, delta)
69 return boost::report_errors();