Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:50:26

0001 ///////////////////////////////////////////////////////////////////////////////
0002 /// \file as_expr.hpp
0003 /// Contains definition of the as_expr\<\> and as_child\<\> helper class
0004 /// templates used to implement proto::domain's as_expr\<\> and as_child\<\>
0005 /// member templates.
0006 //
0007 //  Copyright 2010 Eric Niebler. Distributed under the Boost
0008 //  Software License, Version 1.0. (See accompanying file
0009 //  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0010 
0011 #ifndef BOOST_PROTO_DETAIL_AS_EXPR_HPP_EAN_06_09_2010
0012 #define BOOST_PROTO_DETAIL_AS_EXPR_HPP_EAN_06_09_2010
0013 
0014 #include <boost/config.hpp>
0015 #include <boost/detail/workaround.hpp>
0016 #include <boost/type_traits/remove_const.hpp>
0017 #include <boost/proto/proto_fwd.hpp>
0018 #include <boost/proto/args.hpp>
0019 
0020 #if defined(_MSC_VER)
0021 # pragma warning(push)
0022 # pragma warning(disable : 4714) // function 'xxx' marked as __forceinline not inlined
0023 #endif
0024 
0025 namespace boost { namespace proto { namespace detail
0026 {
0027 
0028     ////////////////////////////////////////////////////////////////////////////////////////////////
0029     template<typename Generator>
0030     struct base_generator
0031     {
0032         typedef Generator type;
0033     };
0034 
0035     template<typename Generator>
0036     struct base_generator<use_basic_expr<Generator> >
0037     {
0038         typedef Generator type;
0039     };
0040 
0041     ////////////////////////////////////////////////////////////////////////////////////////////////
0042     template<typename T, typename Generator, bool WantsBasicExpr>
0043     struct as_expr;
0044 
0045     ////////////////////////////////////////////////////////////////////////////////////////////////
0046     template<typename T, typename Generator>
0047     struct as_expr<T, Generator, false>
0048     {
0049         typedef typename term_traits<T &>::value_type value_type;
0050         typedef proto::expr<proto::tag::terminal, term<value_type>, 0> expr_type;
0051         typedef typename Generator::template result<Generator(expr_type)>::type result_type;
0052 
0053         BOOST_FORCEINLINE
0054         result_type operator()(T &t) const
0055         {
0056             return Generator()(expr_type::make(t));
0057         }
0058     };
0059 
0060     ////////////////////////////////////////////////////////////////////////////////////////////////
0061     template<typename T, typename Generator>
0062     struct as_expr<T, Generator, true>
0063     {
0064         typedef typename term_traits<T &>::value_type value_type;
0065         typedef proto::basic_expr<proto::tag::terminal, term<value_type>, 0> expr_type;
0066         typedef typename Generator::template result<Generator(expr_type)>::type result_type;
0067 
0068         BOOST_FORCEINLINE
0069         result_type operator()(T &t) const
0070         {
0071             return Generator()(expr_type::make(t));
0072         }
0073     };
0074 
0075     ////////////////////////////////////////////////////////////////////////////////////////////////
0076     template<typename T>
0077     struct as_expr<T, proto::default_generator, false>
0078     {
0079         typedef typename term_traits<T &>::value_type value_type;
0080         typedef proto::expr<proto::tag::terminal, term<value_type>, 0> result_type;
0081 
0082         BOOST_FORCEINLINE
0083         result_type operator()(T &t) const
0084         {
0085             return result_type::make(t);
0086         }
0087     };
0088 
0089     ////////////////////////////////////////////////////////////////////////////////////////////////
0090     template<typename T>
0091     struct as_expr<T, proto::default_generator, true>
0092     {
0093         typedef typename term_traits<T &>::value_type value_type;
0094         typedef proto::basic_expr<proto::tag::terminal, term<value_type>, 0> result_type;
0095 
0096         BOOST_FORCEINLINE
0097         result_type operator()(T &t) const
0098         {
0099             return result_type::make(t);
0100         }
0101     };
0102 
0103     ////////////////////////////////////////////////////////////////////////////////////////////////
0104     template<typename T, typename Generator, bool WantsBasicExpr>
0105     struct as_child;
0106 
0107     ////////////////////////////////////////////////////////////////////////////////////////////////
0108     template<typename T, typename Generator>
0109     struct as_child<T, Generator, false>
0110     {
0111     #if BOOST_WORKAROUND(BOOST_MSVC, == 1310)
0112         typedef typename term_traits<T &>::reference reference;
0113     #else
0114         typedef T &reference;
0115     #endif
0116         typedef proto::expr<proto::tag::terminal, term<reference>, 0> expr_type;
0117         typedef typename Generator::template result<Generator(expr_type)>::type result_type;
0118 
0119         BOOST_FORCEINLINE
0120         result_type operator()(T &t) const
0121         {
0122             return Generator()(expr_type::make(t));
0123         }
0124     };
0125 
0126     ////////////////////////////////////////////////////////////////////////////////////////////////
0127     template<typename T, typename Generator>
0128     struct as_child<T, Generator, true>
0129     {
0130     #if BOOST_WORKAROUND(BOOST_MSVC, == 1310)
0131         typedef typename term_traits<T &>::reference reference;
0132     #else
0133         typedef T &reference;
0134     #endif
0135         typedef proto::basic_expr<proto::tag::terminal, term<reference>, 0> expr_type;
0136         typedef typename Generator::template result<Generator(expr_type)>::type result_type;
0137 
0138         BOOST_FORCEINLINE
0139         result_type operator()(T &t) const
0140         {
0141             return Generator()(expr_type::make(t));
0142         }
0143     };
0144 
0145     ////////////////////////////////////////////////////////////////////////////////////////////////
0146     template<typename T>
0147     struct as_child<T, proto::default_generator, false>
0148     {
0149     #if BOOST_WORKAROUND(BOOST_MSVC, == 1310)
0150         typedef typename term_traits<T &>::reference reference;
0151     #else
0152         typedef T &reference;
0153     #endif
0154         typedef proto::expr<proto::tag::terminal, term<reference>, 0> result_type;
0155 
0156         BOOST_FORCEINLINE
0157         result_type operator()(T &t) const
0158         {
0159             return result_type::make(t);
0160         }
0161     };
0162 
0163     ////////////////////////////////////////////////////////////////////////////////////////////////
0164     template<typename T>
0165     struct as_child<T, proto::default_generator, true>
0166     {
0167     #if BOOST_WORKAROUND(BOOST_MSVC, == 1310)
0168         typedef typename term_traits<T &>::reference reference;
0169     #else
0170         typedef T &reference;
0171     #endif
0172         typedef proto::basic_expr<proto::tag::terminal, term<reference>, 0> result_type;
0173 
0174         BOOST_FORCEINLINE
0175         result_type operator()(T &t) const
0176         {
0177             return result_type::make(t);
0178         }
0179     };
0180 
0181 }}}
0182 
0183 #if defined(_MSC_VER)
0184 # pragma warning(pop)
0185 #endif
0186 
0187 #endif