1 ///////////////////////////////////////////////////////////////////////////////
2 /// \file pass_through.hpp
4 /// Definition of the pass_through transform, which is the default transform
5 /// of all of the expression generator metafunctions such as unary_plus<>, plus<>
8 // Copyright 2008 Eric Niebler. Distributed under the Boost
9 // Software License, Version 1.0. (See accompanying file
10 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
12 #ifndef BOOST_PROTO_TRANSFORM_PASS_THROUGH_HPP_EAN_12_26_2006
13 #define BOOST_PROTO_TRANSFORM_PASS_THROUGH_HPP_EAN_12_26_2006
15 #include <boost/preprocessor/cat.hpp>
16 #include <boost/preprocessor/repetition/enum.hpp>
17 #include <boost/preprocessor/iteration/iterate.hpp>
18 #include <boost/mpl/bool.hpp>
19 #include <boost/mpl/if.hpp>
20 #include <boost/type_traits/is_same.hpp>
21 #include <boost/type_traits/remove_reference.hpp>
22 #include <boost/proto/proto_fwd.hpp>
23 #include <boost/proto/args.hpp>
24 #include <boost/proto/transform/impl.hpp>
25 #include <boost/proto/detail/ignore_unused.hpp>
28 # pragma warning(push)
29 # pragma warning(disable : 4714) // function 'xxx' marked as __forceinline not inlined
32 namespace boost { namespace proto
42 , long Arity = arity_of<Expr>::value
44 struct pass_through_impl
47 #include <boost/proto/transform/detail/pass_through_impl.hpp>
49 template<typename Grammar, typename Domain, typename Expr, typename State, typename Data>
50 struct pass_through_impl<Grammar, Domain, Expr, State, Data, 0>
51 : transform_impl<Expr, State, Data>
53 typedef Expr result_type;
55 /// \param e An expression
59 BOOST_PROTO_RETURN_TYPE_STRICT_LOOSE(result_type, typename pass_through_impl::expr_param)
61 typename pass_through_impl::expr_param e
62 , typename pass_through_impl::state_param
63 , typename pass_through_impl::data_param
72 /// \brief A PrimitiveTransform that transforms the child expressions
73 /// of an expression node according to the corresponding children of
76 /// Given a Grammar such as <tt>plus\<T0, T1\></tt>, an expression type
77 /// that matches the grammar such as <tt>plus\<E0, E1\>::type</tt>, a
78 /// state \c S and a data \c V, the result of applying the
79 /// <tt>pass_through\<plus\<T0, T1\> \></tt> transform is:
83 /// T0::result<T0(E0, S, V)>::type
84 /// , T1::result<T1(E1, S, V)>::type
88 /// The above demonstrates how child transforms and child expressions
89 /// are applied pairwise, and how the results are reassembled into a new
90 /// expression node with the same tag type as the original.
92 /// The explicit use of <tt>pass_through\<\></tt> is not usually needed,
93 /// since the expression generator metafunctions such as
94 /// <tt>plus\<\></tt> have <tt>pass_through\<\></tt> as their default
95 /// transform. So, for instance, these are equivalent:
98 /// // Within a grammar definition, these are equivalent:
99 /// when< plus<X, Y>, pass_through< plus<X, Y> > >
100 /// when< plus<X, Y>, plus<X, Y> >
101 /// when< plus<X, Y> > // because of when<class X, class Y=X>
102 /// plus<X, Y> // because plus<> is both a
103 /// // grammar and a transform
106 /// For example, consider the following transform that promotes all
107 /// \c float terminals in an expression to \c double.
110 /// // This transform finds all float terminals in an expression and promotes
111 /// // them to doubles.
114 /// when<terminal<float>, terminal<double>::type(_value) >
115 /// // terminal<>'s default transform is a no-op:
117 /// // nary_expr<> has a pass_through<> transform:
118 /// , nary_expr<_, vararg<Promote> >
122 template<typename Grammar, typename Domain /* = deduce_domain*/>
124 : transform<pass_through<Grammar, Domain> >
126 template<typename Expr, typename State, typename Data>
128 : detail::pass_through_impl<Grammar, Domain, Expr, State, Data>
134 template<typename Grammar, typename Domain>
135 struct is_callable<pass_through<Grammar, Domain> >
139 }} // namespace boost::proto
141 #if defined(_MSC_VER)
142 # pragma warning(pop)