Boost logo

Boost :

Subject: Re: [boost] Best home for cxx11_char_types.hpp?
From: Beman Dawes (bdawes_at_[hidden])
Date: 2014-07-09 16:51:52

On Wed, Jul 9, 2014 at 2:51 PM, Andrey Semashev <andrey.semashev_at_[hidden]>

> On Wednesday 09 July 2014 14:42:55 Beman Dawes wrote:
> > I'm working on an update of Boost.Filesystem that adds support for the
> > C++11 char16_t, char23_t, u16string, and u32string types.
> >
> > For compilers that don't yet support these types, a header
> > cxx11_char_types.hpp (see attached) provides emulation that is good
> enough
> > for filesystem, and is probably useful for other libraries and for user
> > code too. We discussed this header several years ago, and I've been using
> > it since then.
> >
> > Where should this header live? It can certainly go in
> > libs/filesystem/include/boost/filesystem, but that doesn't really expose
> it
> > to general Boost users. Is there a better place, but without introducing
> > unwanted dependencies?
> Are string typedefs generally useful in C++03?

Yes, at least in applications that are not crippled by a compiler that also
lacks Unicode literals.

E.g. does
> std::char_traits<boost::char16>::length() work?

Yes, at least for GCC and MSVC. Have not tested other compilers.

> It would be needed if one to
> construct u16string from a literal.

Compilers that don't support char16_t/char32_t usually don't support
Unicode literals.

So you end up writing code like this:

  // Test with cases that require UTF-16 surrogate pairs

  // build test strings character by character so they work with C++03
  const char32 u32c[] = {0x1F60A, 0x1F60E, 0};
  const char16 u16c[] = {0xD83D, 0xDE0A, 0xD83D, 0xDE0E, 0};

  const u32string u32s(u32c);
  const u16string u16s(u16c);
  const string u8s("\xF0\x9F\x98\x8A\xF0\x9F\x98\x8E");
  const string chars("\xF0\x9F\x98\x8A\xF0\x9F\x98\x8E");

> If not these typedefs should not be
> exposed to users, IMHO.

The cat is already out of the bag. Microsoft has been exposing them for
several releases.

> Otherwise, cstdint.hpp is in Boost.Config, and this header offers similar
> functionality.

Makes sense.


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