]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/xpressive/include/boost/xpressive/detail/static/is_pure.hpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / xpressive / include / boost / xpressive / detail / static / is_pure.hpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // is_pure.hpp
3 //
4 // Copyright 2008 Eric Niebler. Distributed under the Boost
5 // Software License, Version 1.0. (See accompanying file
6 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7
8 #ifndef BOOST_XPRESSIVE_DETAIL_STATIC_IS_PURE_HPP_EAN_10_04_2005
9 #define BOOST_XPRESSIVE_DETAIL_STATIC_IS_PURE_HPP_EAN_10_04_2005
10
11 // MS compatible compilers support #pragma once
12 #if defined(_MSC_VER)
13 # pragma once
14 #endif
15
16 #include <boost/ref.hpp>
17 #include <boost/mpl/and.hpp>
18 #include <boost/mpl/bool.hpp>
19 #include <boost/mpl/assert.hpp>
20 #include <boost/mpl/not_equal_to.hpp>
21 #include <boost/xpressive/detail/detail_fwd.hpp>
22 #include <boost/xpressive/detail/static/width_of.hpp>
23
24 namespace boost { namespace xpressive { namespace detail
25 {
26 ///////////////////////////////////////////////////////////////////////////////
27 // use_simple_repeat_terminal
28 //
29 template<typename Expr, typename Char, bool IsXpr = is_xpr<Expr>::value>
30 struct use_simple_repeat_terminal
31 : mpl::bool_<
32 Expr::quant == quant_fixed_width
33 || (Expr::width != unknown_width::value && Expr::pure)
34 >
35 {};
36
37 template<typename Expr, typename Char>
38 struct use_simple_repeat_terminal<Expr, Char, false>
39 : mpl::true_ // char literals, string literals, etc.
40 {};
41
42 template<typename BidiIter, typename Char>
43 struct use_simple_repeat_terminal<tracking_ptr<regex_impl<BidiIter> >, Char, false>
44 : mpl::false_ // basic_regex
45 {};
46
47 template<typename BidiIter, typename Char>
48 struct use_simple_repeat_terminal<reference_wrapper<basic_regex<BidiIter> >, Char, false>
49 : mpl::false_ // basic_regex
50 {};
51
52 template<typename BidiIter, typename Char>
53 struct use_simple_repeat_terminal<reference_wrapper<basic_regex<BidiIter> const>, Char, false>
54 : mpl::false_ // basic_regex
55 {};
56
57 ///////////////////////////////////////////////////////////////////////////////
58 // use_simple_repeat_
59 //
60 template<typename Expr, typename Char, typename Tag = typename Expr::proto_tag>
61 struct use_simple_repeat_
62 {};
63
64 template<typename Expr, typename Char>
65 struct use_simple_repeat_<Expr, Char, proto::tag::terminal>
66 : use_simple_repeat_terminal<typename proto::result_of::value<Expr>::type, Char>
67 {};
68
69 template<typename Expr, typename Char>
70 struct use_simple_repeat_<Expr, Char, proto::tag::shift_right>
71 : mpl::and_<
72 use_simple_repeat_<typename remove_reference<typename Expr::proto_child0>::type::proto_base_expr, Char>
73 , use_simple_repeat_<typename remove_reference<typename Expr::proto_child1>::type::proto_base_expr, Char>
74 >
75 {};
76
77 template<typename Expr, typename Char>
78 struct use_simple_repeat_<Expr, Char, proto::tag::bitwise_or>
79 : mpl::and_<
80 mpl::not_equal_to<unknown_width, width_of<Expr, Char> >
81 , use_simple_repeat_<typename remove_reference<typename Expr::proto_child0>::type::proto_base_expr, Char>
82 , use_simple_repeat_<typename remove_reference<typename Expr::proto_child1>::type::proto_base_expr, Char>
83 >
84 {};
85
86 template<typename Left>
87 struct use_simple_repeat_assign
88 {};
89
90 template<>
91 struct use_simple_repeat_assign<mark_placeholder>
92 : mpl::false_
93 {};
94
95 template<>
96 struct use_simple_repeat_assign<set_initializer>
97 : mpl::true_
98 {};
99
100 template<typename Nbr>
101 struct use_simple_repeat_assign<attribute_placeholder<Nbr> >
102 : mpl::false_
103 {};
104
105 // either (s1 = ...) or (a1 = ...) or (set = ...)
106 template<typename Expr, typename Char>
107 struct use_simple_repeat_<Expr, Char, proto::tag::assign>
108 : use_simple_repeat_assign<
109 typename proto::result_of::value<
110 typename remove_reference<typename Expr::proto_child0>::type::proto_base_expr
111 >::type
112 >
113 {};
114
115 template<typename Expr, typename Char>
116 struct use_simple_repeat_<Expr, Char, modifier_tag>
117 : use_simple_repeat_<typename remove_reference<typename Expr::proto_child1>::type::proto_base_expr, Char>
118 {};
119
120 template<typename Expr, typename Char>
121 struct use_simple_repeat_<Expr, Char, lookahead_tag>
122 : mpl::false_
123 {};
124
125 template<typename Expr, typename Char>
126 struct use_simple_repeat_<Expr, Char, lookbehind_tag>
127 : mpl::false_
128 {};
129
130 template<typename Expr, typename Char>
131 struct use_simple_repeat_<Expr, Char, keeper_tag>
132 : mpl::false_
133 {};
134
135 // when complementing a set or an assertion, the purity is that of the set (true) or the assertion
136 template<typename Expr, typename Char>
137 struct use_simple_repeat_<Expr, Char, proto::tag::complement>
138 : use_simple_repeat_<typename remove_reference<typename Expr::proto_child0>::type::proto_base_expr, Char>
139 {};
140
141 // The comma is used in list-initialized sets, which are pure
142 template<typename Expr, typename Char>
143 struct use_simple_repeat_<Expr, Char, proto::tag::comma>
144 : mpl::true_
145 {};
146
147 // The subscript operator[] is used for sets, as in set['a' | range('b','h')]
148 // It is also used for actions, which by definition have side-effects and thus are impure
149 template<typename Expr, typename Char, typename Left>
150 struct use_simple_repeat_subscript
151 : mpl::false_
152 {};
153
154 template<typename Expr, typename Char>
155 struct use_simple_repeat_subscript<Expr, Char, set_initializer_type>
156 : mpl::true_
157 {};
158
159 template<typename Expr, typename Char>
160 struct use_simple_repeat_<Expr, Char, proto::tag::subscript>
161 : use_simple_repeat_subscript<Expr, Char, typename remove_reference<typename Expr::proto_child0>::type::proto_base_expr>
162 {};
163
164 // Quantified expressions are variable-width and cannot use the simple quantifier
165 template<typename Expr, typename Char>
166 struct use_simple_repeat_<Expr, Char, proto::tag::unary_plus>
167 : mpl::false_
168 {};
169
170 template<typename Expr, typename Char>
171 struct use_simple_repeat_<Expr, Char, proto::tag::dereference>
172 : mpl::false_
173 {};
174
175 template<typename Expr, typename Char>
176 struct use_simple_repeat_<Expr, Char, proto::tag::logical_not>
177 : mpl::false_
178 {};
179
180 template<typename Expr, typename Char, uint_t Min, uint_t Max>
181 struct use_simple_repeat_<Expr, Char, generic_quant_tag<Min, Max> >
182 : mpl::false_
183 {};
184
185 template<typename Expr, typename Char, uint_t Count>
186 struct use_simple_repeat_<Expr, Char, generic_quant_tag<Count, Count> >
187 : use_simple_repeat_<typename remove_reference<typename Expr::proto_child0>::type::proto_base_expr, Char>
188 {};
189
190 template<typename Expr, typename Char>
191 struct use_simple_repeat_<Expr, Char, proto::tag::negate>
192 : use_simple_repeat_<typename remove_reference<typename Expr::proto_child0>::type::proto_base_expr, Char>
193 {};
194
195 ///////////////////////////////////////////////////////////////////////////////
196 // use_simple_repeat
197 //
198 template<typename Expr, typename Char>
199 struct use_simple_repeat
200 : use_simple_repeat_<Expr, Char>
201 {
202 // should never try to repeat something of 0-width
203 BOOST_MPL_ASSERT_RELATION(0, !=, (width_of<Expr, Char>::value));
204 };
205
206 template<typename Expr, typename Char>
207 struct use_simple_repeat<Expr &, Char>
208 : use_simple_repeat_<Expr, Char>
209 {
210 // should never try to repeat something of 0-width
211 BOOST_MPL_ASSERT_RELATION(0, !=, (width_of<Expr, Char>::value));
212 };
213
214 }}} // namespace boost::xpressive::detail
215
216 #endif