C++ Logo

sg16

Advanced search

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

From: Tom Honermann <tom_at_[hidden]>
Date: Fri, 3 May 2024 17:33:12 -0400
On 4/30/24 7:32 AM, Peter Dimov via SG16 wrote:
> Corentin Jabot wrote:
>> Very rough drafthttps://isocpp.org/files/papers/D3258R0.pdf
> Looks good. I'm however not sure that it makes sense to format
> char8_t (char16_t is borderline.)
>
> Or maybe that's only intended for {:?} ?
>
>> What about iostream?
>> This is a story for another paper (One that an enthusiastic
>> reader is encouraged to write!)
> Here's that paper:
>
> Insert at the end ofhttps://eel.is/c++draft/ostream.inserters.character
> the following:
>
> template<class charT, class traits>
> basic_ostream<charT, traits>& operator<<(basic_ostream<charT, traits>& out, const char8_t* s);
> template<class charT, class traits>
> basic_ostream<charT, traits>& operator<<(basic_ostream<charT, traits>& out, const char16_t* s);
> template<class traits>
> basic_ostream<char, traits>& operator<<(basic_ostream<char, traits>& out, const char32_t* s);
Those aren't consistent; the last one specifies char instead of charT.
>
> Preconditions: s is not a null pointer.
>
> Effects:
> Behaves like a formatted inserter (as described in [ostream.formatted.reqmts]) of `out`.
> Creates a character sequence `seq` holding the transcoded representation
> of s [format.string.transcode].
> Determines padding for `seq` as described in [ostream.formatted.reqmts]. Inserts `seq` into
> `out`. Calls `width(0)`.
>
> Returns:
> `out`.

It would be odd to supply inserters without corresponding extractors.

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);

Variations of the above for both characters and strings are already
defined as deleted in [ostream.general]
<http://eel.is/c++draft/ostream.general>.

Tom.

Received on 2024-05-03 21:33:17