This is the mail archive of the libstdc++@sources.redhat.com mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: About endl...


> <ostream> declares endl to be:
> 
>   // 27.6.2.7 Standard basic_ostream manipulators
>   template<typename _CharT, typename _Traits>
>     basic_ostream<_CharT, _Traits>&
>     endl(basic_ostream<_CharT, _Traits>& __os)
>     { return flush(__os.put(__os.widen('\n'))); }

I saw that in the headers, but I don't understand why is breaks the original
function I posted:

template <class T>
void output(T val) {
   cout << val;
}

Is there a workaround? How can I implement an (template) output method that
could accept endl as argument. Also, from the header definition, I don't
understand why typeid(endl) doesn't work either. Can anyone enlighten me?

BTW, the real code I use that for is a Stream wrapper class that derives from a
base Object class:

class Stream : public Object
{
  protected:
   ios *int_stream;
  public:
   Stream(ios *_str)
      : int_stream(_str)
      {}

   ...

   template <class T>
   Stream &operator << (T &obj) {*dynamic_cast<ostream *> (int_stream) << obj;
return *this;}
};

In this case, the problem is with operator << (...). Any idea how to fix my code
to comply with the new libstdc++?

	Jean-Marc

-- 
Jean-Marc Valin
Universite de Sherbrooke - Genie Electrique
valj01@gel.usherb.ca

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]