const_block.hpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // Copyright (C) 2009-2012 Lorenzo Caminiti
  2. // Distributed under the Boost Software License, Version 1.0
  3. // (see accompanying file LICENSE_1_0.txt or a copy at
  4. // http://www.boost.org/LICENSE_1_0.txt)
  5. // Home at http://www.boost.org/libs/local_function
  6. #ifndef CONST_BLOCK_HPP_
  7. #define CONST_BLOCK_HPP_
  8. #include <boost/local_function.hpp>
  9. #include <boost/local_function/detail/preprocessor/void_list.hpp>
  10. #include <boost/local_function/detail/preprocessor/line_counter.hpp>
  11. #include <boost/preprocessor/list/for_each_i.hpp>
  12. #include <boost/preprocessor/list/adt.hpp>
  13. #include <boost/preprocessor/tuple/eat.hpp>
  14. #include <boost/preprocessor/punctuation/comma_if.hpp>
  15. #include <boost/preprocessor/control/iif.hpp>
  16. #include <boost/preprocessor/cat.hpp>
  17. // PRIVATE //
  18. #define CONST_BLOCK_BIND_(r, unused, i, var) \
  19. BOOST_PP_COMMA_IF(i) const bind& var
  20. //[const_block_macro
  21. #define CONST_BLOCK_(variables) \
  22. void BOOST_LOCAL_FUNCTION( \
  23. BOOST_PP_IIF(BOOST_PP_LIST_IS_NIL(variables), \
  24. void BOOST_PP_TUPLE_EAT(3) \
  25. , \
  26. BOOST_PP_LIST_FOR_EACH_I \
  27. )(CONST_BLOCK_BIND_, ~, variables) \
  28. )
  29. //]
  30. //[const_block_end_macro
  31. #define CONST_BLOCK_END_(id) \
  32. BOOST_LOCAL_FUNCTION_NAME(BOOST_PP_CAT(const_block_, id)) \
  33. BOOST_PP_CAT(const_block_, id)(); /* call local function immediately */
  34. //]
  35. // PUBLIC //
  36. // Arguments `void | var1, var2, ... | (var1) (var2) ...`.
  37. #ifdef BOOST_NO_CXX11_VARIADIC_MACROS
  38. # define CONST_BLOCK(void_or_seq) \
  39. CONST_BLOCK_(BOOST_LOCAL_FUNCTION_DETAIL_PP_VOID_LIST(void_or_seq))
  40. #else
  41. # define CONST_BLOCK(...) \
  42. CONST_BLOCK_(BOOST_LOCAL_FUNCTION_DETAIL_PP_VOID_LIST(__VA_ARGS__))
  43. #endif
  44. #define CONST_BLOCK_END \
  45. CONST_BLOCK_END_(BOOST_LOCAL_FUNCTION_DETAIL_PP_LINE_COUNTER)
  46. #endif // #include guard