--- boost/proto/debug-1.44.0.hpp 2010-06-11 00:03:27.000000000 +0900 +++ boost/proto/debug.hpp 2010-11-30 11:32:30.000000000 +0900 @@ -84,22 +84,41 @@ namespace hidden_detail_ { - struct ostream_wrapper - { - ostream_wrapper(std::ostream &sout) - : sout_(sout) - {} + struct yes_type { char x; }; + struct no_type { yes_type x[2]; }; - std::ostream &sout_; - }; + no_type has_ostream_shift(...); - template - std::ostream &operator <<(ostream_wrapper sout_wrap, Tag const &) - { - return sout_wrap.sout_ << typeid(Tag).name(); - } + template + typename boost::enable_if_c< + sizeof(*(std::ostream*)NULL << *(T*)NULL) + , yes_type >::type + has_ostream_shift(const T&); + + template + struct Out + { + template static void out( std::ostream& os, const T& x ); + }; + + template<> template inline + void Out::out( std::ostream& os, const T& x ) + { + os << x; + } + + template<> template inline + void Out::out( std::ostream& os, const T& x ) + { + os << typeid(T).name(); + } + + template inline + void out( std::ostream& os, const T& x ) + { + Out< sizeof(has_ostream_shift(*(T*)NULL)) == sizeof(yes_type) >::out( os, x ); + } } - namespace functional { /// \brief Pretty-print a Proto expression tree. @@ -139,20 +158,22 @@ template void impl(Expr const &expr, mpl::long_<0>) const { - using namespace hidden_detail_; typedef typename tag_of::type tag; this->sout_ << std::setw(this->depth_) << (this->first_? "" : ", "); - this->sout_ << tag() << "(" << proto::value(expr) << ")\n"; + hidden_detail_::out( this->sout_, tag() ); + this->sout_ << "("; + hidden_detail_::out( this->sout_, proto::value(expr) ); + this->sout_ << ")\n"; this->first_ = false; } template void impl(Expr const &expr, Arity) const { - using namespace hidden_detail_; typedef typename tag_of::type tag; this->sout_ << std::setw(this->depth_) << (this->first_? "" : ", "); - this->sout_ << tag() << "(\n"; + hidden_detail_::out( this->sout_, tag() ); + this->sout_ << "(\n"; display_expr display(this->sout_, this->depth_ + 4); fusion::for_each(expr, display); this->sout_ << std::setw(this->depth_) << "" << ")\n";