nth_of_c_impl.hpp 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #ifndef BOOST_METAPARSE_V1_CPP98_IMPL_NTH_OF_C_IMPL_HPP
  2. #define BOOST_METAPARSE_V1_CPP98_IMPL_NTH_OF_C_IMPL_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/skip_seq.hpp>
  8. #include <boost/mpl/front.hpp>
  9. #include <boost/mpl/pop_front.hpp>
  10. #include <boost/mpl/fold.hpp>
  11. namespace boost
  12. {
  13. namespace metaparse
  14. {
  15. namespace v1
  16. {
  17. namespace impl
  18. {
  19. template <int N, class Seq>
  20. struct nth_of_c_impl
  21. {
  22. private:
  23. template <class NextResult>
  24. struct apply_unchecked :
  25. nth_of_c_impl<
  26. N - 1,
  27. typename boost::mpl::pop_front<Seq>::type
  28. >::template apply<
  29. typename get_remaining<NextResult>::type,
  30. typename get_position<NextResult>::type
  31. >
  32. {};
  33. public:
  34. typedef nth_of_c_impl type;
  35. template <class S, class Pos>
  36. struct apply :
  37. boost::mpl::eval_if<
  38. typename is_error<
  39. typename boost::mpl::front<Seq>::type::template apply<S, Pos>
  40. >::type,
  41. typename boost::mpl::front<Seq>::type::template apply<S, Pos>,
  42. apply_unchecked<
  43. typename boost::mpl::front<Seq>::type::template apply<S, Pos>
  44. >
  45. >
  46. {};
  47. };
  48. template <class Seq>
  49. struct nth_of_c_impl<0, Seq>
  50. {
  51. typedef nth_of_c_impl type;
  52. template <class S, class Pos>
  53. struct apply :
  54. boost::mpl::fold<
  55. typename boost::mpl::pop_front<Seq>::type,
  56. typename boost::mpl::front<Seq>::type::template apply<
  57. S,
  58. Pos
  59. >::type,
  60. skip_seq
  61. >
  62. {};
  63. };
  64. }
  65. }
  66. }
  67. }
  68. #endif