decl.hpp 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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 BOOST_LOCAL_FUNCTION_AUX_DECL_HPP_
  7. #define BOOST_LOCAL_FUNCTION_AUX_DECL_HPP_
  8. #include <boost/local_function/aux_/macro/code_/result.hpp>
  9. #include <boost/local_function/aux_/macro/code_/bind.hpp>
  10. #include <boost/local_function/aux_/macro/code_/functor.hpp>
  11. #include <boost/local_function/aux_/preprocessor/traits/decl.hpp>
  12. #include <boost/local_function/aux_/preprocessor/traits/decl_error.hpp>
  13. #include <boost/scope_exit.hpp>
  14. #include <boost/mpl/assert.hpp>
  15. #include <boost/preprocessor/control/iif.hpp>
  16. #include <boost/preprocessor/facilities/is_empty.hpp>
  17. #include <boost/preprocessor/list/adt.hpp>
  18. #include <boost/preprocessor/tuple/eat.hpp>
  19. // PRIVATE //
  20. #define BOOST_LOCAL_FUNCTION_AUX_DECL_OK_(id, typename01, decl_traits) \
  21. BOOST_LOCAL_FUNCTION_AUX_CODE_RESULT(id, typename01, decl_traits) \
  22. BOOST_LOCAL_FUNCTION_AUX_CODE_BIND(id, typename01, decl_traits) \
  23. BOOST_LOCAL_FUNCTION_AUX_CODE_FUNCTOR(id, typename01, decl_traits)
  24. #define BOOST_LOCAL_FUNCTION_AUX_DECL_ERROR_(id, typename01, decl_traits) \
  25. BOOST_PP_IIF(BOOST_PP_LIST_IS_CONS( \
  26. BOOST_LOCAL_FUNCTION_AUX_PP_DECL_TRAITS_RETURNS(decl_traits)), \
  27. /* return specified, so no result type before this macro expansion */ \
  28. BOOST_PP_TUPLE_EAT(1) \
  29. , \
  30. /* even if error, must declare result type to prevent additional */ \
  31. /* error due to result type appearing before this macro expansion */ \
  32. BOOST_LOCAL_FUNCTION_AUX_CODE_RESULT_DECL \
  33. )(id) \
  34. ; /* close eventual previous statements, otherwise it has no effect */ \
  35. BOOST_MPL_ASSERT_MSG(false, /* always fails (there's an error) */ \
  36. BOOST_LOCAL_FUNCTION_AUX_PP_DECL_TRAITS_ERROR_MSG(decl_traits), ())\
  37. ; /* must close ASSERT macro for eventual use within class scope */
  38. // PUBLIC //
  39. #define BOOST_LOCAL_FUNCTION_AUX_DECL_ARGS_VAR \
  40. BOOST_LOCAL_FUNCTION_AUX_SYMBOL( (args) )
  41. // Undefine local function bound args global variable. Actual declaration of
  42. // this variable is made using SFINAE mechanisms by each local function macro.
  43. extern boost::scope_exit::detail::undeclared
  44. BOOST_LOCAL_FUNCTION_AUX_DECL_ARGS_VAR;
  45. // sign_params: parsed parenthesized params.
  46. #define BOOST_LOCAL_FUNCTION_AUX_DECL(id, typename01, decl_traits) \
  47. BOOST_PP_IIF(BOOST_PP_IS_EMPTY( \
  48. BOOST_LOCAL_FUNCTION_AUX_PP_DECL_TRAITS_ERROR_MSG(decl_traits)), \
  49. BOOST_LOCAL_FUNCTION_AUX_DECL_OK_ \
  50. , \
  51. BOOST_LOCAL_FUNCTION_AUX_DECL_ERROR_ \
  52. )(id, typename01, decl_traits)
  53. #endif // #include guard