Chris@16
|
1 /* Copyright 2003-2013 Joaquin M Lopez Munoz.
|
Chris@16
|
2 * Distributed under the Boost Software License, Version 1.0.
|
Chris@16
|
3 * (See accompanying file LICENSE_1_0.txt or copy at
|
Chris@16
|
4 * http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
5 *
|
Chris@16
|
6 * See http://www.boost.org/libs/multi_index for library home page.
|
Chris@16
|
7 */
|
Chris@16
|
8
|
Chris@16
|
9 #ifndef BOOST_MULTI_INDEX_DETAIL_SCOPE_GUARD_HPP
|
Chris@16
|
10 #define BOOST_MULTI_INDEX_DETAIL_SCOPE_GUARD_HPP
|
Chris@16
|
11
|
Chris@101
|
12 #if defined(_MSC_VER)
|
Chris@16
|
13 #pragma once
|
Chris@16
|
14 #endif
|
Chris@16
|
15
|
Chris@16
|
16 #include <boost/detail/no_exceptions_support.hpp>
|
Chris@16
|
17 #include <boost/mpl/if.hpp>
|
Chris@16
|
18
|
Chris@16
|
19 namespace boost{
|
Chris@16
|
20
|
Chris@16
|
21 namespace multi_index{
|
Chris@16
|
22
|
Chris@16
|
23 namespace detail{
|
Chris@16
|
24
|
Chris@16
|
25 /* Until some official version of the ScopeGuard idiom makes it into Boost,
|
Chris@16
|
26 * we locally define our own. This is a merely reformated version of
|
Chris@16
|
27 * ScopeGuard.h as defined in:
|
Chris@16
|
28 * Alexandrescu, A., Marginean, P.:"Generic<Programming>: Change the Way You
|
Chris@16
|
29 * Write Exception-Safe Code - Forever", C/C++ Users Jornal, Dec 2000,
|
Chris@16
|
30 * http://www.drdobbs.com/184403758
|
Chris@16
|
31 * with the following modifications:
|
Chris@16
|
32 * - General pretty formatting (pretty to my taste at least.)
|
Chris@16
|
33 * - Naming style changed to standard C++ library requirements.
|
Chris@16
|
34 * - Added scope_guard_impl4 and obj_scope_guard_impl3, (Boost.MultiIndex
|
Chris@16
|
35 * needs them). A better design would provide guards for many more
|
Chris@16
|
36 * arguments through the Boost Preprocessor Library.
|
Chris@16
|
37 * - Added scope_guard_impl_base::touch (see below.)
|
Chris@16
|
38 * - Removed RefHolder and ByRef, whose functionality is provided
|
Chris@16
|
39 * already by Boost.Ref.
|
Chris@16
|
40 * - Removed static make_guard's and make_obj_guard's, so that the code
|
Chris@16
|
41 * will work even if BOOST_NO_MEMBER_TEMPLATES is defined. This forces
|
Chris@16
|
42 * us to move some private ctors to public, though.
|
Chris@16
|
43 *
|
Chris@16
|
44 * NB: CodeWarrior Pro 8 seems to have problems looking up safe_execute
|
Chris@16
|
45 * without an explicit qualification.
|
Chris@16
|
46 *
|
Chris@16
|
47 * We also define the following variants of the idiom:
|
Chris@16
|
48 *
|
Chris@16
|
49 * - make_guard_if_c<bool>( ... )
|
Chris@16
|
50 * - make_guard_if<IntegralConstant>( ... )
|
Chris@16
|
51 * - make_obj_guard_if_c<bool>( ... )
|
Chris@16
|
52 * - make_obj_guard_if<IntegralConstant>( ... )
|
Chris@16
|
53 * which may be used with a compile-time constant to yield
|
Chris@16
|
54 * a "null_guard" if the boolean compile-time parameter is false,
|
Chris@16
|
55 * or conversely, the guard is only constructed if the constant is true.
|
Chris@16
|
56 * This is useful to avoid extra tagging, because the returned
|
Chris@16
|
57 * null_guard can be optimzed comlpetely away by the compiler.
|
Chris@16
|
58 */
|
Chris@16
|
59
|
Chris@16
|
60 class scope_guard_impl_base
|
Chris@16
|
61 {
|
Chris@16
|
62 public:
|
Chris@16
|
63 scope_guard_impl_base():dismissed_(false){}
|
Chris@16
|
64 void dismiss()const{dismissed_=true;}
|
Chris@16
|
65
|
Chris@16
|
66 /* This helps prevent some "unused variable" warnings under, for instance,
|
Chris@16
|
67 * GCC 3.2.
|
Chris@16
|
68 */
|
Chris@16
|
69 void touch()const{}
|
Chris@16
|
70
|
Chris@16
|
71 protected:
|
Chris@16
|
72 ~scope_guard_impl_base(){}
|
Chris@16
|
73
|
Chris@16
|
74 scope_guard_impl_base(const scope_guard_impl_base& other):
|
Chris@16
|
75 dismissed_(other.dismissed_)
|
Chris@16
|
76 {
|
Chris@16
|
77 other.dismiss();
|
Chris@16
|
78 }
|
Chris@16
|
79
|
Chris@16
|
80 template<typename J>
|
Chris@16
|
81 static void safe_execute(J& j){
|
Chris@16
|
82 BOOST_TRY{
|
Chris@16
|
83 if(!j.dismissed_)j.execute();
|
Chris@16
|
84 }
|
Chris@16
|
85 BOOST_CATCH(...){}
|
Chris@16
|
86 BOOST_CATCH_END
|
Chris@16
|
87 }
|
Chris@16
|
88
|
Chris@16
|
89 mutable bool dismissed_;
|
Chris@16
|
90
|
Chris@16
|
91 private:
|
Chris@16
|
92 scope_guard_impl_base& operator=(const scope_guard_impl_base&);
|
Chris@16
|
93 };
|
Chris@16
|
94
|
Chris@16
|
95 typedef const scope_guard_impl_base& scope_guard;
|
Chris@16
|
96
|
Chris@16
|
97 struct null_guard : public scope_guard_impl_base
|
Chris@16
|
98 {
|
Chris@16
|
99 template< class T1 >
|
Chris@16
|
100 null_guard( const T1& )
|
Chris@16
|
101 { }
|
Chris@16
|
102
|
Chris@16
|
103 template< class T1, class T2 >
|
Chris@16
|
104 null_guard( const T1&, const T2& )
|
Chris@16
|
105 { }
|
Chris@16
|
106
|
Chris@16
|
107 template< class T1, class T2, class T3 >
|
Chris@16
|
108 null_guard( const T1&, const T2&, const T3& )
|
Chris@16
|
109 { }
|
Chris@16
|
110
|
Chris@16
|
111 template< class T1, class T2, class T3, class T4 >
|
Chris@16
|
112 null_guard( const T1&, const T2&, const T3&, const T4& )
|
Chris@16
|
113 { }
|
Chris@16
|
114
|
Chris@16
|
115 template< class T1, class T2, class T3, class T4, class T5 >
|
Chris@16
|
116 null_guard( const T1&, const T2&, const T3&, const T4&, const T5& )
|
Chris@16
|
117 { }
|
Chris@16
|
118 };
|
Chris@16
|
119
|
Chris@16
|
120 template< bool cond, class T >
|
Chris@16
|
121 struct null_guard_return
|
Chris@16
|
122 {
|
Chris@16
|
123 typedef typename boost::mpl::if_c<cond,T,null_guard>::type type;
|
Chris@16
|
124 };
|
Chris@16
|
125
|
Chris@16
|
126 template<typename F>
|
Chris@16
|
127 class scope_guard_impl0:public scope_guard_impl_base
|
Chris@16
|
128 {
|
Chris@16
|
129 public:
|
Chris@16
|
130 scope_guard_impl0(F fun):fun_(fun){}
|
Chris@16
|
131 ~scope_guard_impl0(){scope_guard_impl_base::safe_execute(*this);}
|
Chris@16
|
132 void execute(){fun_();}
|
Chris@16
|
133
|
Chris@16
|
134 protected:
|
Chris@16
|
135
|
Chris@16
|
136 F fun_;
|
Chris@16
|
137 };
|
Chris@16
|
138
|
Chris@16
|
139 template<typename F>
|
Chris@16
|
140 inline scope_guard_impl0<F> make_guard(F fun)
|
Chris@16
|
141 {
|
Chris@16
|
142 return scope_guard_impl0<F>(fun);
|
Chris@16
|
143 }
|
Chris@16
|
144
|
Chris@16
|
145 template<bool cond, typename F>
|
Chris@16
|
146 inline typename null_guard_return<cond,scope_guard_impl0<F> >::type
|
Chris@16
|
147 make_guard_if_c(F fun)
|
Chris@16
|
148 {
|
Chris@16
|
149 return typename null_guard_return<cond,scope_guard_impl0<F> >::type(fun);
|
Chris@16
|
150 }
|
Chris@16
|
151
|
Chris@16
|
152 template<typename C, typename F>
|
Chris@16
|
153 inline typename null_guard_return<C::value,scope_guard_impl0<F> >::type
|
Chris@16
|
154 make_guard_if(F fun)
|
Chris@16
|
155 {
|
Chris@16
|
156 return make_guard_if<C::value>(fun);
|
Chris@16
|
157 }
|
Chris@16
|
158
|
Chris@16
|
159 template<typename F,typename P1>
|
Chris@16
|
160 class scope_guard_impl1:public scope_guard_impl_base
|
Chris@16
|
161 {
|
Chris@16
|
162 public:
|
Chris@16
|
163 scope_guard_impl1(F fun,P1 p1):fun_(fun),p1_(p1){}
|
Chris@16
|
164 ~scope_guard_impl1(){scope_guard_impl_base::safe_execute(*this);}
|
Chris@16
|
165 void execute(){fun_(p1_);}
|
Chris@16
|
166
|
Chris@16
|
167 protected:
|
Chris@16
|
168 F fun_;
|
Chris@16
|
169 const P1 p1_;
|
Chris@16
|
170 };
|
Chris@16
|
171
|
Chris@16
|
172 template<typename F,typename P1>
|
Chris@16
|
173 inline scope_guard_impl1<F,P1> make_guard(F fun,P1 p1)
|
Chris@16
|
174 {
|
Chris@16
|
175 return scope_guard_impl1<F,P1>(fun,p1);
|
Chris@16
|
176 }
|
Chris@16
|
177
|
Chris@16
|
178 template<bool cond, typename F,typename P1>
|
Chris@16
|
179 inline typename null_guard_return<cond,scope_guard_impl1<F,P1> >::type
|
Chris@16
|
180 make_guard_if_c(F fun,P1 p1)
|
Chris@16
|
181 {
|
Chris@16
|
182 return typename null_guard_return<cond,scope_guard_impl1<F,P1> >::type(fun,p1);
|
Chris@16
|
183 }
|
Chris@16
|
184
|
Chris@16
|
185 template<typename C, typename F,typename P1>
|
Chris@16
|
186 inline typename null_guard_return<C::value,scope_guard_impl1<F,P1> >::type
|
Chris@16
|
187 make_guard_if(F fun,P1 p1)
|
Chris@16
|
188 {
|
Chris@16
|
189 return make_guard_if_c<C::value>(fun,p1);
|
Chris@16
|
190 }
|
Chris@16
|
191
|
Chris@16
|
192 template<typename F,typename P1,typename P2>
|
Chris@16
|
193 class scope_guard_impl2:public scope_guard_impl_base
|
Chris@16
|
194 {
|
Chris@16
|
195 public:
|
Chris@16
|
196 scope_guard_impl2(F fun,P1 p1,P2 p2):fun_(fun),p1_(p1),p2_(p2){}
|
Chris@16
|
197 ~scope_guard_impl2(){scope_guard_impl_base::safe_execute(*this);}
|
Chris@16
|
198 void execute(){fun_(p1_,p2_);}
|
Chris@16
|
199
|
Chris@16
|
200 protected:
|
Chris@16
|
201 F fun_;
|
Chris@16
|
202 const P1 p1_;
|
Chris@16
|
203 const P2 p2_;
|
Chris@16
|
204 };
|
Chris@16
|
205
|
Chris@16
|
206 template<typename F,typename P1,typename P2>
|
Chris@16
|
207 inline scope_guard_impl2<F,P1,P2> make_guard(F fun,P1 p1,P2 p2)
|
Chris@16
|
208 {
|
Chris@16
|
209 return scope_guard_impl2<F,P1,P2>(fun,p1,p2);
|
Chris@16
|
210 }
|
Chris@16
|
211
|
Chris@16
|
212 template<bool cond, typename F,typename P1,typename P2>
|
Chris@16
|
213 inline typename null_guard_return<cond,scope_guard_impl2<F,P1,P2> >::type
|
Chris@16
|
214 make_guard_if_c(F fun,P1 p1,P2 p2)
|
Chris@16
|
215 {
|
Chris@16
|
216 return typename null_guard_return<cond,scope_guard_impl2<F,P1,P2> >::type(fun,p1,p2);
|
Chris@16
|
217 }
|
Chris@16
|
218
|
Chris@16
|
219 template<typename C, typename F,typename P1,typename P2>
|
Chris@16
|
220 inline typename null_guard_return<C::value,scope_guard_impl2<F,P1,P2> >::type
|
Chris@16
|
221 make_guard_if(F fun,P1 p1,P2 p2)
|
Chris@16
|
222 {
|
Chris@16
|
223 return make_guard_if_c<C::value>(fun,p1,p2);
|
Chris@16
|
224 }
|
Chris@16
|
225
|
Chris@16
|
226 template<typename F,typename P1,typename P2,typename P3>
|
Chris@16
|
227 class scope_guard_impl3:public scope_guard_impl_base
|
Chris@16
|
228 {
|
Chris@16
|
229 public:
|
Chris@16
|
230 scope_guard_impl3(F fun,P1 p1,P2 p2,P3 p3):fun_(fun),p1_(p1),p2_(p2),p3_(p3){}
|
Chris@16
|
231 ~scope_guard_impl3(){scope_guard_impl_base::safe_execute(*this);}
|
Chris@16
|
232 void execute(){fun_(p1_,p2_,p3_);}
|
Chris@16
|
233
|
Chris@16
|
234 protected:
|
Chris@16
|
235 F fun_;
|
Chris@16
|
236 const P1 p1_;
|
Chris@16
|
237 const P2 p2_;
|
Chris@16
|
238 const P3 p3_;
|
Chris@16
|
239 };
|
Chris@16
|
240
|
Chris@16
|
241 template<typename F,typename P1,typename P2,typename P3>
|
Chris@16
|
242 inline scope_guard_impl3<F,P1,P2,P3> make_guard(F fun,P1 p1,P2 p2,P3 p3)
|
Chris@16
|
243 {
|
Chris@16
|
244 return scope_guard_impl3<F,P1,P2,P3>(fun,p1,p2,p3);
|
Chris@16
|
245 }
|
Chris@16
|
246
|
Chris@16
|
247 template<bool cond,typename F,typename P1,typename P2,typename P3>
|
Chris@16
|
248 inline typename null_guard_return<cond,scope_guard_impl3<F,P1,P2,P3> >::type
|
Chris@16
|
249 make_guard_if_c(F fun,P1 p1,P2 p2,P3 p3)
|
Chris@16
|
250 {
|
Chris@16
|
251 return typename null_guard_return<cond,scope_guard_impl3<F,P1,P2,P3> >::type(fun,p1,p2,p3);
|
Chris@16
|
252 }
|
Chris@16
|
253
|
Chris@16
|
254 template<typename C,typename F,typename P1,typename P2,typename P3>
|
Chris@16
|
255 inline typename null_guard_return< C::value,scope_guard_impl3<F,P1,P2,P3> >::type
|
Chris@16
|
256 make_guard_if(F fun,P1 p1,P2 p2,P3 p3)
|
Chris@16
|
257 {
|
Chris@16
|
258 return make_guard_if_c<C::value>(fun,p1,p2,p3);
|
Chris@16
|
259 }
|
Chris@16
|
260
|
Chris@16
|
261 template<typename F,typename P1,typename P2,typename P3,typename P4>
|
Chris@16
|
262 class scope_guard_impl4:public scope_guard_impl_base
|
Chris@16
|
263 {
|
Chris@16
|
264 public:
|
Chris@16
|
265 scope_guard_impl4(F fun,P1 p1,P2 p2,P3 p3,P4 p4):
|
Chris@16
|
266 fun_(fun),p1_(p1),p2_(p2),p3_(p3),p4_(p4){}
|
Chris@16
|
267 ~scope_guard_impl4(){scope_guard_impl_base::safe_execute(*this);}
|
Chris@16
|
268 void execute(){fun_(p1_,p2_,p3_,p4_);}
|
Chris@16
|
269
|
Chris@16
|
270 protected:
|
Chris@16
|
271 F fun_;
|
Chris@16
|
272 const P1 p1_;
|
Chris@16
|
273 const P2 p2_;
|
Chris@16
|
274 const P3 p3_;
|
Chris@16
|
275 const P4 p4_;
|
Chris@16
|
276 };
|
Chris@16
|
277
|
Chris@16
|
278 template<typename F,typename P1,typename P2,typename P3,typename P4>
|
Chris@16
|
279 inline scope_guard_impl4<F,P1,P2,P3,P4> make_guard(
|
Chris@16
|
280 F fun,P1 p1,P2 p2,P3 p3,P4 p4)
|
Chris@16
|
281 {
|
Chris@16
|
282 return scope_guard_impl4<F,P1,P2,P3,P4>(fun,p1,p2,p3,p4);
|
Chris@16
|
283 }
|
Chris@16
|
284
|
Chris@16
|
285 template<bool cond, typename F,typename P1,typename P2,typename P3,typename P4>
|
Chris@16
|
286 inline typename null_guard_return<cond,scope_guard_impl4<F,P1,P2,P3,P4> >::type
|
Chris@16
|
287 make_guard_if_c(
|
Chris@16
|
288 F fun,P1 p1,P2 p2,P3 p3,P4 p4)
|
Chris@16
|
289 {
|
Chris@16
|
290 return typename null_guard_return<cond,scope_guard_impl4<F,P1,P2,P3,P4> >::type(fun,p1,p2,p3,p4);
|
Chris@16
|
291 }
|
Chris@16
|
292
|
Chris@16
|
293 template<typename C, typename F,typename P1,typename P2,typename P3,typename P4>
|
Chris@16
|
294 inline typename null_guard_return<C::value,scope_guard_impl4<F,P1,P2,P3,P4> >::type
|
Chris@16
|
295 make_guard_if(
|
Chris@16
|
296 F fun,P1 p1,P2 p2,P3 p3,P4 p4)
|
Chris@16
|
297 {
|
Chris@16
|
298 return make_guard_if_c<C::value>(fun,p1,p2,p3,p4);
|
Chris@16
|
299 }
|
Chris@16
|
300
|
Chris@16
|
301 template<class Obj,typename MemFun>
|
Chris@16
|
302 class obj_scope_guard_impl0:public scope_guard_impl_base
|
Chris@16
|
303 {
|
Chris@16
|
304 public:
|
Chris@16
|
305 obj_scope_guard_impl0(Obj& obj,MemFun mem_fun):obj_(obj),mem_fun_(mem_fun){}
|
Chris@16
|
306 ~obj_scope_guard_impl0(){scope_guard_impl_base::safe_execute(*this);}
|
Chris@16
|
307 void execute(){(obj_.*mem_fun_)();}
|
Chris@16
|
308
|
Chris@16
|
309 protected:
|
Chris@16
|
310 Obj& obj_;
|
Chris@16
|
311 MemFun mem_fun_;
|
Chris@16
|
312 };
|
Chris@16
|
313
|
Chris@16
|
314 template<class Obj,typename MemFun>
|
Chris@16
|
315 inline obj_scope_guard_impl0<Obj,MemFun> make_obj_guard(Obj& obj,MemFun mem_fun)
|
Chris@16
|
316 {
|
Chris@16
|
317 return obj_scope_guard_impl0<Obj,MemFun>(obj,mem_fun);
|
Chris@16
|
318 }
|
Chris@16
|
319
|
Chris@16
|
320 template<bool cond, class Obj,typename MemFun>
|
Chris@16
|
321 inline typename null_guard_return<cond,obj_scope_guard_impl0<Obj,MemFun> >::type
|
Chris@16
|
322 make_obj_guard_if_c(Obj& obj,MemFun mem_fun)
|
Chris@16
|
323 {
|
Chris@16
|
324 return typename null_guard_return<cond,obj_scope_guard_impl0<Obj,MemFun> >::type(obj,mem_fun);
|
Chris@16
|
325 }
|
Chris@16
|
326
|
Chris@16
|
327 template<typename C, class Obj,typename MemFun>
|
Chris@16
|
328 inline typename null_guard_return<C::value,obj_scope_guard_impl0<Obj,MemFun> >::type
|
Chris@16
|
329 make_obj_guard_if(Obj& obj,MemFun mem_fun)
|
Chris@16
|
330 {
|
Chris@16
|
331 return make_obj_guard_if_c<C::value>(obj,mem_fun);
|
Chris@16
|
332 }
|
Chris@16
|
333
|
Chris@16
|
334 template<class Obj,typename MemFun,typename P1>
|
Chris@16
|
335 class obj_scope_guard_impl1:public scope_guard_impl_base
|
Chris@16
|
336 {
|
Chris@16
|
337 public:
|
Chris@16
|
338 obj_scope_guard_impl1(Obj& obj,MemFun mem_fun,P1 p1):
|
Chris@16
|
339 obj_(obj),mem_fun_(mem_fun),p1_(p1){}
|
Chris@16
|
340 ~obj_scope_guard_impl1(){scope_guard_impl_base::safe_execute(*this);}
|
Chris@16
|
341 void execute(){(obj_.*mem_fun_)(p1_);}
|
Chris@16
|
342
|
Chris@16
|
343 protected:
|
Chris@16
|
344 Obj& obj_;
|
Chris@16
|
345 MemFun mem_fun_;
|
Chris@16
|
346 const P1 p1_;
|
Chris@16
|
347 };
|
Chris@16
|
348
|
Chris@16
|
349 template<class Obj,typename MemFun,typename P1>
|
Chris@16
|
350 inline obj_scope_guard_impl1<Obj,MemFun,P1> make_obj_guard(
|
Chris@16
|
351 Obj& obj,MemFun mem_fun,P1 p1)
|
Chris@16
|
352 {
|
Chris@16
|
353 return obj_scope_guard_impl1<Obj,MemFun,P1>(obj,mem_fun,p1);
|
Chris@16
|
354 }
|
Chris@16
|
355
|
Chris@16
|
356 template<bool cond, class Obj,typename MemFun,typename P1>
|
Chris@16
|
357 inline typename null_guard_return<cond,obj_scope_guard_impl1<Obj,MemFun,P1> >::type
|
Chris@16
|
358 make_obj_guard_if_c( Obj& obj,MemFun mem_fun,P1 p1)
|
Chris@16
|
359 {
|
Chris@16
|
360 return typename null_guard_return<cond,obj_scope_guard_impl1<Obj,MemFun,P1> >::type(obj,mem_fun,p1);
|
Chris@16
|
361 }
|
Chris@16
|
362
|
Chris@16
|
363 template<typename C, class Obj,typename MemFun,typename P1>
|
Chris@16
|
364 inline typename null_guard_return<C::value,obj_scope_guard_impl1<Obj,MemFun,P1> >::type
|
Chris@16
|
365 make_obj_guard_if( Obj& obj,MemFun mem_fun,P1 p1)
|
Chris@16
|
366 {
|
Chris@16
|
367 return make_obj_guard_if_c<C::value>(obj,mem_fun,p1);
|
Chris@16
|
368 }
|
Chris@16
|
369
|
Chris@16
|
370 template<class Obj,typename MemFun,typename P1,typename P2>
|
Chris@16
|
371 class obj_scope_guard_impl2:public scope_guard_impl_base
|
Chris@16
|
372 {
|
Chris@16
|
373 public:
|
Chris@16
|
374 obj_scope_guard_impl2(Obj& obj,MemFun mem_fun,P1 p1,P2 p2):
|
Chris@16
|
375 obj_(obj),mem_fun_(mem_fun),p1_(p1),p2_(p2)
|
Chris@16
|
376 {}
|
Chris@16
|
377 ~obj_scope_guard_impl2(){scope_guard_impl_base::safe_execute(*this);}
|
Chris@16
|
378 void execute(){(obj_.*mem_fun_)(p1_,p2_);}
|
Chris@16
|
379
|
Chris@16
|
380 protected:
|
Chris@16
|
381 Obj& obj_;
|
Chris@16
|
382 MemFun mem_fun_;
|
Chris@16
|
383 const P1 p1_;
|
Chris@16
|
384 const P2 p2_;
|
Chris@16
|
385 };
|
Chris@16
|
386
|
Chris@16
|
387 template<class Obj,typename MemFun,typename P1,typename P2>
|
Chris@16
|
388 inline obj_scope_guard_impl2<Obj,MemFun,P1,P2>
|
Chris@16
|
389 make_obj_guard(Obj& obj,MemFun mem_fun,P1 p1,P2 p2)
|
Chris@16
|
390 {
|
Chris@16
|
391 return obj_scope_guard_impl2<Obj,MemFun,P1,P2>(obj,mem_fun,p1,p2);
|
Chris@16
|
392 }
|
Chris@16
|
393
|
Chris@16
|
394 template<bool cond, class Obj,typename MemFun,typename P1,typename P2>
|
Chris@16
|
395 inline typename null_guard_return<cond,obj_scope_guard_impl2<Obj,MemFun,P1,P2> >::type
|
Chris@16
|
396 make_obj_guard_if_c(Obj& obj,MemFun mem_fun,P1 p1,P2 p2)
|
Chris@16
|
397 {
|
Chris@16
|
398 return typename null_guard_return<cond,obj_scope_guard_impl2<Obj,MemFun,P1,P2> >::type(obj,mem_fun,p1,p2);
|
Chris@16
|
399 }
|
Chris@16
|
400
|
Chris@16
|
401 template<typename C, class Obj,typename MemFun,typename P1,typename P2>
|
Chris@16
|
402 inline typename null_guard_return<C::value,obj_scope_guard_impl2<Obj,MemFun,P1,P2> >::type
|
Chris@16
|
403 make_obj_guard_if(Obj& obj,MemFun mem_fun,P1 p1,P2 p2)
|
Chris@16
|
404 {
|
Chris@16
|
405 return make_obj_guard_if_c<C::value>(obj,mem_fun,p1,p2);
|
Chris@16
|
406 }
|
Chris@16
|
407
|
Chris@16
|
408 template<class Obj,typename MemFun,typename P1,typename P2,typename P3>
|
Chris@16
|
409 class obj_scope_guard_impl3:public scope_guard_impl_base
|
Chris@16
|
410 {
|
Chris@16
|
411 public:
|
Chris@16
|
412 obj_scope_guard_impl3(Obj& obj,MemFun mem_fun,P1 p1,P2 p2,P3 p3):
|
Chris@16
|
413 obj_(obj),mem_fun_(mem_fun),p1_(p1),p2_(p2),p3_(p3)
|
Chris@16
|
414 {}
|
Chris@16
|
415 ~obj_scope_guard_impl3(){scope_guard_impl_base::safe_execute(*this);}
|
Chris@16
|
416 void execute(){(obj_.*mem_fun_)(p1_,p2_,p3_);}
|
Chris@16
|
417
|
Chris@16
|
418 protected:
|
Chris@16
|
419 Obj& obj_;
|
Chris@16
|
420 MemFun mem_fun_;
|
Chris@16
|
421 const P1 p1_;
|
Chris@16
|
422 const P2 p2_;
|
Chris@16
|
423 const P3 p3_;
|
Chris@16
|
424 };
|
Chris@16
|
425
|
Chris@16
|
426 template<class Obj,typename MemFun,typename P1,typename P2,typename P3>
|
Chris@16
|
427 inline obj_scope_guard_impl3<Obj,MemFun,P1,P2,P3>
|
Chris@16
|
428 make_obj_guard(Obj& obj,MemFun mem_fun,P1 p1,P2 p2,P3 p3)
|
Chris@16
|
429 {
|
Chris@16
|
430 return obj_scope_guard_impl3<Obj,MemFun,P1,P2,P3>(obj,mem_fun,p1,p2,p3);
|
Chris@16
|
431 }
|
Chris@16
|
432
|
Chris@16
|
433 template<bool cond, class Obj,typename MemFun,typename P1,typename P2,typename P3>
|
Chris@16
|
434 inline typename null_guard_return<cond,obj_scope_guard_impl3<Obj,MemFun,P1,P2,P3> >::type
|
Chris@16
|
435 make_obj_guard_if_c(Obj& obj,MemFun mem_fun,P1 p1,P2 p2,P3 p3)
|
Chris@16
|
436 {
|
Chris@16
|
437 return typename null_guard_return<cond,obj_scope_guard_impl3<Obj,MemFun,P1,P2,P3> >::type(obj,mem_fun,p1,p2,p3);
|
Chris@16
|
438 }
|
Chris@16
|
439
|
Chris@16
|
440 template<typename C, class Obj,typename MemFun,typename P1,typename P2,typename P3>
|
Chris@16
|
441 inline typename null_guard_return<C::value,obj_scope_guard_impl3<Obj,MemFun,P1,P2,P3> >::type
|
Chris@16
|
442 make_obj_guard_if(Obj& obj,MemFun mem_fun,P1 p1,P2 p2,P3 p3)
|
Chris@16
|
443 {
|
Chris@16
|
444 return make_obj_guard_if_c<C::value>(obj,mem_fun,p1,p2,p3);
|
Chris@16
|
445 }
|
Chris@16
|
446
|
Chris@16
|
447 } /* namespace multi_index::detail */
|
Chris@16
|
448
|
Chris@16
|
449 } /* namespace multi_index */
|
Chris@16
|
450
|
Chris@16
|
451 } /* namespace boost */
|
Chris@16
|
452
|
Chris@16
|
453 #endif
|