always.hpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #ifndef BOOST_METAPARSE_V1_ALWAYS_HPP
  2. #define BOOST_METAPARSE_V1_ALWAYS_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/accept.hpp>
  8. #include <boost/metaparse/v1/is_error.hpp>
  9. #include <boost/metaparse/v1/get_remaining.hpp>
  10. #include <boost/metaparse/v1/get_position.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 Result>
  19. struct always
  20. {
  21. private:
  22. template <class Res>
  23. struct apply_unchecked :
  24. accept<
  25. Result,
  26. typename get_remaining<Res>::type,
  27. typename get_position<Res>::type
  28. >
  29. {};
  30. public:
  31. typedef always type;
  32. template <class S, class Pos>
  33. struct apply :
  34. boost::mpl::eval_if<
  35. typename is_error<typename P::template apply<S, Pos> >::type,
  36. typename P::template apply<S, Pos>,
  37. apply_unchecked<typename P::template apply<S, Pos> >
  38. >
  39. {};
  40. };
  41. }
  42. }
  43. }
  44. #endif