Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r68314 - trunk/boost/proto
From: eric_at_[hidden]
Date: 2011-01-19 23:06:22


Author: eric_niebler
Date: 2011-01-19 23:06:20 EST (Wed, 19 Jan 2011)
New Revision: 68314
URL: http://svn.boost.org/trac/boost/changeset/68314

Log:
display_expr is copyable, fixes #5096
Text files modified:
   trunk/boost/proto/debug.hpp | 66 ++++++++++++++++++++++++++-------------
   1 files changed, 44 insertions(+), 22 deletions(-)

Modified: trunk/boost/proto/debug.hpp
==============================================================================
--- trunk/boost/proto/debug.hpp (original)
+++ trunk/boost/proto/debug.hpp 2011-01-19 23:06:20 EST (Wed, 19 Jan 2011)
@@ -11,6 +11,7 @@
 
 #include <iostream>
 #include <boost/preprocessor/stringize.hpp>
+#include <boost/ref.hpp>
 #include <boost/mpl/assert.hpp>
 #include <boost/proto/proto_fwd.hpp>
 #include <boost/proto/traits.hpp>
@@ -108,32 +109,16 @@
         }
     }
 
- namespace functional
+ namespace detail
     {
- /// \brief Pretty-print a Proto expression tree.
- ///
- /// A PolymorphicFunctionObject which accepts a Proto expression
- /// tree and pretty-prints it to an \c ostream for debugging
- /// purposes.
- struct display_expr
+ struct display_expr_impl
         {
- BOOST_PROTO_CALLABLE()
-
- typedef void result_type;
-
- /// \param sout The \c ostream to which the expression tree
- /// will be written.
- /// \param depth The starting indentation depth for this node.
- /// Children nodes will be displayed at a starting
- /// depth of <tt>depth+4</tt>.
- explicit display_expr(std::ostream &sout = std::cout, int depth = 0)
+ explicit display_expr_impl(std::ostream &sout, int depth = 0)
               : depth_(depth)
               , first_(true)
               , sout_(sout)
             {}
 
- /// \brief Pretty-print the current node in a Proto expression
- /// tree.
             template<typename Expr>
             void operator()(Expr const &expr) const
             {
@@ -141,8 +126,8 @@
             }
 
         private:
- display_expr(display_expr const &);
- display_expr &operator =(display_expr const &);
+ display_expr_impl(display_expr_impl const &);
+ display_expr_impl &operator =(display_expr_impl const &);
 
             template<typename Expr>
             void impl(Expr const &expr, mpl::long_<0>) const
@@ -163,7 +148,7 @@
                 this->sout_.width(this->depth_);
                 this->sout_ << (this->first_? "" : ", ");
                 this->sout_ << tag() << "(\n";
- display_expr display(this->sout_, this->depth_ + 4);
+ display_expr_impl display(this->sout_, this->depth_ + 4);
                 fusion::for_each(expr, display);
                 this->sout_.width(this->depth_);
                 this->sout_ << "" << ")\n";
@@ -176,6 +161,43 @@
         };
     }
 
+ namespace functional
+ {
+ /// \brief Pretty-print a Proto expression tree.
+ ///
+ /// A PolymorphicFunctionObject which accepts a Proto expression
+ /// tree and pretty-prints it to an \c ostream for debugging
+ /// purposes.
+ struct display_expr
+ {
+ BOOST_PROTO_CALLABLE()
+
+ typedef void result_type;
+
+ /// \param sout The \c ostream to which the expression tree
+ /// will be written.
+ /// \param depth The starting indentation depth for this node.
+ /// Children nodes will be displayed at a starting
+ /// depth of <tt>depth+4</tt>.
+ explicit display_expr(std::ostream &sout = std::cout, int depth = 0)
+ : depth_(depth)
+ , sout_(sout)
+ {}
+
+ /// \brief Pretty-print the current node in a Proto expression
+ /// tree.
+ template<typename Expr>
+ void operator()(Expr const &expr) const
+ {
+ detail::display_expr_impl(this->sout_, this->depth_)(expr);
+ }
+
+ private:
+ int depth_;
+ reference_wrapper<std::ostream> sout_;
+ };
+ }
+
     /// \brief Pretty-print a Proto expression tree.
     ///
     /// \note Equivalent to <tt>functional::display_expr(0, sout)(expr)</tt>


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk