Ticket #4910: display_expr-66440.2.patch

File display_expr-66440.2.patch, 3.1 KB (added by Maxim Yanchenko <Maxim.Yanchenko@…>, 12 years ago)

patch against rev. 66440

  • ./boost/proto/debug.hpp

     
    8383
    8484    namespace hidden_detail_
    8585    {
    86         struct ostream_wrapper
    87         {
    88             ostream_wrapper(std::ostream &sout)
    89               : sout_(sout)
    90             {}
    91 
    92             std::ostream &sout_;
    93         };
    94 
    95         template<typename Tag>
    96         std::ostream &operator <<(ostream_wrapper sout_wrap, Tag const &)
    97         {
    98             return sout_wrap.sout_ << BOOST_SP_TYPEID(Tag).name();
    99         }
     86        // has_ostream_shift trait
     87        struct yes_type { char x; };
     88        struct no_type  { yes_type x[2]; };
     89
     90        template<typename T> T fake();
     91
     92        no_type has_ostream_shift_test(...);
     93
     94        template<typename T>
     95        typename boost::enable_if_c< sizeof( fake<std::ostream&>() << fake<const T&>() )
     96                                   , yes_type >::type
     97        has_ostream_shift_test(const T&);
     98
     99        template<typename T>
     100        struct has_ostream_shift
     101          : boost::mpl::bool_<
     102                sizeof( has_ostream_shift_test(fake<const T&>()) ) == sizeof( yes_type )
     103            >
     104        {};
     105       
     106        // output
     107        template<typename T> inline
     108        void output_impl( std::ostream& os, const T& x, boost::mpl::true_ )
     109        {
     110            os << x;
     111        }
     112
     113        template<typename T> inline
     114        void output_impl( std::ostream& os, const T& x, boost::mpl::false_ )
     115        {
     116            os << typeid(T).name();
     117        }
     118
     119        template<typename T> inline
     120        void output( std::ostream& os, const T& x )
     121        {
     122          output_impl( os, x, has_ostream_shift<T>() );
     123        }
    100124    }
    101125
    102126    namespace functional
     
    138162            template<typename Expr>
    139163            void impl(Expr const &expr, mpl::long_<0>) const
    140164            {
    141                 using namespace hidden_detail_;
    142165                typedef typename tag_of<Expr>::type tag;
    143166                this->sout_.width(this->depth_);
    144167                this->sout_ << (this->first_? "" : ", ");
    145                 this->sout_ << tag() << "(" << proto::value(expr) << ")\n";
     168                hidden_detail_::out( this->sout_, tag() );
     169                this->sout_ << "(";
     170                hidden_detail_::out( this->sout_, proto::value(expr) );
     171                this->sout_ << ")\n";
    146172                this->first_ = false;
    147173            }
    148174
    149175            template<typename Expr, typename Arity>
    150176            void impl(Expr const &expr, Arity) const
    151177            {
    152                 using namespace hidden_detail_;
    153178                typedef typename tag_of<Expr>::type tag;
    154179                this->sout_.width(this->depth_);
    155180                this->sout_ << (this->first_? "" : ", ");
    156                 this->sout_ << tag() << "(\n";
     181                hidden_detail_::out( this->sout_, tag() );
     182                this->sout_ << "(\n";
    157183                display_expr display(this->sout_, this->depth_ + 4);
    158184                fusion::for_each(expr, display);
    159185                this->sout_.width(this->depth_);