]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | [#next_char] |
2 | [section next_char] | |
3 | ||
4 | [h1 Synopsis] | |
5 | ||
6 | template <class SourcePosition, class Ch> | |
7 | struct next_char; | |
8 | ||
9 | This is a [link lazy_metafunction lazy template metafunction]. | |
10 | ||
11 | [table Arguments | |
12 | [[Name] [Type]] | |
13 | [[`SourcePosition`] [[link source_position source position]]] | |
14 | [[`Ch`] [[link boxed_value boxed] character value. The character `SourcePosition` points to in the input.]] | |
15 | ] | |
16 | ||
17 | [h1 Description] | |
18 | ||
19 | Returns a new source position, pointing to the next character of the same line. | |
20 | ||
21 | [h1 Header] | |
22 | ||
23 | #include <boost/metaparse/next_char.hpp> | |
24 | ||
25 | [h1 Expression semantics] | |
26 | ||
27 | For any `s` source position and `c` wrapped character the following are | |
28 | equivalent | |
29 | ||
30 | get_col<next_char<s, c>> | |
31 | ||
32 | boost::mpl::plus<get_col<s>::type, boost::mpl::int_<1>> | |
33 | ||
34 | get_line<next_char<s, c>> | |
35 | ||
36 | get_line<s> | |
37 | ||
38 | get_prev_char<next_char<s, c>>::type | |
39 | ||
40 | c | |
41 | ||
42 | [h1 Example] | |
43 | ||
44 | #include <boost/metaparse/next_char.hpp> | |
45 | #include <boost/metaparse/source_position.hpp> | |
46 | #include <boost/metaparse/get_col.hpp> | |
47 | #include <boost/metaparse/get_line.hpp> | |
48 | #include <boost/metaparse/get_prev_char.hpp> | |
49 | ||
50 | #include <type_traits> | |
51 | ||
52 | using namespace boost::metaparse; | |
53 | ||
54 | struct returns_source_position | |
55 | { | |
56 | using type = | |
57 | source_position< | |
58 | std::integral_constant<int, 11>, | |
59 | std::integral_constant<int, 13>, | |
60 | std::integral_constant<char, 'a'> | |
61 | >; | |
62 | }; | |
63 | ||
64 | struct returns_char | |
65 | { | |
66 | using type = std::integral_constant<char, 'x'>; | |
67 | }; | |
68 | ||
69 | static_assert( | |
70 | get_col< | |
71 | next_char< | |
72 | source_position< | |
73 | std::integral_constant<int, 11>, | |
74 | std::integral_constant<int, 13>, | |
75 | std::integral_constant<char, 'a'> | |
76 | >, | |
77 | std::integral_constant<char, 'x'> | |
78 | > | |
79 | >::type::value == 14, | |
80 | "it should increase the column component of the source position" | |
81 | ); | |
82 | ||
83 | static_assert( | |
84 | get_line< | |
85 | next_char< | |
86 | source_position< | |
87 | std::integral_constant<int, 11>, | |
88 | std::integral_constant<int, 13>, | |
89 | std::integral_constant<char, 'a'> | |
90 | >, | |
91 | std::integral_constant<char, 'x'> | |
92 | > | |
93 | >::type::value == 11, | |
94 | "it should not increase the line component of the source position" | |
95 | ); | |
96 | ||
97 | static_assert( | |
98 | get_prev_char< | |
99 | next_char< | |
100 | source_position< | |
101 | std::integral_constant<int, 11>, | |
102 | std::integral_constant<int, 13>, | |
103 | std::integral_constant<char, 'a'> | |
104 | >, | |
105 | std::integral_constant<char, 'x'> | |
106 | > | |
107 | >::type::value == 'x', | |
108 | "it should update the prev char component of the source position" | |
109 | ); | |
110 | ||
111 | static_assert( | |
112 | get_col<next_char<returns_source_position, returns_char>>::type::value == 14, | |
113 | "it should support lazy evaluation" | |
114 | ); | |
115 | ||
116 | [endsect] | |
117 |