• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 CONST_BLOCK_HPP_
9 #define CONST_BLOCK_HPP_
10 
11 #include <boost/local_function.hpp>
12 #include <boost/local_function/detail/preprocessor/void_list.hpp>
13 #include <boost/local_function/detail/preprocessor/line_counter.hpp>
14 #include <boost/preprocessor/list/for_each_i.hpp>
15 #include <boost/preprocessor/list/adt.hpp>
16 #include <boost/preprocessor/tuple/eat.hpp>
17 #include <boost/preprocessor/punctuation/comma_if.hpp>
18 #include <boost/preprocessor/control/iif.hpp>
19 #include <boost/preprocessor/cat.hpp>
20 
21 // PRIVATE //
22 
23 #define CONST_BLOCK_BIND_(r, unused, i, var) \
24     BOOST_PP_COMMA_IF(i) const bind& var
25 
26 //[const_block_macro
27 #define CONST_BLOCK_(variables) \
28     void BOOST_LOCAL_FUNCTION( \
29         BOOST_PP_IIF(BOOST_PP_LIST_IS_NIL(variables), \
30             void BOOST_PP_TUPLE_EAT(3) \
31         , \
32             BOOST_PP_LIST_FOR_EACH_I \
33         )(CONST_BLOCK_BIND_, ~, variables) \
34     )
35 //]
36 
37 //[const_block_end_macro
38 #define CONST_BLOCK_END_(id) \
39     BOOST_LOCAL_FUNCTION_NAME(BOOST_PP_CAT(const_block_, id)) \
40     BOOST_PP_CAT(const_block_, id)(); /* call local function immediately */
41 //]
42 
43 // PUBLIC //
44 
45 // Arguments `void | var1, var2, ... | (var1) (var2) ...`.
46 #ifdef BOOST_NO_CXX11_VARIADIC_MACROS
47 #   define CONST_BLOCK(void_or_seq) \
48         CONST_BLOCK_(BOOST_LOCAL_FUNCTION_DETAIL_PP_VOID_LIST(void_or_seq))
49 #else
50 #   define CONST_BLOCK(...) \
51         CONST_BLOCK_(BOOST_LOCAL_FUNCTION_DETAIL_PP_VOID_LIST(__VA_ARGS__))
52 #endif
53 
54 #define CONST_BLOCK_END \
55     CONST_BLOCK_END_(BOOST_LOCAL_FUNCTION_DETAIL_PP_LINE_COUNTER)
56 
57 #endif // #include guard
58 
59