2

I have the following code inspired by one of the SO questions:

int main()
{
    wcout << "\n\n 1- Test normal string with wcout \n";
    wcout << u8"\n 2- Test (u8) string with wcout  \n";
    wcout << u"\n 3- Test (u) string with wcout \n";
    wcout << U"\n 4- Test (U) string with wcout \n";
    wcout << L"\n 5- Test (L) string with wcout \n\n"; 
}

which results in:

Output

cout has similar output.

I understand from the answer on this post that w/cout does not support the string U/u prefixes, or exactly as mentioned:

Meanwhile std::cout's class has no special << overload for const char16_t*, const char32_t* and const wchar_t*, hence it will match <<'s overload for printing pointers.

My questions are:

1- Why it does not support these types? Isn't it a strange for a language not to support its own types? 2- Are there any known plans to add such support in the seen future?

I know that iostream is a library, but, practically, it is still part of the language.

Community
  • 1
  • 1
Kamal Zidan
  • 474
  • 2
  • 9
  • 1
    Encoding and (wide) character representation are orthogonal things. IMO that's answered in the question you linked. – πάντα ῥεῖ May 19 '17 at 20:06
  • @πάνταῥεῖ I understand that there is ambiguity for an `u8""` string literal as it maps to `const char[]` which has no associated encoding, but `u""` maps to `const char16_t[]` and `U""` maps to `const char32_t[]` which according to [this reference](http://en.cppreference.com/w/cpp/language/types) imply UTF-16 / UTF-32 encoding. – zett42 May 19 '17 at 20:52
  • @zett42 Well, that's why I've been upvoting that question (I have some problems understanding that in detail mayself ;-) ). – πάντα ῥεῖ May 19 '17 at 20:54

1 Answers1

0

The usual answer to standard library omissions applies: nobody proposed to add overloads for char16_t const* or char32_t. The proposal to add the character types (N2249) did not contain the relevant library parts. In particular, it didn't add overloads for

template <typename charT, typename Traits>
std::basic_ostream<charT, Traits>& std::operator<< (std::basic_ostream<charT, Traits>&, char16_t const*);
template <typename charT, typename Traits>
std::basic_ostream<charT, Traits>& std::operator<< (std::basic_ostream<charT, Traits>&, char32_t const*);

As there is an overload of these operator taking void const* the address of the pointer is printed. As the new character types are kind of pointless (at least, from my point of view: just use UTF8) I doubt there is anybody interested in creating a proposal.

Dietmar Kühl
  • 150,225
  • 13
  • 225
  • 380