sequence.hpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #ifndef BOOST_METAPARSE_V1_CPP11_SEQUENCE_HPP
  2. #define BOOST_METAPARSE_V1_CPP11_SEQUENCE_HPP
  3. // Copyright Abel Sinkovics (abel@sinkovics.hu) 2018.
  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/push_front_result.hpp>
  8. #include <boost/metaparse/v1/get_remaining.hpp>
  9. #include <boost/metaparse/v1/get_position.hpp>
  10. #include <boost/metaparse/v1/is_error.hpp>
  11. #include <boost/metaparse/v1/return_.hpp>
  12. #include <boost/metaparse/v1/transform.hpp>
  13. #include <boost/mpl/eval_if.hpp>
  14. #include <boost/mpl/vector.hpp>
  15. namespace boost
  16. {
  17. namespace metaparse
  18. {
  19. namespace v1
  20. {
  21. template <class... Ps>
  22. struct sequence;
  23. template <>
  24. struct sequence<> : return_<boost::mpl::vector<>> {};
  25. template <class P, class... Ps>
  26. struct sequence<P, Ps...>
  27. {
  28. private:
  29. template <class Res>
  30. struct apply_unchecked :
  31. transform<
  32. sequence<Ps...>,
  33. impl::push_front_result<Res>
  34. >::template apply<
  35. typename get_remaining<Res>::type,
  36. typename get_position<Res>::type
  37. >
  38. {};
  39. public:
  40. typedef sequence type;
  41. template <class S, class Pos>
  42. struct apply :
  43. boost::mpl::eval_if<
  44. typename is_error<typename P::template apply<S, Pos>>::type,
  45. typename P::template apply<S, Pos>,
  46. apply_unchecked<typename P::template apply<S, Pos>>
  47. >
  48. {};
  49. };
  50. }
  51. }
  52. }
  53. #endif