look_ahead.hpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #ifndef BOOST_METAPARSE_V1_LOOK_AHEAD_HPP
  2. #define BOOST_METAPARSE_V1_LOOK_AHEAD_HPP
  3. // Copyright Abel Sinkovics (abel@sinkovics.hu) 2011.
  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/accept.hpp>
  9. #include <boost/metaparse/v1/get_result.hpp>
  10. #include <boost/mpl/eval_if.hpp>
  11. namespace boost
  12. {
  13. namespace metaparse
  14. {
  15. namespace v1
  16. {
  17. template <class P>
  18. struct look_ahead
  19. {
  20. private:
  21. template <class S, class Pos>
  22. struct no_error :
  23. accept<
  24. typename get_result<typename P::template apply<S, Pos> >::type,
  25. S,
  26. Pos
  27. >
  28. {};
  29. public:
  30. typedef look_ahead type;
  31. template <class S, class Pos>
  32. struct apply :
  33. boost::mpl::eval_if<
  34. typename is_error<typename P::template apply<S, Pos> >::type,
  35. typename P::template apply<S, Pos>,
  36. no_error<S, Pos>
  37. >
  38. {};
  39. };
  40. }
  41. }
  42. }
  43. #endif