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