one_of_c.qbk 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. [#one_of_c]
  2. [section one_of_c]
  3. [h1 Synopsis]
  4. template <char... Cs>
  5. struct one_of_c;
  6. This is a [link parser parser].
  7. [table Arguments
  8. [[Name] [Type]]
  9. [[`Cs`] [character values]]
  10. ]
  11. [h1 Description]
  12. It accepts inputs beginning with any of the `Cs...` characters. The result of
  13. parsing is the first character of the input.
  14. On compilers, which are not C++11-compliant, the maximum number of characters
  15. that can be provided is defined by the `BOOST_METAPARSE_LIMIT_ONE_OF_SIZE`
  16. macro. Its default value is `20`.
  17. [h1 Header]
  18. #include <boost/metaparse/one_of_c.hpp>
  19. [h1 Expression semantics]
  20. For any `c1`, ..., `cn` characters
  21. one_of_c<c1, ..., cn>
  22. is equivalent to
  23. one_of<lit_c<c1>, /* ... */, lit_c<cn>>
  24. [h1 Example]
  25. #include <boost/metaparse/one_of_c.hpp>
  26. #include <boost/metaparse/start.hpp>
  27. #include <boost/metaparse/string.hpp>
  28. #include <boost/metaparse/get_result.hpp>
  29. #include <boost/metaparse/is_error.hpp>
  30. using namespace boost::metaparse;
  31. using whitespace = one_of_c<' ', '\n', '\r', '\t', '\v'>;
  32. static_assert(
  33. get_result<
  34. whitespace::apply<BOOST_METAPARSE_STRING(" "), start>
  35. >::type::value == ' ',
  36. "the result of parsing should be the first character of the input"
  37. );
  38. static_assert(
  39. is_error<whitespace::apply<BOOST_METAPARSE_STRING("x"), start>>::type::value,
  40. "it should return an error when the input does not begin with a whitespace"
  41. );
  42. [endsect]