accept_when.hpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #ifndef BOOST_METAPARSE_V1_ACCEPT_WHEN_HPP
  2. #define BOOST_METAPARSE_V1_ACCEPT_WHEN_HPP
  3. // Copyright Abel Sinkovics (abel@sinkovics.hu) 2009 - 2010.
  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/get_result.hpp>
  8. #include <boost/metaparse/v1/reject.hpp>
  9. #include <boost/metaparse/v1/is_error.hpp>
  10. #include <boost/mpl/if.hpp>
  11. #include <boost/mpl/eval_if.hpp>
  12. namespace boost
  13. {
  14. namespace metaparse
  15. {
  16. namespace v1
  17. {
  18. template <class P, class Pred, class Msg>
  19. struct accept_when
  20. {
  21. private:
  22. struct unchecked
  23. {
  24. template <class S, class Pos>
  25. struct apply :
  26. boost::mpl::eval_if<
  27. typename Pred::template apply<
  28. typename get_result<typename P::template apply<S, Pos> >::type
  29. >::type,
  30. typename P::template apply<S, Pos>,
  31. reject<Msg, Pos>
  32. >
  33. {};
  34. };
  35. public:
  36. typedef accept_when type;
  37. template <class S, class Pos>
  38. struct apply :
  39. boost::mpl::if_<
  40. is_error<typename P::template apply<S, Pos> >,
  41. P,
  42. unchecked
  43. >::type::template apply<
  44. S,
  45. Pos
  46. >
  47. {};
  48. };
  49. }
  50. }
  51. }
  52. #endif