Boost logo

Boost :

From: Alberto Barbati (abarbati_at_[hidden])
Date: 2002-11-16 05:59:21


Robert Ramey wrote:
>
> How does this strike you?
>
> text_iarchive(Stream &_is) :
> is(_is)
> {
> // archives always use classic locale
> #ifndef BOOST_NO_STD_LOCALE
> plocale = is.imbue(std::locale::classic());
> #endif
> init();
> }
> ~text_iarchive(){
> #ifndef BOOST_NO_STD_LOCALE
> is.imbue(plocale);
> #endif
> }

This solution does not address the objections in my last post in the
original thread. You seem really concerned about this. We could meet in
the middle with this solution, instead:

          text_iarchive(Stream &_is, bool _overrideLocale = true) :
                  is(_is)
          {
                  // archives always use classic locale
                  #ifndef BOOST_NO_STD_LOCALE
                 if(_overrideLocale)
                          plocale = is.imbue(std::locale::classic());
                else
                        plocale = is.getloc();
                  #endif
                  init();
          }

> Another observation:
>
> I note that my test.cpp program includes wchar_t member variables initialized to values in excess of 256.
> The system doesn't seem to lose any informaton in storing/loading to a stream with classic locale.

Which platform are you working on? On Win32, VC++ 6sp5, STLport the
following test program produces the output 52 (0x34) instead of 4660
(0x1234). According to the standard, this behaviour is perfectly
conformant. (the ios::binary is required, because the I/O library could
apply CRLF translation to a part of a two-byte character).

#include <iostream>
#include <fstream>

int main()
{
     wchar_t a = L'\x1234';

     std::wofstream out("test.txt", std::ios::binary);
     out << a;
     out.close();

     std::wifstream in("test.txt", std::ios::binary);
     in >> a;
     in.close();

     std::cout << unsigned(a) << std::endl;
     return 0;
}

If this code produces the correct output on your platform, either your
char type has 16 bits or *your* platform is non-conformant, according to
my interpretation of the standard.

Alberto Barbati


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk