Hi Corentin,

 

At the moment, this just looks like a weird reinterpret_cast in the example you provide. I think it would be good to use a name that makes it clear that:

 

  1. The function has a precondition of a specific encoding of text behind the pointer/span
  2. The function is hazardous to call

 

In my view, Rust’s API is ideal:

 

 

This is good design because the functions have names that clearly indicate the encoding precondition and whether or not checking is performed.  The safer version of the function is also has a shorter name, so it shows up first in autocompletion and documentation. People are guided to use the safe/checked option first.

 

I strongly oppose adding the unchecked cast function to the standard library without simultaneously adding the corresponding checked cast.

 

                           Peter

 

From: SG16 <sg16-bounces@lists.isocpp.org> On Behalf Of Corentin via SG16
Sent: 28 January 2021 17:52
To: SG16 <sg16@lists.isocpp.org>; Aaron Ballman <aaron@aaronballman.com>
Cc: Corentin <corentin.jabot@gmail.com>
Subject: [SG16] Reinterpreting pointers of character types

 

EXTERNAL MAIL

Hello, 

 

In which I propose 

reinterpret_string_cast, a function to cast between char* and char8_t* without UB.

 

This ô terrible paper is intended as a discussion starter so that we can refine the design with the help of our good friends in CWG :)

 

Have a great day,

 

Corentin