Chris@16: /////////////////////////////////////////////////////////////////////////////// Chris@16: /// \file pass_through.hpp Chris@16: /// Chris@16: /// Definition of the pass_through transform, which is the default transform Chris@16: /// of all of the expression generator metafunctions such as unary_plus<>, plus<> Chris@16: /// and nary_expr<>. Chris@16: // Chris@16: // Copyright 2008 Eric Niebler. Distributed under the Boost Chris@16: // Software License, Version 1.0. (See accompanying file Chris@16: // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) Chris@16: Chris@16: #ifndef BOOST_PROTO_TRANSFORM_PASS_THROUGH_HPP_EAN_12_26_2006 Chris@16: #define BOOST_PROTO_TRANSFORM_PASS_THROUGH_HPP_EAN_12_26_2006 Chris@16: Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: Chris@101: #if defined(_MSC_VER) Chris@16: # pragma warning(push) Chris@16: # pragma warning(disable : 4714) // function 'xxx' marked as __forceinline not inlined Chris@16: #endif Chris@16: Chris@16: namespace boost { namespace proto Chris@16: { Chris@16: namespace detail Chris@16: { Chris@16: template< Chris@16: typename Grammar Chris@16: , typename Domain Chris@16: , typename Expr Chris@16: , typename State Chris@16: , typename Data Chris@16: , long Arity = arity_of::value Chris@16: > Chris@16: struct pass_through_impl Chris@16: {}; Chris@16: Chris@16: #include Chris@16: Chris@16: template Chris@16: struct pass_through_impl Chris@16: : transform_impl Chris@16: { Chris@16: typedef Expr result_type; Chris@16: Chris@16: /// \param e An expression Chris@16: /// \return \c e Chris@16: /// \throw nothrow Chris@16: BOOST_FORCEINLINE Chris@16: BOOST_PROTO_RETURN_TYPE_STRICT_LOOSE(result_type, typename pass_through_impl::expr_param) Chris@16: operator()( Chris@16: typename pass_through_impl::expr_param e Chris@16: , typename pass_through_impl::state_param Chris@16: , typename pass_through_impl::data_param Chris@16: ) const Chris@16: { Chris@16: return e; Chris@16: } Chris@16: }; Chris@16: Chris@16: } // namespace detail Chris@16: Chris@16: /// \brief A PrimitiveTransform that transforms the child expressions Chris@16: /// of an expression node according to the corresponding children of Chris@16: /// a Grammar. Chris@16: /// Chris@16: /// Given a Grammar such as plus\, an expression type Chris@16: /// that matches the grammar such as plus\::type, a Chris@16: /// state \c S and a data \c V, the result of applying the Chris@16: /// pass_through\ \> transform is: Chris@16: /// Chris@16: /// \code Chris@16: /// plus< Chris@16: /// T0::result::type Chris@16: /// , T1::result::type Chris@16: /// >::type Chris@16: /// \endcode Chris@16: /// Chris@16: /// The above demonstrates how child transforms and child expressions Chris@16: /// are applied pairwise, and how the results are reassembled into a new Chris@16: /// expression node with the same tag type as the original. Chris@16: /// Chris@16: /// The explicit use of pass_through\<\> is not usually needed, Chris@16: /// since the expression generator metafunctions such as Chris@16: /// plus\<\> have pass_through\<\> as their default Chris@16: /// transform. So, for instance, these are equivalent: Chris@16: /// Chris@16: /// \code Chris@16: /// // Within a grammar definition, these are equivalent: Chris@16: /// when< plus, pass_through< plus > > Chris@16: /// when< plus, plus > Chris@16: /// when< plus > // because of when Chris@16: /// plus // because plus<> is both a Chris@16: /// // grammar and a transform Chris@16: /// \endcode Chris@16: /// Chris@16: /// For example, consider the following transform that promotes all Chris@16: /// \c float terminals in an expression to \c double. Chris@16: /// Chris@16: /// \code Chris@16: /// // This transform finds all float terminals in an expression and promotes Chris@16: /// // them to doubles. Chris@16: /// struct Promote Chris@16: /// : or_< Chris@16: /// when, terminal::type(_value) > Chris@16: /// // terminal<>'s default transform is a no-op: Chris@16: /// , terminal<_> Chris@16: /// // nary_expr<> has a pass_through<> transform: Chris@16: /// , nary_expr<_, vararg > Chris@16: /// > Chris@16: /// {}; Chris@16: /// \endcode Chris@16: template Chris@16: struct pass_through Chris@16: : transform > Chris@16: { Chris@16: template Chris@16: struct impl Chris@16: : detail::pass_through_impl Chris@16: {}; Chris@16: }; Chris@16: Chris@16: /// INTERNAL ONLY Chris@16: /// Chris@16: template Chris@16: struct is_callable > Chris@16: : mpl::true_ Chris@16: {}; Chris@16: Chris@16: }} // namespace boost::proto Chris@16: Chris@101: #if defined(_MSC_VER) Chris@16: # pragma warning(pop) Chris@16: #endif Chris@16: Chris@16: #endif