1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
|
// Copyright Alexander Nasonov 2006-2009
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#ifndef FILE_boost_scope_exit_hpp_INCLUDED
#define FILE_boost_scope_exit_hpp_INCLUDED
#include <boost/config.hpp>
#include <boost/detail/workaround.hpp>
#include <boost/preprocessor/cat.hpp>
#include <boost/preprocessor/facilities/empty.hpp>
#include <boost/preprocessor/punctuation/comma_if.hpp>
#include <boost/preprocessor/seq/cat.hpp>
#include <boost/preprocessor/seq/for_each_i.hpp>
#include <boost/preprocessor/tuple/elem.hpp>
#include <boost/typeof/typeof.hpp>
#if defined(__GNUC__) && !defined(BOOST_INTEL)
# define BOOST_SCOPE_EXIT_AUX_GCC (__GNUC__ * 100 + __GNUC_MINOR__)
#else
# define BOOST_SCOPE_EXIT_AUX_GCC 0
#endif
#if BOOST_WORKAROUND(BOOST_SCOPE_EXIT_AUX_GCC, BOOST_TESTED_AT(413))
#define BOOST_SCOPE_EXIT_AUX_TPL_WORKAROUND
#endif
// Steven Watanabe's trick
namespace boost { namespace scope_exit { namespace aux {
template<int> struct declare;
typedef void* declared;
struct undeclared { declared dummy[2]; };
template<>
struct declare<sizeof(undeclared)>
{
template<int>
struct apply
{
declared value;
friend void operator>(bool, const apply&) {}
};
};
template<>
struct declare<sizeof(declared)>
{
static const int apply = 0;
};
} } }
extern boost::scope_exit::aux::undeclared boost_scope_exit_args; // undefined
namespace boost { namespace scope_exit { namespace aux {
typedef void (*ref_tag)(int&);
typedef void (*val_tag)(int );
template<class T, class Tag> struct member;
template<class T>
struct member<T,ref_tag>
{
T& value;
#ifndef BOOST_SCOPE_EXIT_AUX_TPL_WORKAROUND
member(T& ref) : value(ref) {}
#endif
};
template<class T>
struct member<T,val_tag>
{
T value;
#ifndef BOOST_SCOPE_EXIT_AUX_TPL_WORKAROUND
member(T& val) : value(val) {}
#endif
};
template<class T> inline T& deref(T* p, ref_tag) { return *p; }
template<class T> inline T& deref(T& r, val_tag) { return r; }
template<class T>
struct wrapper
{
typedef T type;
};
template<class T> wrapper<T> wrap(T&);
} } }
#include BOOST_TYPEOF_INCREMENT_REGISTRATION_GROUP()
BOOST_TYPEOF_REGISTER_TEMPLATE(boost::scope_exit::aux::wrapper, 1)
#define BOOST_SCOPE_EXIT_AUX_GUARD(id) BOOST_PP_CAT(boost_se_guard_, id)
#define BOOST_SCOPE_EXIT_AUX_GUARD_T(id) BOOST_PP_CAT(boost_se_guard_t_, id)
#define BOOST_SCOPE_EXIT_AUX_PARAMS(id) BOOST_PP_CAT(boost_se_params_, id)
#define BOOST_SCOPE_EXIT_AUX_PARAMS_T(id) BOOST_PP_CAT(boost_se_params_t_, id)
#define BOOST_SCOPE_EXIT_AUX_TAG(id, i) \
BOOST_PP_SEQ_CAT( (boost_se_tag_)(i)(_)(id) )
#define BOOST_SCOPE_EXIT_AUX_PARAM(id, i, var) \
BOOST_PP_SEQ_CAT( (boost_se_param_)(i)(_)(id) )
#define BOOST_SCOPE_EXIT_AUX_PARAM_T(id, i, var) \
BOOST_PP_SEQ_CAT( (boost_se_param_t_)(i)(_)(id) )
#define BOOST_SCOPE_EXIT_AUX_CAPTURE_T(id, i, var) \
BOOST_PP_SEQ_CAT( (boost_se_capture_t_)(i)(_)(id) )
#define BOOST_SCOPE_EXIT_AUX_WRAPPED(id, i) \
BOOST_PP_SEQ_CAT( (boost_se_wrapped_t_)(i)(_)(id) )
#define BOOST_SCOPE_EXIT_AUX_DEREF(id, i, var) \
boost::scope_exit::aux::deref(var, (BOOST_SCOPE_EXIT_AUX_TAG(id,i))0)
#define BOOST_SCOPE_EXIT_AUX_MEMBER(r, id, i, var) \
boost::scope_exit::aux::member< \
BOOST_SCOPE_EXIT_AUX_PARAM_T(id,i,var), \
BOOST_SCOPE_EXIT_AUX_TAG(id,i) \
> BOOST_SCOPE_EXIT_AUX_PARAM(id,i,var);
// idty is (id,typename) or (id,BOOST_PP_EMPTY())
#define BOOST_SCOPE_EXIT_AUX_ARG_DECL(r, idty, i, var) \
BOOST_PP_COMMA_IF(i) BOOST_PP_TUPLE_ELEM(2,1,idty) \
BOOST_SCOPE_EXIT_AUX_PARAMS_T(BOOST_PP_TUPLE_ELEM(2,0,idty)):: \
BOOST_SCOPE_EXIT_AUX_PARAM_T(BOOST_PP_TUPLE_ELEM(2,0,idty), i, var) var
#define BOOST_SCOPE_EXIT_AUX_ARG(r, id, i, var) BOOST_PP_COMMA_IF(i) \
boost_se_params_->BOOST_SCOPE_EXIT_AUX_PARAM(id,i,var).value
#define BOOST_SCOPE_EXIT_AUX_TAG_DECL(r, id, i, var) \
typedef void (*BOOST_SCOPE_EXIT_AUX_TAG(id,i))(int var);
#ifdef BOOST_SCOPE_EXIT_AUX_TPL_WORKAROUND
#define BOOST_SCOPE_EXIT_AUX_PARAMS_T_CTOR(id, seq)
#define BOOST_SCOPE_EXIT_AUX_PARAM_INIT(r, id, i, var) \
BOOST_PP_COMMA_IF(i) { BOOST_SCOPE_EXIT_AUX_DEREF(id,i,var) }
#define BOOST_SCOPE_EXIT_AUX_PARAMS_INIT(id, seq) \
= { BOOST_PP_SEQ_FOR_EACH_I(BOOST_SCOPE_EXIT_AUX_PARAM_INIT, id, seq) };
#else
#define BOOST_SCOPE_EXIT_AUX_CTOR_ARG(r, id, i, var) BOOST_PP_COMMA_IF(i) \
BOOST_SCOPE_EXIT_AUX_PARAM_T(id,i,var) & BOOST_PP_CAT(a,i)
#define BOOST_SCOPE_EXIT_AUX_MEMBER_INIT(r, id, i, var) BOOST_PP_COMMA_IF(i) \
BOOST_SCOPE_EXIT_AUX_PARAM(id,i,var) ( BOOST_PP_CAT(a,i) )
#define BOOST_SCOPE_EXIT_AUX_PARAMS_T_CTOR(id, seq) \
BOOST_SCOPE_EXIT_AUX_PARAMS_T(id)( \
BOOST_PP_SEQ_FOR_EACH_I(BOOST_SCOPE_EXIT_AUX_CTOR_ARG, id, seq ) ) \
: BOOST_PP_SEQ_FOR_EACH_I(BOOST_SCOPE_EXIT_AUX_MEMBER_INIT, id, seq) {}
#define BOOST_SCOPE_EXIT_AUX_PARAM_INIT(r, id, i, var) \
BOOST_PP_COMMA_IF(i) BOOST_SCOPE_EXIT_AUX_DEREF(id,i,var)
#define BOOST_SCOPE_EXIT_AUX_PARAMS_INIT(id, seq) \
( BOOST_PP_SEQ_FOR_EACH_I(BOOST_SCOPE_EXIT_AUX_PARAM_INIT, id, seq) );
#endif
#if defined(BOOST_TYPEOF_EMULATION)
#define BOOST_SCOPE_EXIT_AUX_CAPTURE_DECL(r, idty, i, var) \
struct BOOST_SCOPE_EXIT_AUX_WRAPPED(BOOST_PP_TUPLE_ELEM(2,0,idty), i) \
: BOOST_TYPEOF(boost::scope_exit::aux::wrap( \
BOOST_SCOPE_EXIT_AUX_DEREF(BOOST_PP_TUPLE_ELEM(2,0,idty), i, var))) \
{}; typedef BOOST_PP_TUPLE_ELEM(2,1,idty) \
BOOST_SCOPE_EXIT_AUX_WRAPPED(BOOST_PP_TUPLE_ELEM(2,0,idty), i)::type \
BOOST_SCOPE_EXIT_AUX_CAPTURE_T(BOOST_PP_TUPLE_ELEM(2,0,idty), i, var);
#elif defined(BOOST_INTEL)
#define BOOST_SCOPE_EXIT_AUX_CAPTURE_DECL(r, idty, i, var) \
typedef BOOST_TYPEOF_KEYWORD( \
BOOST_SCOPE_EXIT_AUX_DEREF(BOOST_PP_TUPLE_ELEM(2,0,idty), i, var)) \
BOOST_SCOPE_EXIT_AUX_CAPTURE_T(BOOST_PP_TUPLE_ELEM(2,0,idty), i, var);
#else
#define BOOST_SCOPE_EXIT_AUX_CAPTURE_DECL(r, idty, i, var) \
typedef BOOST_TYPEOF(boost::scope_exit::aux::wrap( \
BOOST_SCOPE_EXIT_AUX_DEREF(BOOST_PP_TUPLE_ELEM(2,0,idty), i, var))) \
BOOST_SCOPE_EXIT_AUX_WRAPPED(BOOST_PP_TUPLE_ELEM(2,0,idty), i); \
typedef BOOST_PP_TUPLE_ELEM(2,1,idty) \
BOOST_SCOPE_EXIT_AUX_WRAPPED(BOOST_PP_TUPLE_ELEM(2,0,idty), i)::type \
BOOST_SCOPE_EXIT_AUX_CAPTURE_T(BOOST_PP_TUPLE_ELEM(2,0,idty), i, var);
#endif
#define BOOST_SCOPE_EXIT_AUX_PARAM_DECL(r, idty, i, var) \
typedef BOOST_SCOPE_EXIT_AUX_CAPTURE_T( \
BOOST_PP_TUPLE_ELEM(2,0,idty), i, var) \
BOOST_SCOPE_EXIT_AUX_PARAM_T(BOOST_PP_TUPLE_ELEM(2,0,idty), i, var);
#define BOOST_SCOPE_EXIT_AUX_IMPL(id, seq, ty) \
BOOST_PP_SEQ_FOR_EACH_I(BOOST_SCOPE_EXIT_AUX_TAG_DECL, id, seq) \
BOOST_PP_SEQ_FOR_EACH_I(BOOST_SCOPE_EXIT_AUX_CAPTURE_DECL, (id,ty), seq) \
struct BOOST_SCOPE_EXIT_AUX_PARAMS_T(id) { \
BOOST_PP_SEQ_FOR_EACH_I(BOOST_SCOPE_EXIT_AUX_PARAM_DECL, (id,ty), seq)\
BOOST_PP_SEQ_FOR_EACH_I(BOOST_SCOPE_EXIT_AUX_MEMBER, id, seq) \
BOOST_SCOPE_EXIT_AUX_PARAMS_T_CTOR(id, seq) \
} BOOST_SCOPE_EXIT_AUX_PARAMS(id) BOOST_SCOPE_EXIT_AUX_PARAMS_INIT(id, seq)\
boost::scope_exit::aux::declare<sizeof(boost_scope_exit_args)> \
::apply<0> boost_scope_exit_args; \
boost_scope_exit_args.value = &BOOST_SCOPE_EXIT_AUX_PARAMS(id); \
struct BOOST_SCOPE_EXIT_AUX_GUARD_T(id) { \
BOOST_SCOPE_EXIT_AUX_PARAMS_T(id)* boost_se_params_; \
BOOST_SCOPE_EXIT_AUX_GUARD_T(id) (void* boost_se_params) \
: boost_se_params_( \
(BOOST_SCOPE_EXIT_AUX_PARAMS_T(id)*)boost_se_params) \
{} \
~BOOST_SCOPE_EXIT_AUX_GUARD_T(id)() { boost_se_body( \
BOOST_PP_SEQ_FOR_EACH_I(BOOST_SCOPE_EXIT_AUX_ARG, id, seq) ); } \
static void boost_se_body(BOOST_PP_SEQ_FOR_EACH_I( \
BOOST_SCOPE_EXIT_AUX_ARG_DECL, (id,ty), seq) )
#if defined(BOOST_MSVC)
#define BOOST_SCOPE_EXIT_END } BOOST_SCOPE_EXIT_AUX_GUARD(__COUNTER__) ( \
boost_scope_exit_args.value);
#define BOOST_SCOPE_EXIT(seq) \
BOOST_SCOPE_EXIT_AUX_IMPL(__COUNTER__, seq, BOOST_PP_EMPTY())
#else
#define BOOST_SCOPE_EXIT_END } BOOST_SCOPE_EXIT_AUX_GUARD(__LINE__) ( \
boost_scope_exit_args.value);
#define BOOST_SCOPE_EXIT(seq) \
BOOST_SCOPE_EXIT_AUX_IMPL(__LINE__, seq, BOOST_PP_EMPTY())
#endif
#ifdef BOOST_SCOPE_EXIT_AUX_TPL_WORKAROUND
#define BOOST_SCOPE_EXIT_TPL(seq) \
BOOST_SCOPE_EXIT_AUX_IMPL(__LINE__, seq, typename)
#else
#define BOOST_SCOPE_EXIT_TPL(seq) BOOST_SCOPE_EXIT(seq)
#endif
#endif // #ifndef FILE_boost_scope_exit_hpp_INCLUDED
|