PageRenderTime 83ms CodeModel.GetById 66ms app.highlight 15ms RepoModel.GetById 1ms app.codeStats 0ms

/Src/Dependencies/Boost/boost/proto/detail/as_expr.hpp

http://hadesmem.googlecode.com/
C++ Header | 170 lines | 125 code | 25 blank | 20 comment | 4 complexity | 39dbd896040bcb1da12c68f00d987cc3 MD5 | raw file
  1///////////////////////////////////////////////////////////////////////////////
  2/// \file as_expr.hpp
  3/// Contains definition of the as_expr\<\> and as_child\<\> helper class
  4/// templates used to implement proto::domain's as_expr\<\> and as_child\<\>
  5/// member templates.
  6//
  7//  Copyright 2010 Eric Niebler. Distributed under the Boost
  8//  Software License, Version 1.0. (See accompanying file
  9//  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
 10
 11#ifndef BOOST_PROTO_DETAIL_AS_EXPR_HPP_EAN_06_09_2010
 12#define BOOST_PROTO_DETAIL_AS_EXPR_HPP_EAN_06_09_2010
 13
 14#include <boost/config.hpp>
 15#include <boost/detail/workaround.hpp>
 16#include <boost/type_traits/remove_const.hpp>
 17#include <boost/proto/proto_fwd.hpp>
 18#include <boost/proto/args.hpp>
 19
 20namespace boost { namespace proto { namespace detail
 21{
 22
 23    ////////////////////////////////////////////////////////////////////////////////////////////////
 24    template<typename Generator>
 25    struct base_generator
 26    {
 27        typedef Generator type;
 28    };
 29
 30    template<typename Generator>
 31    struct base_generator<use_basic_expr<Generator> >
 32    {
 33        typedef Generator type;
 34    };
 35
 36    ////////////////////////////////////////////////////////////////////////////////////////////////
 37    template<typename T, typename Generator, bool WantsBasicExpr>
 38    struct as_expr;
 39
 40    ////////////////////////////////////////////////////////////////////////////////////////////////
 41    template<typename T, typename Generator>
 42    struct as_expr<T, Generator, false>
 43    {
 44        typedef typename term_traits<T &>::value_type value_type;
 45        typedef proto::expr<proto::tag::terminal, term<value_type>, 0> expr_type;
 46        typedef typename Generator::template result<Generator(expr_type)>::type result_type;
 47
 48        result_type operator()(T &t) const
 49        {
 50            return Generator()(expr_type::make(t));
 51        }
 52    };
 53
 54    ////////////////////////////////////////////////////////////////////////////////////////////////
 55    template<typename T, typename Generator>
 56    struct as_expr<T, Generator, true>
 57    {
 58        typedef typename term_traits<T &>::value_type value_type;
 59        typedef proto::basic_expr<proto::tag::terminal, term<value_type>, 0> expr_type;
 60        typedef typename Generator::template result<Generator(expr_type)>::type result_type;
 61
 62        result_type operator()(T &t) const
 63        {
 64            return Generator()(expr_type::make(t));
 65        }
 66    };
 67
 68    ////////////////////////////////////////////////////////////////////////////////////////////////
 69    template<typename T>
 70    struct as_expr<T, proto::default_generator, false>
 71    {
 72        typedef typename term_traits<T &>::value_type value_type;
 73        typedef proto::expr<proto::tag::terminal, term<value_type>, 0> result_type;
 74
 75        result_type operator()(T &t) const
 76        {
 77            return result_type::make(t);
 78        }
 79    };
 80
 81    ////////////////////////////////////////////////////////////////////////////////////////////////
 82    template<typename T>
 83    struct as_expr<T, proto::default_generator, true>
 84    {
 85        typedef typename term_traits<T &>::value_type value_type;
 86        typedef proto::basic_expr<proto::tag::terminal, term<value_type>, 0> result_type;
 87
 88        result_type operator()(T &t) const
 89        {
 90            return result_type::make(t);
 91        }
 92    };
 93
 94    ////////////////////////////////////////////////////////////////////////////////////////////////
 95    template<typename T, typename Generator, bool WantsBasicExpr>
 96    struct as_child;
 97
 98    ////////////////////////////////////////////////////////////////////////////////////////////////
 99    template<typename T, typename Generator>
100    struct as_child<T, Generator, false>
101    {
102    #if BOOST_WORKAROUND(BOOST_MSVC, == 1310)
103        typedef typename term_traits<T &>::reference reference;
104    #else
105        typedef T &reference;
106    #endif
107        typedef proto::expr<proto::tag::terminal, term<reference>, 0> expr_type;
108        typedef typename Generator::template result<Generator(expr_type)>::type result_type;
109
110        result_type operator()(T &t) const
111        {
112            return Generator()(expr_type::make(t));
113        }
114    };
115
116    ////////////////////////////////////////////////////////////////////////////////////////////////
117    template<typename T, typename Generator>
118    struct as_child<T, Generator, true>
119    {
120    #if BOOST_WORKAROUND(BOOST_MSVC, == 1310)
121        typedef typename term_traits<T &>::reference reference;
122    #else
123        typedef T &reference;
124    #endif
125        typedef proto::basic_expr<proto::tag::terminal, term<reference>, 0> expr_type;
126        typedef typename Generator::template result<Generator(expr_type)>::type result_type;
127
128        result_type operator()(T &t) const
129        {
130            return Generator()(expr_type::make(t));
131        }
132    };
133
134    ////////////////////////////////////////////////////////////////////////////////////////////////
135    template<typename T>
136    struct as_child<T, proto::default_generator, false>
137    {
138    #if BOOST_WORKAROUND(BOOST_MSVC, == 1310)
139        typedef typename term_traits<T &>::reference reference;
140    #else
141        typedef T &reference;
142    #endif
143        typedef proto::expr<proto::tag::terminal, term<reference>, 0> result_type;
144
145        result_type operator()(T &t) const
146        {
147            return result_type::make(t);
148        }
149    };
150
151    ////////////////////////////////////////////////////////////////////////////////////////////////
152    template<typename T>
153    struct as_child<T, proto::default_generator, true>
154    {
155    #if BOOST_WORKAROUND(BOOST_MSVC, == 1310)
156        typedef typename term_traits<T &>::reference reference;
157    #else
158        typedef T &reference;
159    #endif
160        typedef proto::basic_expr<proto::tag::terminal, term<reference>, 0> result_type;
161
162        result_type operator()(T &t) const
163        {
164            return result_type::make(t);
165        }
166    };
167
168}}}
169
170#endif