Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-16 10:07:35

0001 ///////////////////////////////////////////////////////////////////////////////
0002 /// \file pass_through.hpp
0003 ///
0004 /// Definition of the pass_through transform, which is the default transform
0005 /// of all of the expression generator metafunctions such as unary_plus<>, plus<>
0006 /// and nary_expr<>.
0007 //
0008 //  Copyright 2008 Eric Niebler. Distributed under the Boost
0009 //  Software License, Version 1.0. (See accompanying file
0010 //  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0011 
0012 #ifndef BOOST_PROTO_TRANSFORM_PASS_THROUGH_HPP_EAN_12_26_2006
0013 #define BOOST_PROTO_TRANSFORM_PASS_THROUGH_HPP_EAN_12_26_2006
0014 
0015 #include <boost/preprocessor/cat.hpp>
0016 #include <boost/preprocessor/repetition/enum.hpp>
0017 #include <boost/preprocessor/iteration/iterate.hpp>
0018 #include <boost/mpl/bool.hpp>
0019 #include <boost/mpl/if.hpp>
0020 #include <boost/type_traits/is_same.hpp>
0021 #include <boost/type_traits/remove_reference.hpp>
0022 #include <boost/proto/proto_fwd.hpp>
0023 #include <boost/proto/args.hpp>
0024 #include <boost/proto/transform/impl.hpp>
0025 #include <boost/proto/detail/ignore_unused.hpp>
0026 
0027 #if defined(_MSC_VER)
0028 # pragma warning(push)
0029 # pragma warning(disable : 4714) // function 'xxx' marked as __forceinline not inlined
0030 #endif
0031 
0032 namespace boost { namespace proto
0033 {
0034     namespace detail
0035     {
0036         template<
0037             typename Grammar
0038           , typename Domain
0039           , typename Expr
0040           , typename State
0041           , typename Data
0042           , long Arity = arity_of<Expr>::value
0043         >
0044         struct pass_through_impl
0045         {};
0046 
0047         #include <boost/proto/transform/detail/pass_through_impl.hpp>
0048 
0049         template<typename Grammar, typename Domain, typename Expr, typename State, typename Data>
0050         struct pass_through_impl<Grammar, Domain, Expr, State, Data, 0>
0051           : transform_impl<Expr, State, Data>
0052         {
0053             typedef Expr result_type;
0054 
0055             /// \param e An expression
0056             /// \return \c e
0057             /// \throw nothrow
0058             BOOST_FORCEINLINE
0059             BOOST_PROTO_RETURN_TYPE_STRICT_LOOSE(result_type, typename pass_through_impl::expr_param)
0060             operator()(
0061                 typename pass_through_impl::expr_param e
0062               , typename pass_through_impl::state_param
0063               , typename pass_through_impl::data_param
0064             ) const
0065             {
0066                 return e;
0067             }
0068         };
0069 
0070     } // namespace detail
0071 
0072     /// \brief A PrimitiveTransform that transforms the child expressions
0073     /// of an expression node according to the corresponding children of
0074     /// a Grammar.
0075     ///
0076     /// Given a Grammar such as <tt>plus\<T0, T1\></tt>, an expression type
0077     /// that matches the grammar such as <tt>plus\<E0, E1\>::type</tt>, a
0078     /// state \c S and a data \c V, the result of applying the
0079     /// <tt>pass_through\<plus\<T0, T1\> \></tt> transform is:
0080     ///
0081     /// \code
0082     /// plus<
0083     ///     T0::result<T0(E0, S, V)>::type
0084     ///   , T1::result<T1(E1, S, V)>::type
0085     /// >::type
0086     /// \endcode
0087     ///
0088     /// The above demonstrates how child transforms and child expressions
0089     /// are applied pairwise, and how the results are reassembled into a new
0090     /// expression node with the same tag type as the original.
0091     ///
0092     /// The explicit use of <tt>pass_through\<\></tt> is not usually needed,
0093     /// since the expression generator metafunctions such as
0094     /// <tt>plus\<\></tt> have <tt>pass_through\<\></tt> as their default
0095     /// transform. So, for instance, these are equivalent:
0096     ///
0097     /// \code
0098     /// // Within a grammar definition, these are equivalent:
0099     /// when< plus<X, Y>, pass_through< plus<X, Y> > >
0100     /// when< plus<X, Y>, plus<X, Y> >
0101     /// when< plus<X, Y> > // because of when<class X, class Y=X>
0102     /// plus<X, Y>         // because plus<> is both a
0103     ///                    //   grammar and a transform
0104     /// \endcode
0105     ///
0106     /// For example, consider the following transform that promotes all
0107     /// \c float terminals in an expression to \c double.
0108     ///
0109     /// \code
0110     /// // This transform finds all float terminals in an expression and promotes
0111     /// // them to doubles.
0112     /// struct Promote
0113     ///  : or_<
0114     ///         when<terminal<float>, terminal<double>::type(_value) >
0115     ///         // terminal<>'s default transform is a no-op:
0116     ///       , terminal<_>
0117     ///         // nary_expr<> has a pass_through<> transform:
0118     ///       , nary_expr<_, vararg<Promote> >
0119     ///     >
0120     /// {};
0121     /// \endcode
0122     template<typename Grammar, typename Domain /* = deduce_domain*/>
0123     struct pass_through
0124       : transform<pass_through<Grammar, Domain> >
0125     {
0126         template<typename Expr, typename State, typename Data>
0127         struct impl
0128           : detail::pass_through_impl<Grammar, Domain, Expr, State, Data>
0129         {};
0130     };
0131 
0132     /// INTERNAL ONLY
0133     ///
0134     template<typename Grammar, typename Domain>
0135     struct is_callable<pass_through<Grammar, Domain> >
0136       : mpl::true_
0137     {};
0138 
0139 }} // namespace boost::proto
0140 
0141 #if defined(_MSC_VER)
0142 # pragma warning(pop)
0143 #endif
0144 
0145 #endif