nth_of_c.hpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #ifndef BOOST_METAPARSE_V1_CPP98_IMPL_NTH_OF_C_HPP
  2. #define BOOST_METAPARSE_V1_CPP98_IMPL_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_impl.hpp>
  8. #include <boost/metaparse/v1/error/index_out_of_range.hpp>
  9. #include <boost/metaparse/v1/fail.hpp>
  10. #include <boost/metaparse/limit_sequence_size.hpp>
  11. #include <boost/mpl/list.hpp>
  12. #include <boost/preprocessor/repetition/repeat.hpp>
  13. #include <boost/preprocessor/punctuation/comma_if.hpp>
  14. #include <boost/preprocessor/repetition/enum_params.hpp>
  15. #include <boost/preprocessor/cat.hpp>
  16. namespace boost
  17. {
  18. namespace metaparse
  19. {
  20. namespace v1
  21. {
  22. namespace impl
  23. {
  24. #ifdef BOOST_METAPARSE_NTH_OF_CASE
  25. # error BOOST_METAPARSE_NTH_OF_CASE already defined
  26. #endif
  27. #define BOOST_METAPARSE_NTH_OF_CASE(z, n, unused) \
  28. template < \
  29. int K BOOST_PP_COMMA_IF(n) \
  30. BOOST_PP_ENUM_PARAMS(n, class P) \
  31. > \
  32. struct BOOST_PP_CAT(nth_of_c, n) : \
  33. boost::mpl::if_< \
  34. boost::mpl::bool_<(0 <= K && K < n)>, \
  35. nth_of_c_impl< \
  36. K, \
  37. boost::mpl::list<BOOST_PP_ENUM_PARAMS(n, P)> \
  38. >, \
  39. fail<error::index_out_of_range<0, n - 1, K> > \
  40. >::type \
  41. {};
  42. BOOST_PP_REPEAT(
  43. BOOST_METAPARSE_LIMIT_SEQUENCE_SIZE,
  44. BOOST_METAPARSE_NTH_OF_CASE,
  45. ~
  46. )
  47. #undef BOOST_METAPARSE_NTH_OF_CASE
  48. }
  49. }
  50. }
  51. }
  52. #endif