any_of_c.hpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #ifndef BOOST_METAPARSE_V1_CPP14_IMPL_ANY_OF_C_HPP
  2. #define BOOST_METAPARSE_V1_CPP14_IMPL_ANY_OF_C_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/mpl/bool.hpp>
  8. namespace boost
  9. {
  10. namespace metaparse
  11. {
  12. namespace v1
  13. {
  14. namespace impl
  15. {
  16. template <char... Cs>
  17. struct any_of_c
  18. {
  19. typedef any_of_c type;
  20. static constexpr bool run(char c_)
  21. {
  22. const bool values[] = {(c_ == Cs)...};
  23. for (const bool* i = values; i != values + sizeof...(Cs); ++i)
  24. {
  25. if (*i)
  26. {
  27. return true;
  28. }
  29. }
  30. return false;
  31. }
  32. template <class Chr>
  33. struct apply : boost::mpl::bool_<any_of_c::run(Chr::type::value)> {};
  34. };
  35. template <>
  36. struct any_of_c<>
  37. {
  38. typedef any_of_c type;
  39. template <class>
  40. struct apply : boost::mpl::false_ {};
  41. };
  42. }
  43. }
  44. }
  45. }
  46. #endif