count_args.hpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. // NO INCLUDE GUARDS, THE HEADER IS INTENDED FOR MULTIPLE INCLUSION
  2. // Copyright Aleksey Gurtovoy 2000-2004
  3. //
  4. // Distributed under the Boost Software License, Version 1.0.
  5. // (See accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt)
  7. //
  8. // See http://www.boost.org/libs/mpl for documentation.
  9. // $Id$
  10. // $Date$
  11. // $Revision$
  12. #include <boost/preprocessor/expr_if.hpp>
  13. #include <boost/preprocessor/inc.hpp>
  14. #include <boost/preprocessor/cat.hpp>
  15. #if !defined(AUX778076_COUNT_ARGS_PARAM_NAME)
  16. # define AUX778076_COUNT_ARGS_PARAM_NAME T
  17. #endif
  18. #if !defined(AUX778076_COUNT_ARGS_TEMPLATE_PARAM)
  19. # define AUX778076_COUNT_ARGS_TEMPLATE_PARAM typename AUX778076_COUNT_ARGS_PARAM_NAME
  20. #endif
  21. // local macros, #undef-ined at the end of the header
  22. #if !defined(AUX778076_COUNT_ARGS_USE_STANDARD_PP_PRIMITIVES)
  23. # include <boost/mpl/aux_/preprocessor/repeat.hpp>
  24. # include <boost/mpl/aux_/preprocessor/params.hpp>
  25. # define AUX778076_COUNT_ARGS_REPEAT BOOST_MPL_PP_REPEAT
  26. # define AUX778076_COUNT_ARGS_PARAMS(param) \
  27. BOOST_MPL_PP_PARAMS( \
  28. AUX778076_COUNT_ARGS_ARITY \
  29. , param \
  30. ) \
  31. /**/
  32. #else
  33. # include <boost/preprocessor/enum_shifted_params.hpp>
  34. # include <boost/preprocessor/repeat.hpp>
  35. # include <boost/preprocessor/inc.hpp>
  36. # define AUX778076_COUNT_ARGS_REPEAT BOOST_PP_REPEAT
  37. # define AUX778076_COUNT_ARGS_PARAMS(param) \
  38. BOOST_PP_ENUM_SHIFTED_PARAMS( \
  39. BOOST_PP_INC(AUX778076_COUNT_ARGS_ARITY) \
  40. , param \
  41. ) \
  42. /**/
  43. #endif // AUX778076_COUNT_ARGS_USE_STANDARD_PP_PRIMITIVES
  44. #define AUX778076_IS_ARG_TEMPLATE_NAME \
  45. BOOST_PP_CAT(is_,BOOST_PP_CAT(AUX778076_COUNT_ARGS_PREFIX,_arg)) \
  46. /**/
  47. #define AUX778076_COUNT_ARGS_FUNC(unused, i, param) \
  48. BOOST_PP_EXPR_IF(i, +) \
  49. AUX778076_IS_ARG_TEMPLATE_NAME<BOOST_PP_CAT(param,BOOST_PP_INC(i))>::value \
  50. /**/
  51. // is_<xxx>_arg
  52. template< AUX778076_COUNT_ARGS_TEMPLATE_PARAM >
  53. struct AUX778076_IS_ARG_TEMPLATE_NAME
  54. {
  55. BOOST_STATIC_CONSTANT(bool, value = true);
  56. };
  57. template<>
  58. struct AUX778076_IS_ARG_TEMPLATE_NAME<AUX778076_COUNT_ARGS_DEFAULT>
  59. {
  60. BOOST_STATIC_CONSTANT(bool, value = false);
  61. };
  62. // <xxx>_count_args
  63. template<
  64. AUX778076_COUNT_ARGS_PARAMS(AUX778076_COUNT_ARGS_TEMPLATE_PARAM)
  65. >
  66. struct BOOST_PP_CAT(AUX778076_COUNT_ARGS_PREFIX,_count_args)
  67. {
  68. BOOST_STATIC_CONSTANT(int, value = AUX778076_COUNT_ARGS_REPEAT(
  69. AUX778076_COUNT_ARGS_ARITY
  70. , AUX778076_COUNT_ARGS_FUNC
  71. , AUX778076_COUNT_ARGS_PARAM_NAME
  72. ));
  73. };
  74. #undef AUX778076_COUNT_ARGS_FUNC
  75. #undef AUX778076_IS_ARG_TEMPLATE_NAME
  76. #undef AUX778076_COUNT_ARGS_PARAMS
  77. #undef AUX778076_COUNT_ARGS_REPEAT
  78. #undef AUX778076_COUNT_ARGS_ARITY
  79. #undef AUX778076_COUNT_ARGS_DEFAULT
  80. #undef AUX778076_COUNT_ARGS_PREFIX
  81. #undef AUX778076_COUNT_ARGS_USE_STANDARD_PP_PRIMITIVES
  82. #undef AUX778076_COUNT_ARGS_TEMPLATE_PARAM
  83. #undef AUX778076_COUNT_ARGS_PARAM_NAME