last_of.qbk 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. [#last_of]
  2. [section last_of]
  3. [h1 Synopsis]
  4. template <class... Ps>
  5. struct last_of;
  6. This is a [link parser_combinator parser combinator].
  7. [table Arguments
  8. [[Name] [Type]]
  9. [[`Ps...`] [[link parser parser]s]]
  10. ]
  11. [h1 Description]
  12. `last_of` applies the `Ps...` parsers in sequence. It accepts an input when all
  13. parsers accept it. The result of parsing is the result of the last parser.
  14. On compilers, which are not C++11-compliant, the maximum number of parsers
  15. `last_of` accepts can be specified with the
  16. `BOOST_METAPARSE_LIMIT_SEQUENCE_SIZE` macro. Its default value is `5`.
  17. [h1 Header]
  18. #include <boost/metaparse/last_of.hpp>
  19. [h1 Expression semantics]
  20. For any `p1`, ... `pn` parsers
  21. first_of<p1, ..., pn>
  22. is equivalent to
  23. nth_of_c<n, p1, ..., pn>
  24. [h1 Example]
  25. #include <boost/metaparse/last_of.hpp>
  26. #include <boost/metaparse/int_.hpp>
  27. #include <boost/metaparse/lit_c.hpp>
  28. #include <boost/metaparse/string.hpp>
  29. #include <boost/metaparse/start.hpp>
  30. #include <boost/metaparse/is_error.hpp>
  31. #include <boost/metaparse/get_result.hpp>
  32. #include <type_traits>
  33. using namespace boost::metaparse;
  34. using comma_int = last_of<lit_c<','>, int_>;
  35. static_assert(
  36. is_error<comma_int::apply<BOOST_METAPARSE_STRING("13"), start>>::type::value,
  37. "int without comma is rejected"
  38. );
  39. static_assert(
  40. get_result<
  41. comma_int::apply<BOOST_METAPARSE_STRING(",13"), start>
  42. >::type::value,
  43. "the result is the result of the last parser"
  44. );
  45. [endsect]