one_of.hpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #ifndef BOOST_METAPARSE_V1_CPP11_ONE_OF_HPP
  2. #define BOOST_METAPARSE_V1_CPP11_ONE_OF_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/is_error.hpp>
  8. #include <boost/metaparse/v1/fail.hpp>
  9. #include <boost/metaparse/v1/cpp11/impl/eval_later_result.hpp>
  10. #include <boost/metaparse/v1/error/none_of_the_expected_cases_found.hpp>
  11. #include <boost/mpl/eval_if.hpp>
  12. namespace boost
  13. {
  14. namespace metaparse
  15. {
  16. namespace v1
  17. {
  18. template <class... Ps>
  19. struct one_of;
  20. template <class P, class... Ps>
  21. struct one_of<P, Ps...>
  22. {
  23. typedef one_of type;
  24. template <class S, class Pos>
  25. struct apply :
  26. boost::mpl::eval_if<
  27. typename is_error<typename P::template apply<S, Pos>>::type,
  28. boost::mpl::eval_if<
  29. typename is_error<
  30. typename one_of<Ps...>::template apply<S, Pos>
  31. >::type,
  32. impl::eval_later_result<
  33. typename P::template apply<S, Pos>,
  34. typename one_of<Ps...>::template apply<S, Pos>
  35. >,
  36. typename one_of<Ps...>::template apply<S, Pos>
  37. >,
  38. typename P::template apply<S, Pos>
  39. >
  40. {};
  41. };
  42. template <>
  43. struct one_of<> : fail<error::none_of_the_expected_cases_found> {};
  44. }
  45. }
  46. }
  47. #endif