]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/local_function/example/scope_exit.hpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / local_function / example / scope_exit.hpp
1
2 // Copyright (C) 2009-2012 Lorenzo Caminiti
3 // Distributed under the Boost Software License, Version 1.0
4 // (see accompanying file LICENSE_1_0.txt or a copy at
5 // http://www.boost.org/LICENSE_1_0.txt)
6 // Home at http://www.boost.org/libs/local_function
7
8 #ifndef SCOPE_EXIT_HPP_
9 #define SCOPE_EXIT_HPP_
10
11 #include <boost/local_function.hpp>
12 #include <boost/local_function/detail/preprocessor/line_counter.hpp>
13 #include <boost/function.hpp>
14 #include <boost/preprocessor/cat.hpp>
15 #include <boost/config.hpp>
16
17 //[scope_exit_class
18 struct scope_exit {
19 scope_exit(boost::function<void (void)> f): f_(f) {}
20 ~scope_exit(void) { f_(); }
21 private:
22 boost::function<void (void)> f_;
23 };
24 //]
25
26 // PRIVATE //
27
28 //[scope_exit_end_macro
29 #define SCOPE_EXIT_END_(id) \
30 BOOST_LOCAL_FUNCTION_NAME(BOOST_PP_CAT(scope_exit_func_, id)) \
31 scope_exit BOOST_PP_CAT(scope_exit_, id)( \
32 BOOST_PP_CAT(scope_exit_func_, id));
33 //]
34
35 // PUBLIC //
36
37 #ifdef BOOST_NO_CXX11_VARIADIC_MACROS
38 # define SCOPE_EXIT(void_or_seq) \
39 void BOOST_LOCAL_FUNCTION(void_or_seq)
40 #else
41 //[scope_exit_macro
42 # define SCOPE_EXIT(...) \
43 void BOOST_LOCAL_FUNCTION(__VA_ARGS__)
44 //]
45 #endif
46
47 #define SCOPE_EXIT_END \
48 SCOPE_EXIT_END_(BOOST_LOCAL_FUNCTION_DETAIL_PP_LINE_COUNTER)
49
50 #endif // #include guard
51