Chris@16: /////////////////////////////////////////////////////////////////////////////// Chris@16: /// \file deep_copy.hpp Chris@16: /// Replace all nodes stored by reference by nodes stored by value. 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_DEEP_COPY_HPP_EAN_11_21_2006 Chris@16: #define BOOST_PROTO_DEEP_COPY_HPP_EAN_11_21_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: Chris@16: namespace boost { namespace proto Chris@16: { Chris@16: namespace detail Chris@16: { Chris@16: template Chris@16: struct deep_copy_impl; Chris@16: Chris@16: template Chris@16: struct deep_copy_impl Chris@16: { Chris@16: typedef Chris@16: typename base_expr< Chris@16: typename Expr::proto_domain Chris@16: , tag::terminal Chris@16: , term::value_type> Chris@16: >::type Chris@16: expr_type; Chris@16: Chris@16: typedef typename Expr::proto_generator proto_generator; Chris@16: typedef typename proto_generator::template result::type result_type; Chris@16: Chris@16: template Chris@16: result_type operator()(Expr2 const &e, S const &, D const &) const Chris@16: { Chris@16: return proto_generator()(expr_type::make(e.proto_base().child0)); Chris@16: } Chris@16: }; Chris@16: } Chris@16: Chris@16: namespace result_of Chris@16: { Chris@16: /// \brief A metafunction for calculating the return type Chris@16: /// of \c proto::deep_copy(). Chris@16: /// Chris@16: /// A metafunction for calculating the return type Chris@16: /// of \c proto::deep_copy(). The type parameter \c Expr Chris@16: /// should be the type of a Proto expression tree. Chris@16: /// It should not be a reference type, nor should it Chris@16: /// be cv-qualified. Chris@16: template Chris@16: struct deep_copy Chris@16: { Chris@16: typedef Chris@16: typename detail::deep_copy_impl< Chris@16: BOOST_PROTO_UNCVREF(Expr) Chris@16: >::result_type Chris@16: type; Chris@16: }; Chris@16: } Chris@16: Chris@16: namespace functional Chris@16: { Chris@16: /// \brief A PolymorphicFunctionObject type for deep-copying Chris@16: /// Proto expression trees. Chris@16: /// Chris@16: /// A PolymorphicFunctionObject type for deep-copying Chris@16: /// Proto expression trees. When a tree is deep-copied, Chris@16: /// all internal nodes and most terminals held by reference Chris@16: /// are instead held by value. Chris@16: /// Chris@16: /// \attention Terminals of reference-to-function type are Chris@16: /// left unchanged. Terminals of reference-to-array type are Chris@16: /// stored by value, which can cause a large amount of data Chris@16: /// to be passed by value and stored on the stack. Chris@16: struct deep_copy Chris@16: { Chris@16: BOOST_PROTO_CALLABLE() Chris@16: Chris@16: template Chris@16: struct result; Chris@16: Chris@16: template Chris@16: struct result Chris@16: { Chris@16: typedef Chris@16: typename detail::deep_copy_impl< Chris@16: BOOST_PROTO_UNCVREF(Expr) Chris@16: >::result_type Chris@16: type; Chris@16: }; Chris@16: Chris@16: /// \brief Deep-copies a Proto expression tree, turning all Chris@16: /// nodes and terminals held by reference into ones held by Chris@16: /// value. Chris@16: template Chris@16: typename result_of::deep_copy::type Chris@16: operator()(Expr const &e) const Chris@16: { Chris@16: return proto::detail::deep_copy_impl()(e, 0, 0); Chris@16: } Chris@16: }; Chris@16: } Chris@16: Chris@16: /// \brief A function for deep-copying Chris@16: /// Proto expression trees. Chris@16: /// Chris@16: /// A function for deep-copying Chris@16: /// Proto expression trees. When a tree is deep-copied, Chris@16: /// all internal nodes and most terminals held by reference Chris@16: /// are instead held by value. Chris@16: /// Chris@16: /// \attention Terminals of reference-to-function type are Chris@16: /// left unchanged. Chris@16: /// Chris@16: /// \sa proto::functional::deep_copy. Chris@16: template Chris@16: typename proto::result_of::deep_copy::type Chris@16: deep_copy(Expr const &e) Chris@16: { Chris@16: return proto::detail::deep_copy_impl()(e, 0, 0); Chris@16: } Chris@16: Chris@16: /// \brief A PrimitiveTransform for deep-copying Chris@16: /// Proto expression trees. Chris@16: /// Chris@16: /// A PrimitiveTransform for deep-copying Chris@16: /// Proto expression trees. When a tree is deep-copied, Chris@16: /// all internal nodes and most terminals held by reference Chris@16: /// are instead held by value. Chris@16: /// Chris@16: /// \attention Terminals of reference-to-function type are Chris@16: /// left unchanged. Chris@16: /// Chris@16: /// \sa proto::functional::deep_copy. Chris@16: struct _deep_copy Chris@16: : proto::transform<_deep_copy> Chris@16: { Chris@16: template Chris@16: struct impl Chris@16: : detail::deep_copy_impl Chris@16: {}; Chris@16: }; Chris@16: Chris@16: namespace detail Chris@16: { Chris@16: // include the definition of deep_copy_impl Chris@16: #include Chris@16: } Chris@16: Chris@16: }} Chris@16: Chris@16: #endif // BOOST_PROTO_COMPILER_DEEP_COPY_HPP_EAN_11_21_2006 Chris@16: