Boost logo

Boost :

Subject: Re: [boost] [C++0x] Emulate C++0x char16_t, char32_t, std::u16string, and std::u32string
From: Artyom Beilis (artyomtnk_at_[hidden])
Date: 2011-07-21 01:54:16

--- On Thu, 7/21/11, Beman Dawes <bdawes_at_[hidden]> wrote:

> From: Beman Dawes <bdawes_at_[hidden]>
> > You can't create working
> >
> > std::basic_ostringstream<char16_t> stream;
> >
> > Because stream << 1245 would not work due to
> lack of std::locale facets.
> >
> > You can't create requires facets as for example they
> are specialized
> > in many standard libraries.
> Emulation via simple uint16_t and uint32_t typedefs doesn't
> work for
> all use cases. So only use it when it does work.

And Boost.Filesystem.v3 is one of these specific use cases.

Boost.Filesystem uses codecvt facet? You can't create them, at
least with gcc/linux because existing codecvt facets are specialized
for each type of character - and you have to derive from it.

For example this code would not link with Linux/gcc-4.6

#include <locale>

class real_facet :
    public std::codecvt<char16_t,char,std::mbstate_t>

class simulated_facet :
    public std::codecvt<unsigned short,char,std::mbstate_t>

int main()
    std::locale l1(std::locale::classic(),new real_facet());
    std::locale l2(std::locale::classic(),new simulated_facet());

With errors like:

undefined reference to `std::codecvt<char16_t, char, __mbstate_t>::do_in(__mbstate_t&, char const*, char const*, char const*&, char16_t*, char16_t*, char16_t*&) const'

: undefined reference to `std::codecvt<unsigned short, char, __mbstate_t>::do_max_length() const'
> > Even existing Microsoft's VC2010 does not work if you
> compile application
> > with /MD or /MDd
> I'll retest just to be sure, but I'm fairly sure that some
> of my tests
> have used those switches.
MSVC2010 does not provide specialization for std::locale::id
for these new facets and they are undefined in the dll.
If you want I'll provide a fault case for MSVC10 as well.
And all these with compilers that **declare** support 
of charXX_t.
So you may try to put an effort in implementing some emulation
but at these points char16_t/char32_t are broken with modern
Artyom Beilis
CppCMS - C++ Web Framework:
CppDB - C++ SQL Connectivity:

Boost list run by bdawes at, gregod at, cpdaniel at, john at