Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:50:32

0001 ///////////////////////////////////////////////////////////////////////////////
0002 /// \file deep_copy.hpp
0003 /// Replace all nodes stored by reference by nodes stored by value.
0004 //
0005 //  Copyright 2008 Eric Niebler. Distributed under the Boost
0006 //  Software License, Version 1.0. (See accompanying file
0007 //  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0008 
0009 #ifndef BOOST_PROTO_DEEP_COPY_HPP_EAN_11_21_2006
0010 #define BOOST_PROTO_DEEP_COPY_HPP_EAN_11_21_2006
0011 
0012 #include <boost/preprocessor/cat.hpp>
0013 #include <boost/preprocessor/repetition/enum.hpp>
0014 #include <boost/preprocessor/iteration/iterate.hpp>
0015 #include <boost/mpl/if.hpp>
0016 #include <boost/type_traits/remove_reference.hpp>
0017 #include <boost/proto/proto_fwd.hpp>
0018 #include <boost/proto/args.hpp>
0019 #include <boost/proto/expr.hpp>
0020 
0021 namespace boost { namespace proto
0022 {
0023     namespace detail
0024     {
0025         template<typename Expr, long Arity = Expr::proto_arity_c>
0026         struct deep_copy_impl;
0027 
0028         template<typename Expr>
0029         struct deep_copy_impl<Expr, 0>
0030         {
0031             typedef
0032                 typename base_expr<
0033                     typename Expr::proto_domain
0034                   , tag::terminal
0035                   , term<typename term_traits<typename Expr::proto_child0>::value_type>
0036                 >::type
0037             expr_type;
0038 
0039             typedef typename Expr::proto_generator proto_generator;
0040             typedef typename proto_generator::template result<proto_generator(expr_type)>::type result_type;
0041 
0042             template<typename Expr2, typename S, typename D>
0043             result_type operator()(Expr2 const &e, S const &, D const &) const
0044             {
0045                 return proto_generator()(expr_type::make(e.proto_base().child0));
0046             }
0047         };
0048     }
0049 
0050     namespace result_of
0051     {
0052         /// \brief A metafunction for calculating the return type
0053         /// of \c proto::deep_copy().
0054         ///
0055         /// A metafunction for calculating the return type
0056         /// of \c proto::deep_copy(). The type parameter \c Expr
0057         /// should be the type of a Proto expression tree.
0058         /// It should not be a reference type, nor should it
0059         /// be cv-qualified.
0060         template<typename Expr>
0061         struct deep_copy
0062         {
0063             typedef
0064                 typename detail::deep_copy_impl<
0065                     BOOST_PROTO_UNCVREF(Expr)
0066                 >::result_type
0067             type;
0068         };
0069     }
0070 
0071     namespace functional
0072     {
0073         /// \brief A PolymorphicFunctionObject type for deep-copying
0074         /// Proto expression trees.
0075         ///
0076         /// A PolymorphicFunctionObject type for deep-copying
0077         /// Proto expression trees. When a tree is deep-copied,
0078         /// all internal nodes and most terminals held by reference
0079         /// are instead held by value.
0080         ///
0081         /// \attention Terminals of reference-to-function type are
0082         /// left unchanged. Terminals of reference-to-array type are
0083         /// stored by value, which can cause a large amount of data
0084         /// to be passed by value and stored on the stack.
0085         struct deep_copy
0086         {
0087             BOOST_PROTO_CALLABLE()
0088 
0089             template<typename Sig>
0090             struct result;
0091 
0092             template<typename This, typename Expr>
0093             struct result<This(Expr)>
0094             {
0095                 typedef
0096                     typename detail::deep_copy_impl<
0097                         BOOST_PROTO_UNCVREF(Expr)
0098                     >::result_type
0099                 type;
0100             };
0101 
0102             /// \brief Deep-copies a Proto expression tree, turning all
0103             /// nodes and terminals held by reference into ones held by
0104             /// value.
0105             template<typename Expr>
0106             typename result_of::deep_copy<Expr>::type
0107             operator()(Expr const &e) const
0108             {
0109                 return proto::detail::deep_copy_impl<Expr>()(e, 0, 0);
0110             }
0111         };
0112     }
0113 
0114     /// \brief A function for deep-copying
0115     /// Proto expression trees.
0116     ///
0117     /// A function for deep-copying
0118     /// Proto expression trees. When a tree is deep-copied,
0119     /// all internal nodes and most terminals held by reference
0120     /// are instead held by value.
0121     ///
0122     /// \attention Terminals of reference-to-function type are
0123     /// left unchanged.
0124     ///
0125     /// \sa proto::functional::deep_copy.
0126     template<typename Expr>
0127     typename proto::result_of::deep_copy<Expr>::type
0128     deep_copy(Expr const &e)
0129     {
0130         return proto::detail::deep_copy_impl<Expr>()(e, 0, 0);
0131     }
0132 
0133     /// \brief A PrimitiveTransform for deep-copying
0134     /// Proto expression trees.
0135     ///
0136     /// A PrimitiveTransform for deep-copying
0137     /// Proto expression trees. When a tree is deep-copied,
0138     /// all internal nodes and most terminals held by reference
0139     /// are instead held by value.
0140     ///
0141     /// \attention Terminals of reference-to-function type are
0142     /// left unchanged.
0143     ///
0144     /// \sa proto::functional::deep_copy.
0145     struct _deep_copy
0146       : proto::transform<_deep_copy>
0147     {
0148         template<typename E, typename S, typename D>
0149         struct impl
0150           : detail::deep_copy_impl<BOOST_PROTO_UNCVREF(E)>
0151         {};
0152     };
0153 
0154     namespace detail
0155     {
0156         // include the definition of deep_copy_impl
0157         #include <boost/proto/detail/deep_copy.hpp>
0158     }
0159 
0160 }}
0161 
0162 #endif // BOOST_PROTO_COMPILER_DEEP_COPY_HPP_EAN_11_21_2006
0163