Chris@16
|
1 ///////////////////////////////////////////////////////////////////////////////
|
Chris@16
|
2 /// \file pass_through.hpp
|
Chris@16
|
3 ///
|
Chris@16
|
4 /// Definition of the pass_through transform, which is the default transform
|
Chris@16
|
5 /// of all of the expression generator metafunctions such as unary_plus<>, plus<>
|
Chris@16
|
6 /// and nary_expr<>.
|
Chris@16
|
7 //
|
Chris@16
|
8 // Copyright 2008 Eric Niebler. Distributed under the Boost
|
Chris@16
|
9 // Software License, Version 1.0. (See accompanying file
|
Chris@16
|
10 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
11
|
Chris@16
|
12 #ifndef BOOST_PROTO_TRANSFORM_PASS_THROUGH_HPP_EAN_12_26_2006
|
Chris@16
|
13 #define BOOST_PROTO_TRANSFORM_PASS_THROUGH_HPP_EAN_12_26_2006
|
Chris@16
|
14
|
Chris@16
|
15 #include <boost/preprocessor/cat.hpp>
|
Chris@16
|
16 #include <boost/preprocessor/repetition/enum.hpp>
|
Chris@16
|
17 #include <boost/preprocessor/iteration/iterate.hpp>
|
Chris@16
|
18 #include <boost/mpl/bool.hpp>
|
Chris@16
|
19 #include <boost/mpl/if.hpp>
|
Chris@16
|
20 #include <boost/type_traits/is_same.hpp>
|
Chris@16
|
21 #include <boost/type_traits/remove_reference.hpp>
|
Chris@16
|
22 #include <boost/proto/proto_fwd.hpp>
|
Chris@16
|
23 #include <boost/proto/args.hpp>
|
Chris@16
|
24 #include <boost/proto/transform/impl.hpp>
|
Chris@16
|
25 #include <boost/proto/detail/ignore_unused.hpp>
|
Chris@16
|
26
|
Chris@101
|
27 #if defined(_MSC_VER)
|
Chris@16
|
28 # pragma warning(push)
|
Chris@16
|
29 # pragma warning(disable : 4714) // function 'xxx' marked as __forceinline not inlined
|
Chris@16
|
30 #endif
|
Chris@16
|
31
|
Chris@16
|
32 namespace boost { namespace proto
|
Chris@16
|
33 {
|
Chris@16
|
34 namespace detail
|
Chris@16
|
35 {
|
Chris@16
|
36 template<
|
Chris@16
|
37 typename Grammar
|
Chris@16
|
38 , typename Domain
|
Chris@16
|
39 , typename Expr
|
Chris@16
|
40 , typename State
|
Chris@16
|
41 , typename Data
|
Chris@16
|
42 , long Arity = arity_of<Expr>::value
|
Chris@16
|
43 >
|
Chris@16
|
44 struct pass_through_impl
|
Chris@16
|
45 {};
|
Chris@16
|
46
|
Chris@16
|
47 #include <boost/proto/transform/detail/pass_through_impl.hpp>
|
Chris@16
|
48
|
Chris@16
|
49 template<typename Grammar, typename Domain, typename Expr, typename State, typename Data>
|
Chris@16
|
50 struct pass_through_impl<Grammar, Domain, Expr, State, Data, 0>
|
Chris@16
|
51 : transform_impl<Expr, State, Data>
|
Chris@16
|
52 {
|
Chris@16
|
53 typedef Expr result_type;
|
Chris@16
|
54
|
Chris@16
|
55 /// \param e An expression
|
Chris@16
|
56 /// \return \c e
|
Chris@16
|
57 /// \throw nothrow
|
Chris@16
|
58 BOOST_FORCEINLINE
|
Chris@16
|
59 BOOST_PROTO_RETURN_TYPE_STRICT_LOOSE(result_type, typename pass_through_impl::expr_param)
|
Chris@16
|
60 operator()(
|
Chris@16
|
61 typename pass_through_impl::expr_param e
|
Chris@16
|
62 , typename pass_through_impl::state_param
|
Chris@16
|
63 , typename pass_through_impl::data_param
|
Chris@16
|
64 ) const
|
Chris@16
|
65 {
|
Chris@16
|
66 return e;
|
Chris@16
|
67 }
|
Chris@16
|
68 };
|
Chris@16
|
69
|
Chris@16
|
70 } // namespace detail
|
Chris@16
|
71
|
Chris@16
|
72 /// \brief A PrimitiveTransform that transforms the child expressions
|
Chris@16
|
73 /// of an expression node according to the corresponding children of
|
Chris@16
|
74 /// a Grammar.
|
Chris@16
|
75 ///
|
Chris@16
|
76 /// Given a Grammar such as <tt>plus\<T0, T1\></tt>, an expression type
|
Chris@16
|
77 /// that matches the grammar such as <tt>plus\<E0, E1\>::type</tt>, a
|
Chris@16
|
78 /// state \c S and a data \c V, the result of applying the
|
Chris@16
|
79 /// <tt>pass_through\<plus\<T0, T1\> \></tt> transform is:
|
Chris@16
|
80 ///
|
Chris@16
|
81 /// \code
|
Chris@16
|
82 /// plus<
|
Chris@16
|
83 /// T0::result<T0(E0, S, V)>::type
|
Chris@16
|
84 /// , T1::result<T1(E1, S, V)>::type
|
Chris@16
|
85 /// >::type
|
Chris@16
|
86 /// \endcode
|
Chris@16
|
87 ///
|
Chris@16
|
88 /// The above demonstrates how child transforms and child expressions
|
Chris@16
|
89 /// are applied pairwise, and how the results are reassembled into a new
|
Chris@16
|
90 /// expression node with the same tag type as the original.
|
Chris@16
|
91 ///
|
Chris@16
|
92 /// The explicit use of <tt>pass_through\<\></tt> is not usually needed,
|
Chris@16
|
93 /// since the expression generator metafunctions such as
|
Chris@16
|
94 /// <tt>plus\<\></tt> have <tt>pass_through\<\></tt> as their default
|
Chris@16
|
95 /// transform. So, for instance, these are equivalent:
|
Chris@16
|
96 ///
|
Chris@16
|
97 /// \code
|
Chris@16
|
98 /// // Within a grammar definition, these are equivalent:
|
Chris@16
|
99 /// when< plus<X, Y>, pass_through< plus<X, Y> > >
|
Chris@16
|
100 /// when< plus<X, Y>, plus<X, Y> >
|
Chris@16
|
101 /// when< plus<X, Y> > // because of when<class X, class Y=X>
|
Chris@16
|
102 /// plus<X, Y> // because plus<> is both a
|
Chris@16
|
103 /// // grammar and a transform
|
Chris@16
|
104 /// \endcode
|
Chris@16
|
105 ///
|
Chris@16
|
106 /// For example, consider the following transform that promotes all
|
Chris@16
|
107 /// \c float terminals in an expression to \c double.
|
Chris@16
|
108 ///
|
Chris@16
|
109 /// \code
|
Chris@16
|
110 /// // This transform finds all float terminals in an expression and promotes
|
Chris@16
|
111 /// // them to doubles.
|
Chris@16
|
112 /// struct Promote
|
Chris@16
|
113 /// : or_<
|
Chris@16
|
114 /// when<terminal<float>, terminal<double>::type(_value) >
|
Chris@16
|
115 /// // terminal<>'s default transform is a no-op:
|
Chris@16
|
116 /// , terminal<_>
|
Chris@16
|
117 /// // nary_expr<> has a pass_through<> transform:
|
Chris@16
|
118 /// , nary_expr<_, vararg<Promote> >
|
Chris@16
|
119 /// >
|
Chris@16
|
120 /// {};
|
Chris@16
|
121 /// \endcode
|
Chris@16
|
122 template<typename Grammar, typename Domain /* = deduce_domain*/>
|
Chris@16
|
123 struct pass_through
|
Chris@16
|
124 : transform<pass_through<Grammar, Domain> >
|
Chris@16
|
125 {
|
Chris@16
|
126 template<typename Expr, typename State, typename Data>
|
Chris@16
|
127 struct impl
|
Chris@16
|
128 : detail::pass_through_impl<Grammar, Domain, Expr, State, Data>
|
Chris@16
|
129 {};
|
Chris@16
|
130 };
|
Chris@16
|
131
|
Chris@16
|
132 /// INTERNAL ONLY
|
Chris@16
|
133 ///
|
Chris@16
|
134 template<typename Grammar, typename Domain>
|
Chris@16
|
135 struct is_callable<pass_through<Grammar, Domain> >
|
Chris@16
|
136 : mpl::true_
|
Chris@16
|
137 {};
|
Chris@16
|
138
|
Chris@16
|
139 }} // namespace boost::proto
|
Chris@16
|
140
|
Chris@101
|
141 #if defined(_MSC_VER)
|
Chris@16
|
142 # pragma warning(pop)
|
Chris@16
|
143 #endif
|
Chris@16
|
144
|
Chris@16
|
145 #endif
|