empty.qbk 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. [#empty]
  2. [section empty]
  3. [h1 Synopsis]
  4. template <class Result>
  5. struct empty;
  6. This is a [link parser parser].
  7. [table Arguments
  8. [[Name] [Type]]
  9. [[`Result`] [[link metaprogramming_value template metaprogramming value]]]
  10. ]
  11. [h1 Description]
  12. It accepts empty input only. The result of parsing is the `Result`
  13. argument.
  14. [h1 Header]
  15. #include <boost/metaparse/empty.hpp>
  16. [h1 Expression semantics]
  17. For any `c` class the following are equivalent:
  18. empty<c>
  19. except<one_char, c, error::end_of_input_expected>
  20. [h1 Example]
  21. #include <boost/metaparse/empty.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. #include <type_traits>
  27. using namespace boost::metaparse;
  28. using want_empty = empty<BOOST_METAPARSE_STRING("result")>;
  29. static_assert(
  30. !is_error<want_empty::apply<BOOST_METAPARSE_STRING(""), start>>::type::value,
  31. "empty accepts the empty input"
  32. );
  33. static_assert(
  34. is_error<want_empty::apply<BOOST_METAPARSE_STRING("x"), start>>::type::value,
  35. "empty should reject non-empty input"
  36. );
  37. static_assert(
  38. std::is_same<
  39. get_result<want_empty::apply<BOOST_METAPARSE_STRING(""), start>>::type,
  40. BOOST_METAPARSE_STRING("result")
  41. >::type::value,
  42. "the result of parsing should be the given value"
  43. );
  44. [endsect]