Ticket #4910: display_expr-1.44.0.patch

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

patch against 1.44.0

  • boost/proto/

    old new  
    8484
    8585    namespace hidden_detail_
    8686    {
    87         struct ostream_wrapper
    88         {
    89             ostream_wrapper(std::ostream &sout)
    90               : sout_(sout)
    91             {}
     87      struct yes_type { char x; };
     88      struct no_type  { yes_type x[2]; };
    9289
    93             std::ostream &sout_;
    94         };
     90      no_type has_ostream_shift(...);
    9591
    96         template<typename Tag>
    97         std::ostream &operator <<(ostream_wrapper sout_wrap, Tag const &)
    98         {
    99             return sout_wrap.sout_ << typeid(Tag).name();
    100         }
     92      template<class T>
     93      typename boost::enable_if_c<
     94          sizeof(*(std::ostream*)NULL << *(T*)NULL)
     95        , yes_type >::type
     96      has_ostream_shift(const T&);
     97
     98      template<bool has>
     99      struct Out
     100      {
     101        template<class T> static void out( std::ostream& os, const T& x );
     102      };
     103
     104      template<> template<class T> inline
     105      void Out<true>::out( std::ostream& os, const T& x )
     106      {
     107        os << x;
     108      }
     109
     110      template<> template<class T> inline
     111      void Out<false>::out( std::ostream& os, const T& x )
     112      {
     113        os << typeid(T).name();
     114      }
     115
     116      template<class T> inline
     117      void out( std::ostream& os, const T& x )
     118      {
     119        Out< sizeof(has_ostream_shift(*(T*)NULL)) == sizeof(yes_type) >::out( os, x );
     120      }
    101121    }
    102 
    103122    namespace functional
    104123    {
    105124        /// \brief Pretty-print a Proto expression tree.
     
    139158            template<typename Expr>
    140159            void impl(Expr const &expr, mpl::long_<0>) const
    141160            {
    142                 using namespace hidden_detail_;
    143161                typedef typename tag_of<Expr>::type tag;
    144162                this->sout_ << std::setw(this->depth_) << (this->first_? "" : ", ");
    145                 this->sout_ << tag() << "(" << proto::value(expr) << ")\n";
     163                hidden_detail_::out( this->sout_, tag() );
     164                this->sout_ << "(";
     165                hidden_detail_::out( this->sout_, proto::value(expr) );
     166                this->sout_ << ")\n";
    146167                this->first_ = false;
    147168            }
    148169
    149170            template<typename Expr, typename Arity>
    150171            void impl(Expr const &expr, Arity) const
    151172            {
    152                 using namespace hidden_detail_;
    153173                typedef typename tag_of<Expr>::type tag;
    154174                this->sout_ << std::setw(this->depth_) << (this->first_? "" : ", ");
    155                 this->sout_ << tag() << "(\n";
     175                hidden_detail_::out( this->sout_, tag() );
     176                this->sout_ << "(\n";
    156177                display_expr display(this->sout_, this->depth_ + 4);
    157178                fusion::for_each(expr, display);
    158179                this->sout_ << std::setw(this->depth_) << "" << ")\n";