last_of.hpp 1.8 KB

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