[SG16-Unicode] String views with strong code unit types

Tom Honermann tom at honermann.net
Sun Jul 7 05:28:55 CEST 2019


On 6/4/19 3:38 AM, Lyberta wrote:
> I'm trying to replicate a "sv" UDL with strong code unit types.
>
> constexpr auto operator "" _cus(const char8_t* literal, std::size_t size)
>
> As view types require some outside storage, I'm will need to create an
> array of code units in static memory. I'm not sure how to do that. Also,
> the compiler says that "size" is not a constant expression. Any ideas?

This is a solvable problem in C++20 due to the adoption of P0732.  See 
the "Emulate C++17 u8 literals" section of P1423R2 
(http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1423r2.html#emulate) 
for an example.  Note that gcc's implementation of P0732 currently has a 
defect that prevents this technique being used.  See 
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88095.  A patch has been 
proposed, but I haven't tried it yet.

Tom.



More information about the Unicode mailing list