Attempt to represent the S^2->S^3 header reorganisation as a series of "hg rename" operations
1 /* Copyright 2003-2005 Joaquín M López Muñoz.
2 * Distributed under the Boost Software License, Version 1.0.
3 * (See accompanying file LICENSE_1_0.txt or copy at
4 * http://www.boost.org/LICENSE_1_0.txt)
6 * See http://www.boost.org/libs/multi_index for library home page.
9 #ifndef BOOST_MULTI_INDEX_DETAIL_SCOPE_GUARD_HPP
10 #define BOOST_MULTI_INDEX_DETAIL_SCOPE_GUARD_HPP
12 #if defined(_MSC_VER)&&(_MSC_VER>=1200)
18 namespace multi_index{
22 /* Until some official version of the ScopeGuard idiom makes it into Boost,
23 * we locally define our own. This is a merely reformated version of
24 * ScopeGuard.h as defined in:
25 * Alexandrescu, A., Marginean, P.:"Generic<Programming>: Change the Way You
26 * Write Exception-Safe Code - Forever", C/C++ Users Jornal, Dec 2000,
27 * http://www.cuj.com/documents/s=8000/cujcexp1812alexandr/
28 * with the following modifications:
29 * - General pretty formatting (pretty to my taste at least.)
30 * - Naming style changed to standard C++ library requirements.
31 * - safe_execute does not feature a try-catch protection, so we can
32 * use this even if BOOST_NO_EXCEPTIONS is defined.
33 * - Added scope_guard_impl4 and obj_scope_guard_impl3, (Boost.MultiIndex
34 * needs them). A better design would provide guards for many more
35 * arguments through the Boost Preprocessor Library.
36 * - Added scope_guard_impl_base::touch (see below.)
37 * - Removed RefHolder and ByRef, whose functionality is provided
38 * already by Boost.Ref.
39 * - Removed static make_guard's and make_obj_guard's, so that the code
40 * will work even if BOOST_NO_MEMBER_TEMPLATES is defined. This forces
41 * us to move some private ctors to public, though.
43 * NB: CodeWarrior Pro 8 seems to have problems looking up safe_execute
44 * without an explicit qualification.
47 class scope_guard_impl_base
50 scope_guard_impl_base():dismissed_(false){}
51 void dismiss()const{dismissed_=true;}
53 /* This helps prevent some "unused variable" warnings under, for instance,
59 ~scope_guard_impl_base(){}
61 scope_guard_impl_base(const scope_guard_impl_base& other):
62 dismissed_(other.dismissed_)
68 static void safe_execute(J& j){if(!j.dismissed_)j.execute();}
70 mutable bool dismissed_;
73 scope_guard_impl_base& operator=(const scope_guard_impl_base&);
76 typedef const scope_guard_impl_base& scope_guard;
79 class scope_guard_impl0:public scope_guard_impl_base
82 scope_guard_impl0(F fun):fun_(fun){}
83 ~scope_guard_impl0(){scope_guard_impl_base::safe_execute(*this);}
84 void execute(){fun_();}
92 inline scope_guard_impl0<F> make_guard(F fun)
94 return scope_guard_impl0<F>(fun);
97 template<typename F,typename P1>
98 class scope_guard_impl1:public scope_guard_impl_base
101 scope_guard_impl1(F fun,P1 p1):fun_(fun),p1_(p1){}
102 ~scope_guard_impl1(){scope_guard_impl_base::safe_execute(*this);}
103 void execute(){fun_(p1_);}
110 template<typename F,typename P1>
111 inline scope_guard_impl1<F,P1> make_guard(F fun,P1 p1)
113 return scope_guard_impl1<F,P1>(fun,p1);
116 template<typename F,typename P1,typename P2>
117 class scope_guard_impl2:public scope_guard_impl_base
120 scope_guard_impl2(F fun,P1 p1,P2 p2):fun_(fun),p1_(p1),p2_(p2){}
121 ~scope_guard_impl2(){scope_guard_impl_base::safe_execute(*this);}
122 void execute(){fun_(p1_,p2_);}
130 template<typename F,typename P1,typename P2>
131 inline scope_guard_impl2<F,P1,P2> make_guard(F fun,P1 p1,P2 p2)
133 return scope_guard_impl2<F,P1,P2>(fun,p1,p2);
136 template<typename F,typename P1,typename P2,typename P3>
137 class scope_guard_impl3:public scope_guard_impl_base
140 scope_guard_impl3(F fun,P1 p1,P2 p2,P3 p3):fun_(fun),p1_(p1),p2_(p2),p3_(p3){}
141 ~scope_guard_impl3(){scope_guard_impl_base::safe_execute(*this);}
142 void execute(){fun_(p1_,p2_,p3_);}
151 template<typename F,typename P1,typename P2,typename P3>
152 inline scope_guard_impl3<F,P1,P2,P3> make_guard(F fun,P1 p1,P2 p2,P3 p3)
154 return scope_guard_impl3<F,P1,P2,P3>(fun,p1,p2,p3);
157 template<typename F,typename P1,typename P2,typename P3,typename P4>
158 class scope_guard_impl4:public scope_guard_impl_base
161 scope_guard_impl4(F fun,P1 p1,P2 p2,P3 p3,P4 p4):
162 fun_(fun),p1_(p1),p2_(p2),p3_(p3),p4_(p4){}
163 ~scope_guard_impl4(){scope_guard_impl_base::safe_execute(*this);}
164 void execute(){fun_(p1_,p2_,p3_,p4_);}
174 template<typename F,typename P1,typename P2,typename P3,typename P4>
175 inline scope_guard_impl4<F,P1,P2,P3,P4> make_guard(
176 F fun,P1 p1,P2 p2,P3 p3,P4 p4)
178 return scope_guard_impl4<F,P1,P2,P3,P4>(fun,p1,p2,p3,p4);
181 template<class Obj,typename MemFun>
182 class obj_scope_guard_impl0:public scope_guard_impl_base
185 obj_scope_guard_impl0(Obj& obj,MemFun mem_fun):obj_(obj),mem_fun_(mem_fun){}
186 ~obj_scope_guard_impl0(){scope_guard_impl_base::safe_execute(*this);}
187 void execute(){(obj_.*mem_fun_)();}
194 template<class Obj,typename MemFun>
195 inline obj_scope_guard_impl0<Obj,MemFun> make_obj_guard(Obj& obj,MemFun mem_fun)
197 return obj_scope_guard_impl0<Obj,MemFun>(obj,mem_fun);
200 template<class Obj,typename MemFun,typename P1>
201 class obj_scope_guard_impl1:public scope_guard_impl_base
204 obj_scope_guard_impl1(Obj& obj,MemFun mem_fun,P1 p1):
205 obj_(obj),mem_fun_(mem_fun),p1_(p1){}
206 ~obj_scope_guard_impl1(){scope_guard_impl_base::safe_execute(*this);}
207 void execute(){(obj_.*mem_fun_)(p1_);}
215 template<class Obj,typename MemFun,typename P1>
216 inline obj_scope_guard_impl1<Obj,MemFun,P1> make_obj_guard(
217 Obj& obj,MemFun mem_fun,P1 p1)
219 return obj_scope_guard_impl1<Obj,MemFun,P1>(obj,mem_fun,p1);
222 template<class Obj,typename MemFun,typename P1,typename P2>
223 class obj_scope_guard_impl2:public scope_guard_impl_base
226 obj_scope_guard_impl2(Obj& obj,MemFun mem_fun,P1 p1,P2 p2):
227 obj_(obj),mem_fun_(mem_fun),p1_(p1),p2_(p2)
229 ~obj_scope_guard_impl2(){scope_guard_impl_base::safe_execute(*this);}
230 void execute(){(obj_.*mem_fun_)(p1_,p2_);}
239 template<class Obj,typename MemFun,typename P1,typename P2>
240 inline obj_scope_guard_impl2<Obj,MemFun,P1,P2>
241 make_obj_guard(Obj& obj,MemFun mem_fun,P1 p1,P2 p2)
243 return obj_scope_guard_impl2<Obj,MemFun,P1,P2>(obj,mem_fun,p1,p2);
246 template<class Obj,typename MemFun,typename P1,typename P2,typename P3>
247 class obj_scope_guard_impl3:public scope_guard_impl_base
250 obj_scope_guard_impl3(Obj& obj,MemFun mem_fun,P1 p1,P2 p2,P3 p3):
251 obj_(obj),mem_fun_(mem_fun),p1_(p1),p2_(p2),p3_(p3)
253 ~obj_scope_guard_impl3(){scope_guard_impl_base::safe_execute(*this);}
254 void execute(){(obj_.*mem_fun_)(p1_,p2_,p3_);}
264 template<class Obj,typename MemFun,typename P1,typename P2,typename P3>
265 inline obj_scope_guard_impl3<Obj,MemFun,P1,P2,P3>
266 make_obj_guard(Obj& obj,MemFun mem_fun,P1 p1,P2 p2,P3 p3)
268 return obj_scope_guard_impl3<Obj,MemFun,P1,P2,P3>(obj,mem_fun,p1,p2,p3);
271 } /* namespace multi_index::detail */
273 } /* namespace multi_index */
275 } /* namespace boost */