Ticket #4910: display_expr-66440.patch

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

patch against rev. 66440

  • boost/proto/

    old new  
    8383
    8484    namespace hidden_detail_
    8585    {
    86         struct ostream_wrapper
    87         {
    88             ostream_wrapper(std::ostream &sout)
    89               : sout_(sout)
    90             {}
     86      struct yes_type { char x; };
     87      struct no_type  { yes_type x[2]; };
    9188
    92             std::ostream &sout_;
    93         };
     89      no_type has_ostream_shift(...);
    9490
    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         }
     91      template<class T>
     92      typename boost::enable_if_c<
     93          sizeof(*(std::ostream*)NULL << *(T*)NULL)
     94        , yes_type >::type
     95      has_ostream_shift(const T&);
     96
     97      template<bool has>
     98      struct Out
     99      {
     100        template<class T> static void out( std::ostream& os, const T& x );
     101      };
     102
     103      template<> template<class T> inline
     104      void Out<true>::out( std::ostream& os, const T& x )
     105      {
     106        os << x;
     107      }
     108
     109      template<> template<class T> inline
     110      void Out<false>::out( std::ostream& os, const T& x )
     111      {
     112        os << BOOST_SP_TYPEID(T).name();
     113      }
     114
     115      template<class T> inline
     116      void out( std::ostream& os, const T& x )
     117      {
     118        Out< sizeof(has_ostream_shift(*(T*)NULL)) == sizeof(yes_type) >::out( os, x );
     119      }
    100120    }
    101121
    102122    namespace functional
     
    138158            template<typename Expr>
    139159            void impl(Expr const &expr, mpl::long_<0>) const
    140160            {
    141                 using namespace hidden_detail_;
    142161                typedef typename tag_of<Expr>::type tag;
    143162                this->sout_.width(this->depth_);
    144163                this->sout_ << (this->first_? "" : ", ");
    145                 this->sout_ << tag() << "(" << proto::value(expr) << ")\n";
     164                hidden_detail_::out( this->sout_, tag() );
     165                this->sout_ << "(";
     166                hidden_detail_::out( this->sout_, proto::value(expr) );
     167                this->sout_ << ")\n";
    146168                this->first_ = false;
    147169            }
    148170
    149171            template<typename Expr, typename Arity>
    150172            void impl(Expr const &expr, Arity) const
    151173            {
    152                 using namespace hidden_detail_;
    153174                typedef typename tag_of<Expr>::type tag;
    154175                this->sout_.width(this->depth_);
    155176                this->sout_ << (this->first_? "" : ", ");
    156                 this->sout_ << tag() << "(\n";
     177                hidden_detail_::out( this->sout_, tag() );
     178                this->sout_ << "(\n";
    157179                display_expr display(this->sout_, this->depth_ + 4);
    158180                fusion::for_each(expr, display);
    159181                this->sout_.width(this->depth_);