Boost logo

Boost Users :

From: Luca Cappa (luca.cappa_at_[hidden])
Date: 2007-10-01 11:49:54


Hello all,
in the following little program:

using namespace boost::archive;
int main ()
{
   std::wostringstream lOSS;
   lOSS << __FUNCTION__;

   return 0;
}

for the operator<<() statement is called the following operator<<() (in
file boost_1_34_1\libs\serialization\src\xml_woarchive.cpp):

std::wostream & operator<<(std::wostream &os, const char *t) .

Instead I expected that it would be called the one defined in "ostream"
file, i.e.

        basic_ostream<_Elem, _Traits>& __CLRCALL_OR_CDECL operator<<(
                basic_ostream<_Elem, _Traits>& _Ostr, const char *_Val) .

Notice that the fault is of the "using namespace boost::archive;"
directive: in fact when it is removed it happens what I expected. Why does
this happen? Is it forbidden to use "using namespace boost::archive;" in
application's code?

The problem with calling the wrong operator<<() with a string is that the
implementation in the boost::archive namespace ends up in an infinite loop
as it does:

std::wostream & operator<<(std::wostream &os, const char *t){
     for(;;){
         wchar_t wc;
         int result = std::mbtowc(&wc, t, 10 /* max number */);
         if(0 < result)
             os.put(wc);
         else
         if(0 == result)
             break;
         else
             boost::throw_exception(
                 iterators::dataflow_exception(
                     iterators::dataflow_exception::invalid_conversion
                 )
             );
     }
     return os;
}

Thanks in advance,
Luca


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net