Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:53:51

0001 ///////////////////////////////////////////////////////////////////////////////
0002 // is_pure.hpp
0003 //
0004 //  Copyright 2008 Eric Niebler. Distributed under the Boost
0005 //  Software License, Version 1.0. (See accompanying file
0006 //  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0007 
0008 #ifndef BOOST_XPRESSIVE_DETAIL_STATIC_IS_PURE_HPP_EAN_10_04_2005
0009 #define BOOST_XPRESSIVE_DETAIL_STATIC_IS_PURE_HPP_EAN_10_04_2005
0010 
0011 // MS compatible compilers support #pragma once
0012 #if defined(_MSC_VER)
0013 # pragma once
0014 #endif
0015 
0016 #include <boost/ref.hpp>
0017 #include <boost/mpl/and.hpp>
0018 #include <boost/mpl/bool.hpp>
0019 #include <boost/mpl/assert.hpp>
0020 #include <boost/mpl/not_equal_to.hpp>
0021 #include <boost/xpressive/detail/detail_fwd.hpp>
0022 #include <boost/xpressive/detail/static/width_of.hpp>
0023 
0024 namespace boost { namespace xpressive { namespace detail
0025 {
0026     ///////////////////////////////////////////////////////////////////////////////
0027     // use_simple_repeat_terminal
0028     //
0029     template<typename Expr, typename Char, bool IsXpr = is_xpr<Expr>::value>
0030     struct use_simple_repeat_terminal
0031       : mpl::bool_<
0032             Expr::quant == quant_fixed_width
0033         || (Expr::width != unknown_width::value && Expr::pure)
0034         >
0035     {};
0036 
0037     template<typename Expr, typename Char>
0038     struct use_simple_repeat_terminal<Expr, Char, false>
0039       : mpl::true_              // char literals, string literals, etc.
0040     {};
0041 
0042     template<typename BidiIter, typename Char>
0043     struct use_simple_repeat_terminal<tracking_ptr<regex_impl<BidiIter> >, Char, false>
0044       : mpl::false_             // basic_regex
0045     {};
0046 
0047     template<typename BidiIter, typename Char>
0048     struct use_simple_repeat_terminal<reference_wrapper<basic_regex<BidiIter> >, Char, false>
0049       : mpl::false_             // basic_regex
0050     {};
0051 
0052     template<typename BidiIter, typename Char>
0053     struct use_simple_repeat_terminal<reference_wrapper<basic_regex<BidiIter> const>, Char, false>
0054       : mpl::false_             // basic_regex
0055     {};
0056 
0057     ///////////////////////////////////////////////////////////////////////////////
0058     // use_simple_repeat_
0059     //
0060     template<typename Expr, typename Char, typename Tag = typename Expr::proto_tag>
0061     struct use_simple_repeat_
0062     {};
0063 
0064     template<typename Expr, typename Char>
0065     struct use_simple_repeat_<Expr, Char, proto::tag::terminal>
0066       : use_simple_repeat_terminal<typename proto::result_of::value<Expr>::type, Char>
0067     {};
0068 
0069     template<typename Expr, typename Char>
0070     struct use_simple_repeat_<Expr, Char, proto::tag::shift_right>
0071       : mpl::and_<
0072             use_simple_repeat_<typename remove_reference<typename Expr::proto_child0>::type::proto_base_expr, Char>
0073           , use_simple_repeat_<typename remove_reference<typename Expr::proto_child1>::type::proto_base_expr, Char>
0074         >
0075     {};
0076 
0077     template<typename Expr, typename Char>
0078     struct use_simple_repeat_<Expr, Char, proto::tag::bitwise_or>
0079       : mpl::and_<
0080             mpl::not_equal_to<unknown_width, width_of<Expr, Char> >
0081           , use_simple_repeat_<typename remove_reference<typename Expr::proto_child0>::type::proto_base_expr, Char>
0082           , use_simple_repeat_<typename remove_reference<typename Expr::proto_child1>::type::proto_base_expr, Char>
0083         >
0084     {};
0085 
0086     template<typename Left>
0087     struct use_simple_repeat_assign
0088     {};
0089 
0090     template<>
0091     struct use_simple_repeat_assign<mark_placeholder>
0092       : mpl::false_
0093     {};
0094 
0095     template<>
0096     struct use_simple_repeat_assign<set_initializer>
0097       : mpl::true_
0098     {};
0099 
0100     template<typename Nbr>
0101     struct use_simple_repeat_assign<attribute_placeholder<Nbr> >
0102       : mpl::false_
0103     {};
0104 
0105     // either (s1 = ...) or (a1 = ...) or (set = ...)
0106     template<typename Expr, typename Char>
0107     struct use_simple_repeat_<Expr, Char, proto::tag::assign>
0108       : use_simple_repeat_assign<
0109             typename proto::result_of::value<
0110                 typename remove_reference<typename Expr::proto_child0>::type::proto_base_expr
0111             >::type
0112         >
0113     {};
0114 
0115     template<typename Expr, typename Char>
0116     struct use_simple_repeat_<Expr, Char, modifier_tag>
0117       : use_simple_repeat_<typename remove_reference<typename Expr::proto_child1>::type::proto_base_expr, Char>
0118     {};
0119 
0120     template<typename Expr, typename Char>
0121     struct use_simple_repeat_<Expr, Char, lookahead_tag>
0122       : mpl::false_
0123     {};
0124 
0125     template<typename Expr, typename Char>
0126     struct use_simple_repeat_<Expr, Char, lookbehind_tag>
0127       : mpl::false_
0128     {};
0129 
0130     template<typename Expr, typename Char>
0131     struct use_simple_repeat_<Expr, Char, keeper_tag>
0132       : mpl::false_
0133     {};
0134 
0135     // when complementing a set or an assertion, the purity is that of the set (true) or the assertion
0136     template<typename Expr, typename Char>
0137     struct use_simple_repeat_<Expr, Char, proto::tag::complement>
0138       : use_simple_repeat_<typename remove_reference<typename Expr::proto_child0>::type::proto_base_expr, Char>
0139     {};
0140 
0141     // The comma is used in list-initialized sets, which are pure
0142     template<typename Expr, typename Char>
0143     struct use_simple_repeat_<Expr, Char, proto::tag::comma>
0144       : mpl::true_
0145     {};
0146 
0147     // The subscript operator[] is used for sets, as in set['a' | range('b','h')]
0148     // It is also used for actions, which by definition have side-effects and thus are impure
0149     template<typename Expr, typename Char, typename Left>
0150     struct use_simple_repeat_subscript
0151       : mpl::false_
0152     {};
0153 
0154     template<typename Expr, typename Char>
0155     struct use_simple_repeat_subscript<Expr, Char, set_initializer_type>
0156       : mpl::true_
0157     {};
0158 
0159     template<typename Expr, typename Char>
0160     struct use_simple_repeat_<Expr, Char, proto::tag::subscript>
0161       : use_simple_repeat_subscript<Expr, Char, typename remove_reference<typename Expr::proto_child0>::type::proto_base_expr>
0162     {};
0163 
0164     // Quantified expressions are variable-width and cannot use the simple quantifier
0165     template<typename Expr, typename Char>
0166     struct use_simple_repeat_<Expr, Char, proto::tag::unary_plus>
0167       : mpl::false_
0168     {};
0169 
0170     template<typename Expr, typename Char>
0171     struct use_simple_repeat_<Expr, Char, proto::tag::dereference>
0172       : mpl::false_
0173     {};
0174 
0175     template<typename Expr, typename Char>
0176     struct use_simple_repeat_<Expr, Char, proto::tag::logical_not>
0177       : mpl::false_
0178     {};
0179 
0180     template<typename Expr, typename Char, uint_t Min, uint_t Max>
0181     struct use_simple_repeat_<Expr, Char, generic_quant_tag<Min, Max> >
0182       : mpl::false_
0183     {};
0184 
0185     template<typename Expr, typename Char, uint_t Count>
0186     struct use_simple_repeat_<Expr, Char, generic_quant_tag<Count, Count> >
0187       : use_simple_repeat_<typename remove_reference<typename Expr::proto_child0>::type::proto_base_expr, Char>
0188     {};
0189 
0190     template<typename Expr, typename Char>
0191     struct use_simple_repeat_<Expr, Char, proto::tag::negate>
0192       : use_simple_repeat_<typename remove_reference<typename Expr::proto_child0>::type::proto_base_expr, Char>
0193     {};
0194 
0195     ///////////////////////////////////////////////////////////////////////////////
0196     // use_simple_repeat
0197     //
0198     template<typename Expr, typename Char>
0199     struct use_simple_repeat
0200       : use_simple_repeat_<Expr, Char>
0201     {
0202         // should never try to repeat something of 0-width
0203         BOOST_MPL_ASSERT_RELATION(0, !=, (width_of<Expr, Char>::value));
0204     };
0205 
0206     template<typename Expr, typename Char>
0207     struct use_simple_repeat<Expr &, Char>
0208       : use_simple_repeat_<Expr, Char>
0209     {
0210         // should never try to repeat something of 0-width
0211         BOOST_MPL_ASSERT_RELATION(0, !=, (width_of<Expr, Char>::value));
0212     };
0213 
0214 }}} // namespace boost::xpressive::detail
0215 
0216 #endif