split_args.hpp 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. // Copyright Daniel Wallin 2006.
  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)
  5. #ifndef BOOST_PARAMETER_AUX_PREPROCESSOR_IMPL_SPLIT_ARGS_HPP
  6. #define BOOST_PARAMETER_AUX_PREPROCESSOR_IMPL_SPLIT_ARGS_HPP
  7. #include <boost/preprocessor/tuple/elem.hpp>
  8. // Accessor macros for the split_args tuple.
  9. #define BOOST_PARAMETER_SPLIT_ARG_REQ_COUNT(x) BOOST_PP_TUPLE_ELEM(4, 0, x)
  10. #define BOOST_PARAMETER_SPLIT_ARG_REQ_SEQ(x) BOOST_PP_TUPLE_ELEM(4, 1, x)
  11. #define BOOST_PARAMETER_SPLIT_ARG_OPT_COUNT(x) BOOST_PP_TUPLE_ELEM(4, 2, x)
  12. #define BOOST_PARAMETER_SPLIT_ARG_OPT_SEQ(x) BOOST_PP_TUPLE_ELEM(4, 3, x)
  13. #include <boost/preprocessor/arithmetic/inc.hpp>
  14. #include <boost/preprocessor/seq/push_back.hpp>
  15. // Helper macros for BOOST_PARAMETER_FUNCTION_SPLIT_ARGS.
  16. #define BOOST_PARAMETER_FUNCTION_SPLIT_ARG_required(s_a, arg) \
  17. ( \
  18. BOOST_PP_INC(BOOST_PARAMETER_SPLIT_ARG_REQ_COUNT(s_a)) \
  19. , BOOST_PP_SEQ_PUSH_BACK(BOOST_PARAMETER_SPLIT_ARG_REQ_SEQ(s_a), arg) \
  20. , BOOST_PARAMETER_SPLIT_ARG_OPT_COUNT(s_a) \
  21. , BOOST_PARAMETER_SPLIT_ARG_OPT_SEQ(s_a) \
  22. )
  23. /**/
  24. #define BOOST_PARAMETER_FUNCTION_SPLIT_ARG_deduced_required(split_args, arg) \
  25. BOOST_PARAMETER_FUNCTION_SPLIT_ARG_required(split_args, arg)
  26. /**/
  27. #define BOOST_PARAMETER_FUNCTION_SPLIT_ARG_optional(s_a, arg) \
  28. ( \
  29. BOOST_PARAMETER_SPLIT_ARG_REQ_COUNT(s_a) \
  30. , BOOST_PARAMETER_SPLIT_ARG_REQ_SEQ(s_a) \
  31. , BOOST_PP_INC(BOOST_PARAMETER_SPLIT_ARG_OPT_COUNT(s_a)) \
  32. , BOOST_PP_SEQ_PUSH_BACK(BOOST_PARAMETER_SPLIT_ARG_OPT_SEQ(s_a), arg) \
  33. )
  34. /**/
  35. #define BOOST_PARAMETER_FUNCTION_SPLIT_ARG_deduced_optional(split_args, arg) \
  36. BOOST_PARAMETER_FUNCTION_SPLIT_ARG_optional(split_args, arg)
  37. /**/
  38. #include <boost/parameter/aux_/preprocessor/impl/argument_specs.hpp>
  39. #include <boost/preprocessor/cat.hpp>
  40. #define BOOST_PARAMETER_FUNCTION_SPLIT_ARG(s, split_args, arg) \
  41. BOOST_PP_CAT( \
  42. BOOST_PARAMETER_FUNCTION_SPLIT_ARG_ \
  43. , BOOST_PARAMETER_FN_ARG_QUALIFIER(arg) \
  44. )(split_args, arg)
  45. /**/
  46. #include <boost/preprocessor/seq/fold_left.hpp>
  47. #include <boost/preprocessor/seq/seq.hpp>
  48. // Expands from the flattened BOOST_PARAMETER_FUNCTION et. al. arg sequence to
  49. // the tuple (required_count, required_args, optional_count, optional_args).
  50. #define BOOST_PARAMETER_FUNCTION_SPLIT_ARGS(args) \
  51. BOOST_PP_SEQ_FOLD_LEFT( \
  52. BOOST_PARAMETER_FUNCTION_SPLIT_ARG \
  53. , (0, BOOST_PP_SEQ_NIL, 0, BOOST_PP_SEQ_NIL) \
  54. , args \
  55. )
  56. /**/
  57. #endif // include guard