• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1[#empty]
2[section empty]
3
4[h1 Synopsis]
5
6  template <class Result>
7  struct empty;
8
9This is a [link parser parser].
10
11[table Arguments
12  [[Name]     [Type]]
13  [[`Result`] [[link metaprogramming_value template metaprogramming value]]]
14]
15
16[h1 Description]
17
18It accepts empty input only. The result of parsing is the `Result`
19argument.
20
21[h1 Header]
22
23  #include <boost/metaparse/empty.hpp>
24
25[h1 Expression semantics]
26
27For any `c` class the following are equivalent:
28
29  empty<c>
30
31  except<one_char, c, error::end_of_input_expected>
32
33[h1 Example]
34
35  #include <boost/metaparse/empty.hpp>
36  #include <boost/metaparse/start.hpp>
37  #include <boost/metaparse/string.hpp>
38  #include <boost/metaparse/is_error.hpp>
39  #include <boost/metaparse/get_result.hpp>
40
41  #include <type_traits>
42
43  using namespace boost::metaparse;
44
45  using want_empty = empty<BOOST_METAPARSE_STRING("result")>;
46
47  static_assert(
48    !is_error<want_empty::apply<BOOST_METAPARSE_STRING(""), start>>::type::value,
49    "empty accepts the empty input"
50  );
51
52  static_assert(
53    is_error<want_empty::apply<BOOST_METAPARSE_STRING("x"), start>>::type::value,
54    "empty should reject non-empty input"
55  );
56
57  static_assert(
58    std::is_same<
59      get_result<want_empty::apply<BOOST_METAPARSE_STRING(""), start>>::type,
60      BOOST_METAPARSE_STRING("result")
61    >::type::value,
62    "the result of parsing should be the given value"
63  );
64
65[endsect]
66
67