except_keywords.hpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #ifndef META_HS_EXCEPT_KEYWORDS_HPP
  2. #define META_HS_EXCEPT_KEYWORDS_HPP
  3. // Copyright Abel Sinkovics (abel@sinkovics.hu) 2012.
  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/accept_when.hpp>
  8. #include <boost/mpl/equal.hpp>
  9. #include <boost/mpl/and.hpp>
  10. #include <boost/mpl/not.hpp>
  11. #include <boost/mpl/fold.hpp>
  12. #include <boost/mpl/bool.hpp>
  13. #include <boost/mpl/apply_wrap.hpp>
  14. struct keywords_are_not_allowed {};
  15. template <class P, class Keywords>
  16. class except_keywords
  17. {
  18. private:
  19. template <class T>
  20. struct not_a_keyword
  21. {
  22. typedef not_a_keyword type;
  23. template <class Acc, class Keyword>
  24. struct apply :
  25. boost::mpl::and_<
  26. Acc,
  27. boost::mpl::not_<typename boost::mpl::equal<T, Keyword>::type>
  28. >
  29. {};
  30. };
  31. struct not_keyword
  32. {
  33. typedef not_keyword type;
  34. template <class T>
  35. struct apply :
  36. boost::mpl::fold<Keywords, boost::mpl::true_, not_a_keyword<T> >
  37. {};
  38. };
  39. public:
  40. typedef except_keywords type;
  41. template <class S, class Pos>
  42. struct apply :
  43. boost::mpl::apply_wrap2<
  44. boost::metaparse::accept_when<P, not_keyword, keywords_are_not_allowed>,
  45. S,
  46. Pos
  47. >
  48. {};
  49. };
  50. #endif