C++ Logo

sg16

Advanced search

Re: Follow up on SG16 review of P2996R2 (Reflection for C++26)

From: Peter Dimov <pdimov_at_[hidden]>
Date: Sat, 4 May 2024 12:39:25 +0300
Tom Honermann wrote:
> On 5/3/24 8:49 PM, Peter Dimov wrote:
> > Tom Honermann wrote:
> >> Characters should be handled as well as strings:
> >>
> >>
> >> template<class charT, class traits>
> >> basic_ostream<charT, traits>& operator<<(basic_ostream<charT,
> >> traits>& out, char8_t); template<class charT, class traits>
> >> basic_ostream<charT, traits>& operator<<(basic_ostream<charT,
> >> traits>& out, char16_t); template<class charT, class traits>
> >> basic_ostream<charT, traits>& operator<<(basic_ostream<charT,
> >> traits>& out, char32_t);
> > I don't think the first one of these makes any sense. It's not
> > possible to transcode a char8_t on its own.
>
> It is if it is an ASCII character. Differentiating ASCII vs whatever the ordinary
> literal encoding is is why u8'x' was added in C++17.

It might make sense conceptually in the abstract, but I fail to see the practical
use of it.

Trying to insert char8_t on its own into a stream is almost certainly an error.

The only possible case I see is generic debug output, and ostream doesn't
really do this particularly well (as opposed to std::format).

> If we support this:
>
> std::cout << u8"x";
>
> then we should also support:
>
> std::cout << u8'x';

I don't see why. If you want the literal sequence consisting of the character
'x' inserted into std::cout, simply use u8"x".

Incidentally `is >> c` is also almost always an error, even in the ordinary
`char` case. I'm looking at one such use right now.

Received on 2024-05-04 09:39:29