nth_of_c.hpp 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #ifndef BOOST_METAPARSE_V1_CPP11_IMPL_NTH_OF_C_HPP
  2. #define BOOST_METAPARSE_V1_CPP11_IMPL_NTH_OF_C_HPP
  3. // Copyright Abel Sinkovics (abel@sinkovics.hu) 2017.
  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/cpp11/impl/nth_of_c_skip_remaining.hpp>
  8. #include <boost/metaparse/v1/is_error.hpp>
  9. #include <boost/metaparse/v1/get_remaining.hpp>
  10. #include <boost/metaparse/v1/get_position.hpp>
  11. #include <boost/metaparse/v1/get_result.hpp>
  12. #include <type_traits>
  13. namespace boost
  14. {
  15. namespace metaparse
  16. {
  17. namespace v1
  18. {
  19. namespace impl
  20. {
  21. template <int N, class S, class Pos, class... Ps>
  22. struct nth_of_c;
  23. template <int N, class S, class Pos, class P, class... Ps>
  24. struct nth_of_c<N, S, Pos, P, Ps...>
  25. {
  26. private:
  27. template <class NextResult>
  28. struct apply_unchecked :
  29. nth_of_c<
  30. N - 1,
  31. typename get_remaining<NextResult>::type,
  32. typename get_position<NextResult>::type,
  33. Ps...
  34. >
  35. {};
  36. public:
  37. typedef
  38. typename std::conditional<
  39. is_error<typename P::template apply<S, Pos>>::type::value,
  40. typename P::template apply<S, Pos>,
  41. apply_unchecked<typename P::template apply<S, Pos>>
  42. >::type::type
  43. type;
  44. };
  45. template <class P, class S, class Pos, class... Ps>
  46. struct nth_of_c<0, S, Pos, P, Ps...>
  47. {
  48. private:
  49. template <class NextResult>
  50. struct apply_unchecked :
  51. nth_of_c_skip_remaining<
  52. typename get_result<NextResult>::type,
  53. typename get_remaining<NextResult>::type,
  54. typename get_position<NextResult>::type,
  55. Ps...
  56. >
  57. {};
  58. public:
  59. typedef
  60. typename std::conditional<
  61. is_error<typename P::template apply<S, Pos>>::type::value,
  62. typename P::template apply<S, Pos>,
  63. apply_unchecked<typename P::template apply<S, Pos>>
  64. >::type::type
  65. type;
  66. };
  67. }
  68. }
  69. }
  70. }
  71. #endif