lit_c.qbk 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. [#lit_c]
  2. [section lit_c]
  3. [h1 Synopsis]
  4. template <char C>
  5. struct lit;
  6. This is a [link parser parser].
  7. [table Arguments
  8. [[Name] [Type]]
  9. [[`C`] [`char` value]]
  10. ]
  11. [h1 Description]
  12. Parser accepting only the `C` character. The result of parsing is the accepted
  13. character.
  14. [h1 Header]
  15. #include <boost/metaparse/lit_c.hpp>
  16. [h1 Expression semantics]
  17. For any `c` character the following are equivalent:
  18. lit_c<c>
  19. lit<boost::mpl::char_<c>>
  20. [h1 Example]
  21. #include <boost/metaparse/lit_c.hpp>
  22. #include <boost/metaparse/start.hpp>
  23. #include <boost/metaparse/string.hpp>
  24. #include <boost/metaparse/is_error.hpp>
  25. #include <boost/metaparse/get_result.hpp>
  26. using namespace boost::metaparse;
  27. static_assert(
  28. is_error<lit_c<'x'>::apply<BOOST_METAPARSE_STRING("a"), start>>::type::value,
  29. "a different character should be an error"
  30. );
  31. static_assert(
  32. is_error<lit_c<'x'>::apply<BOOST_METAPARSE_STRING(""), start>>::type::value,
  33. "empty input should be an error"
  34. );
  35. static_assert(
  36. get_result<
  37. lit_c<'x'>::apply<BOOST_METAPARSE_STRING("x"), start>
  38. >::type::value == 'x',
  39. "result of parsing should be the accepted character"
  40. );
  41. [endsect]