nth_of_c.hpp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #ifndef BOOST_METAPARSE_V1_CPP98_NTH_OF_C_HPP
  2. #define BOOST_METAPARSE_V1_CPP98_NTH_OF_C_HPP
  3. // Copyright Abel Sinkovics (abel@sinkovics.hu) 2013.
  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. #include <boost/metaparse/v1/cpp98/impl/nth_of_c.hpp>
  8. #include <boost/metaparse/limit_sequence_size.hpp>
  9. #include <boost/preprocessor/repetition/repeat.hpp>
  10. #include <boost/preprocessor/repetition/enum.hpp>
  11. #include <boost/preprocessor/punctuation/comma_if.hpp>
  12. #include <boost/preprocessor/repetition/enum_params.hpp>
  13. #include <boost/preprocessor/repetition/enum_params_with_a_default.hpp>
  14. #include <boost/preprocessor/arithmetic/sub.hpp>
  15. #include <boost/preprocessor/cat.hpp>
  16. #include <boost/preprocessor/tuple/eat.hpp>
  17. namespace boost
  18. {
  19. namespace metaparse
  20. {
  21. namespace v1
  22. {
  23. template <
  24. int N,
  25. BOOST_PP_ENUM_PARAMS_WITH_A_DEFAULT(
  26. BOOST_METAPARSE_LIMIT_SEQUENCE_SIZE,
  27. class P,
  28. boost::mpl::na
  29. )
  30. >
  31. struct nth_of_c;
  32. #ifdef BOOST_METAPARSE_NTH_OF_N
  33. # error BOOST_METAPARSE_NTH_OF_N already defined
  34. #endif
  35. #define BOOST_METAPARSE_NTH_OF_N(z, n, unused) \
  36. template <int K BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM_PARAMS(n, class P)> \
  37. struct nth_of_c< \
  38. K, \
  39. BOOST_PP_ENUM_PARAMS(n, P) \
  40. BOOST_PP_COMMA_IF(n) \
  41. BOOST_PP_ENUM( \
  42. BOOST_PP_SUB(BOOST_METAPARSE_LIMIT_SEQUENCE_SIZE, n), \
  43. boost::mpl::na BOOST_PP_TUPLE_EAT(3), \
  44. ~ \
  45. ) \
  46. > : \
  47. impl::BOOST_PP_CAT(nth_of_c, n)< \
  48. K BOOST_PP_COMMA_IF(n) \
  49. BOOST_PP_ENUM_PARAMS(n, P) \
  50. > \
  51. {};
  52. BOOST_PP_REPEAT(
  53. BOOST_METAPARSE_LIMIT_SEQUENCE_SIZE,
  54. BOOST_METAPARSE_NTH_OF_N,
  55. ~
  56. )
  57. #undef BOOST_METAPARSE_NTH_OF_N
  58. }
  59. }
  60. }
  61. #endif