Project revived from Feb2017
[EroSomnia.git] / deps / boost_1_63_0 / boost / proto / transform / arg.hpp
blob9fdf80e5b4a5203f01c704f75b21066bc481845d
1 ///////////////////////////////////////////////////////////////////////////////
2 /// \file arg.hpp
3 /// Contains definition of the argN transforms.
4 //
5 // Copyright 2008 Eric Niebler. Distributed under the Boost
6 // Software License, Version 1.0. (See accompanying file
7 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
9 #ifndef BOOST_PROTO_TRANSFORM_ARG_HPP_EAN_11_01_2007
10 #define BOOST_PROTO_TRANSFORM_ARG_HPP_EAN_11_01_2007
12 #include <boost/mpl/if.hpp>
13 #include <boost/proto/proto_fwd.hpp>
14 #include <boost/proto/traits.hpp>
15 #include <boost/proto/transform/impl.hpp>
16 #include <boost/type_traits/is_array.hpp>
17 #include <boost/proto/transform/env.hpp>
19 namespace boost { namespace proto
22 /// \brief A PrimitiveTransform that returns the current expression
23 /// unmodified
24 ///
25 /// Example:
26 ///
27 /// \code
28 /// proto::terminal<int>::type i = {42};
29 /// proto::terminal<int>::type & j = proto::_expr()(i);
30 /// assert( boost::addressof(i) == boost::addressof(j) );
31 /// \endcode
32 struct _expr : transform<_expr>
34 template<typename Expr, typename State, typename Data>
35 struct impl : transform_impl<Expr, State, Data>
37 typedef Expr result_type;
39 /// Returns the current expression.
40 /// \param e The current expression.
41 /// \return \c e
42 /// \throw nothrow
43 BOOST_PROTO_RETURN_TYPE_STRICT_LOOSE(result_type, typename impl::expr_param)
44 operator()(
45 typename impl::expr_param e
46 , typename impl::state_param
47 , typename impl::data_param
48 ) const
50 return e;
55 /// \brief A PrimitiveTransform that returns the current state
56 /// unmodified
57 ///
58 /// Example:
59 ///
60 /// \code
61 /// proto::terminal<int>::type i = {42};
62 /// char ch = proto::_state()(i, 'a');
63 /// assert( ch == 'a' );
64 /// \endcode
65 struct _state : transform<_state>
67 template<typename Expr, typename State, typename Data>
68 struct impl : transform_impl<Expr, State, Data>
70 typedef State result_type;
72 /// Returns the current state.
73 /// \param s The current state.
74 /// \return \c s
75 /// \throw nothrow
76 BOOST_PROTO_RETURN_TYPE_STRICT_LOOSE(result_type, typename impl::state_param)
77 operator ()(
78 typename impl::expr_param
79 , typename impl::state_param s
80 , typename impl::data_param
81 ) const
83 return s;
88 /// \brief A PrimitiveTransform that returns the current data
89 /// unmodified
90 ///
91 /// Example:
92 ///
93 /// \code
94 /// proto::terminal<int>::type i = {42};
95 /// std::string str("hello");
96 /// std::string & data = proto::_data()(i, 'a', str);
97 /// assert( &str == &data );
98 /// \endcode
99 struct _data : transform<_data>
101 template<typename Expr, typename State, typename Data>
102 struct impl
103 : mpl::if_c<
104 is_env<Data>::value
105 , _env_var<data_type>
106 , _env
107 >::type::template impl<Expr, State, Data>
111 /// \brief A PrimitiveTransform that returns N-th child of the current
112 /// expression.
114 /// Example:
116 /// \code
117 /// proto::terminal<int>::type i = {42};
118 /// proto::terminal<int>::type & j = proto::_child_c<0>()(-i);
119 /// assert( boost::addressof(i) == boost::addressof(j) );
120 /// \endcode
121 template<int N>
122 struct _child_c : transform<_child_c<N> >
124 template<typename Expr, typename State, typename Data>
125 struct impl : transform_impl<Expr, State, Data>
127 typedef
128 typename result_of::child_c<Expr, N>::type
129 result_type;
131 /// Returns the N-th child of \c e
132 /// \pre <tt>arity_of\<Expr\>::value \> N</tt>
133 /// \param e The current expression.
134 /// \return <tt>proto::child_c\<N\>(e)</tt>
135 /// \throw nothrow
136 #ifdef BOOST_PROTO_STRICT_RESULT_OF
137 result_type
138 #else
139 typename result_of::child_c<typename impl::expr_param, N>::type
140 #endif
141 operator ()(
142 typename impl::expr_param e
143 , typename impl::state_param
144 , typename impl::data_param
145 ) const
147 return proto::child_c<N>(e);
152 /// \brief A PrimitiveTransform that returns the value of the
153 /// current terminal expression.
155 /// Example:
157 /// \code
158 /// proto::terminal<int>::type i = {42};
159 /// int j = proto::_value()(i);
160 /// assert( 42 == j );
161 /// \endcode
162 struct _value : transform<_value>
164 template<typename Expr, typename State, typename Data>
165 struct impl : transform_impl<Expr, State, Data>
167 typedef
168 typename result_of::value<Expr>::type
169 result_type;
171 /// Returns the value of the specified terminal expression.
172 /// \pre <tt>arity_of\<Expr\>::value == 0</tt>.
173 /// \param e The current expression.
174 /// \return <tt>proto::value(e)</tt>
175 /// \throw nothrow
176 #ifdef BOOST_PROTO_STRICT_RESULT_OF
177 typename mpl::if_c<is_array<result_type>::value, result_type &, result_type>::type
178 #else
179 typename result_of::value<typename impl::expr_param>::type
180 #endif
181 operator ()(
182 typename impl::expr_param e
183 , typename impl::state_param
184 , typename impl::data_param
185 ) const
187 return proto::value(e);
192 /// \brief A PrimitiveTransform that does nothing
193 /// and returns void.
194 struct _void : transform<_void>
196 template<typename Expr, typename State, typename Data>
197 struct impl : transform_impl<Expr, State, Data>
199 typedef void result_type;
201 /// Does nothing and returns void
202 void operator ()(
203 typename impl::expr_param
204 , typename impl::state_param
205 , typename impl::data_param
206 ) const
211 /// \brief A unary CallableTransform that wraps its argument
212 /// in a \c boost::reference_wrapper\<\>.
214 /// Example:
216 /// \code
217 /// proto::terminal<int>::type i = {42};
218 /// boost::reference_wrapper<proto::terminal<int>::type> j
219 /// = proto::when<_, proto::_byref(_)>()(i);
220 /// assert( boost::addressof(i) == boost::addressof(j.get()) );
221 /// \endcode
222 struct _byref : callable
224 template<typename Sig>
225 struct result;
227 template<typename This, typename T>
228 struct result<This(T)>
230 typedef boost::reference_wrapper<T const> const type;
233 template<typename This, typename T>
234 struct result<This(T &)>
236 typedef boost::reference_wrapper<T> const type;
239 /// Wrap the parameter \c t in a \c boost::reference_wrapper\<\>
240 /// \param t The object to wrap
241 /// \return <tt>boost::ref(t)</tt>
242 /// \throw nothrow
243 template<typename T>
244 boost::reference_wrapper<T> const operator ()(T &t) const
246 return boost::reference_wrapper<T>(t);
249 /// \overload
251 template<typename T>
252 boost::reference_wrapper<T const> const operator ()(T const &t) const
254 return boost::reference_wrapper<T const>(t);
258 /// \brief A unary CallableTransform that strips references
259 /// and \c boost::reference_wrapper\<\> from its argument.
261 /// Example:
263 /// \code
264 /// proto::terminal<int>::type i = {42};
265 /// int j = 67;
266 /// int k = proto::when<_, proto::_byval(proto::_state)>()(i, boost::ref(j));
267 /// assert( 67 == k );
268 /// \endcode
269 struct _byval : callable
271 template<typename Sig>
272 struct result;
274 template<typename This, typename T>
275 struct result<This(T)>
277 typedef T type;
280 template<typename This, typename T>
281 struct result<This(T &)>
282 : result<This(T)>
285 template<typename This, typename T>
286 struct result<This(boost::reference_wrapper<T>)>
287 : result<This(T)>
290 /// \param t The object to unref
291 /// \return <tt>t</tt>
292 /// \throw nothrow
293 template<typename T>
294 T operator ()(T const &t) const
296 return t;
299 /// \overload
301 template<typename T>
302 T operator ()(boost::reference_wrapper<T> const &t) const
304 return t;
308 /// INTERNAL ONLY
310 template<>
311 struct is_callable<_expr>
312 : mpl::true_
315 /// INTERNAL ONLY
317 template<>
318 struct is_callable<_state>
319 : mpl::true_
322 /// INTERNAL ONLY
324 template<>
325 struct is_callable<_data>
326 : mpl::true_
329 /// INTERNAL ONLY
331 template<int N>
332 struct is_callable<_child_c<N> >
333 : mpl::true_
336 /// INTERNAL ONLY
338 template<>
339 struct is_callable<_value>
340 : mpl::true_
343 /// INTERNAL ONLY
345 template<>
346 struct is_callable<_byref>
347 : mpl::true_
350 /// INTERNAL ONLY
352 template<>
353 struct is_callable<_byval>
354 : mpl::true_
359 #endif