• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1[#get_position]
2[section get_position]
3
4[h1 Synopsis]
5
6  template <class D>
7  struct get_position;
8
9This is a [link lazy_metafunction lazy template metafunction].
10
11[table Arguments
12  [[Name] [Type]]
13  [[`D`]  [[link accept accept] or [link reject reject] value]]
14]
15
16[h1 Description]
17
18Returns the source position information of a parsing result.
19
20[h1 Header]
21
22  #include <boost/metaparse/get_position.hpp>
23
24[h1 Example]
25
26  #include <boost/metaparse/get_position.hpp>
27  #include <boost/metaparse/start.hpp>
28  #include <boost/metaparse/accept.hpp>
29  #include <boost/metaparse/reject.hpp>
30  #include <boost/metaparse/string.hpp>
31  #include <boost/metaparse/define_error.hpp>
32
33  #include <type_traits>
34
35  using namespace boost::metaparse;
36
37  BOOST_METAPARSE_DEFINE_ERROR(sample_error, "Sample error message");
38
39  struct returns_reject
40  {
41    using type = reject<sample_error, start>;
42  };
43
44  static_assert(
45    std::is_same<
46      start,
47      get_position<reject<sample_error, start>>::type
48    >::type::value,
49    "It should return the position of a reject"
50  );
51
52  static_assert(
53    std::is_same<
54      start,
55      get_position<
56        accept<sample_error, BOOST_METAPARSE_STRING("foo"), start>
57      >::type
58    >::type::value,
59    "It should return the position of an accept"
60  );
61
62  static_assert(
63    std::is_same<start, get_position<returns_reject>::type>::type::value,
64    "It should support lazy evaluation"
65  );
66
67[endsect]
68
69