1 ///////////////////////////////////////////////////////////////////////////////
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)
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
11 // MS compatible compilers support #pragma once
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>
24 namespace boost { namespace xpressive { namespace detail
26 ///////////////////////////////////////////////////////////////////////////////
27 // use_simple_repeat_terminal
29 template<typename Expr, typename Char, bool IsXpr = is_xpr<Expr>::value>
30 struct use_simple_repeat_terminal
32 Expr::quant == quant_fixed_width
33 || (Expr::width != unknown_width::value && Expr::pure)
37 template<typename Expr, typename Char>
38 struct use_simple_repeat_terminal<Expr, Char, false>
39 : mpl::true_ // char literals, string literals, etc.
42 template<typename BidiIter, typename Char>
43 struct use_simple_repeat_terminal<tracking_ptr<regex_impl<BidiIter> >, Char, false>
44 : mpl::false_ // basic_regex
47 template<typename BidiIter, typename Char>
48 struct use_simple_repeat_terminal<reference_wrapper<basic_regex<BidiIter> >, Char, false>
49 : mpl::false_ // basic_regex
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
57 ///////////////////////////////////////////////////////////////////////////////
60 template<typename Expr, typename Char, typename Tag = typename Expr::proto_tag>
61 struct use_simple_repeat_
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>
69 template<typename Expr, typename Char>
70 struct use_simple_repeat_<Expr, Char, proto::tag::shift_right>
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>
77 template<typename Expr, typename Char>
78 struct use_simple_repeat_<Expr, Char, proto::tag::bitwise_or>
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>
86 template<typename Left>
87 struct use_simple_repeat_assign
91 struct use_simple_repeat_assign<mark_placeholder>
96 struct use_simple_repeat_assign<set_initializer>
100 template<typename Nbr>
101 struct use_simple_repeat_assign<attribute_placeholder<Nbr> >
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
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>
120 template<typename Expr, typename Char>
121 struct use_simple_repeat_<Expr, Char, lookahead_tag>
125 template<typename Expr, typename Char>
126 struct use_simple_repeat_<Expr, Char, lookbehind_tag>
130 template<typename Expr, typename Char>
131 struct use_simple_repeat_<Expr, Char, keeper_tag>
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>
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>
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
154 template<typename Expr, typename Char>
155 struct use_simple_repeat_subscript<Expr, Char, set_initializer_type>
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>
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>
170 template<typename Expr, typename Char>
171 struct use_simple_repeat_<Expr, Char, proto::tag::dereference>
175 template<typename Expr, typename Char>
176 struct use_simple_repeat_<Expr, Char, proto::tag::logical_not>
180 template<typename Expr, typename Char, uint_t Min, uint_t Max>
181 struct use_simple_repeat_<Expr, Char, generic_quant_tag<Min, Max> >
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>
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>
195 ///////////////////////////////////////////////////////////////////////////////
198 template<typename Expr, typename Char>
199 struct use_simple_repeat
200 : use_simple_repeat_<Expr, Char>
202 // should never try to repeat something of 0-width
203 BOOST_MPL_ASSERT_RELATION(0, !=, (width_of<Expr, Char>::value));
206 template<typename Expr, typename Char>
207 struct use_simple_repeat<Expr &, Char>
208 : use_simple_repeat_<Expr, Char>
210 // should never try to repeat something of 0-width
211 BOOST_MPL_ASSERT_RELATION(0, !=, (width_of<Expr, Char>::value));
214 }}} // namespace boost::xpressive::detail