/////////////////////////////////////////////////////////////////////////////// // as_xpr.hpp // // Copyright 2004 Eric Niebler. Distributed under the Boost // Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) #ifndef BOOST_XPRESSIVE_DETAIL_STATIC_AS_XPR_HPP_EAN_10_04_2005 #define BOOST_XPRESSIVE_DETAIL_STATIC_AS_XPR_HPP_EAN_10_04_2005 // MS compatible compilers support #pragma once #if defined(_MSC_VER) && (_MSC_VER >= 1020) # pragma once #endif #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include namespace boost { namespace xpressive { namespace detail { template struct wrap { wrap(T); }; /////////////////////////////////////////////////////////////////////////////// // is_string_literal // template struct is_string_literal : mpl::or_ < is_convertible > , is_convertible > > { }; /////////////////////////////////////////////////////////////////////////////// // string_generator // template struct string_placeholder_generator { typedef typename remove_cv < typename mpl::eval_if < is_array , remove_bounds , remove_pointer >::type >::type char_type; typedef string_placeholder type; }; /////////////////////////////////////////////////////////////////////////////// // as_matcher template::value> struct as_matcher_type { typedef Matcher type; static type const &call(Matcher const &matcher) { return matcher; } }; template struct as_matcher_type { typedef typename mpl::eval_if < is_string_literal , string_placeholder_generator , mpl::identity > >::type type; static type call(Literal const &literal) { return type(literal); } }; template struct as_matcher_type, false> { typedef regex_placeholder type; static type call(basic_regex const &rex) { typedef core_access access; shared_ptr > impl = access::get_regex_impl(rex); return type(impl); } }; template struct as_matcher_type const>, false> { typedef regex_placeholder type; static type call(reference_wrapper const> const &rex) { typedef core_access access; shared_ptr > impl = access::get_regex_impl(rex.get()); return type(impl); } }; /////////////////////////////////////////////////////////////////////////////// // as_xpr_type // template struct as_xpr_type // is_op == true { typedef Xpr type; typedef Xpr const &const_reference; static Xpr const &call(Xpr const &xpr) { return xpr; } }; template struct as_xpr_type { typedef proto::unary_op < typename as_matcher_type::type , proto::noop_tag > type; typedef type const const_reference; static type const call(Xpr const &xpr) { return proto::noop(detail::as_matcher_type::call(xpr)); } }; }}} // namespace boost::xpressive::detail namespace boost { namespace xpressive { /////////////////////////////////////////////////////////////////////////////// // as_xpr (from a literal to an xpression) // template inline typename detail::as_xpr_type::const_reference as_xpr(Xpr const &xpr) { return detail::as_xpr_type::call(xpr); } }} // namespace boost::xpressive #endif