Are unicode prefixes in string literals necessary? #668
Replies: 3 comments 5 replies
-
Remember that Herb doesn't want to get his hands dirty with Unicode yet.
We could make the Unicode prefixes work like the built-in integer literals. Apparently, this is the mapping (https://en.cppreference.com/w/cpp/language/string_literal):
According to https://tzlaine.github.io/unicode_cppnow_2023/#/0/42/2, |
Beta Was this translation helpful? Give feedback.
-
I'm thinking about if we already can declare integer variables without suffixes: x: i32 = 10;
y: longlong = 10; Why can we not just declare string variables without prefixes? // const *char8_t = "text";
// basic_string<char8_t> = "text";
x: u8string = "text";
// const *char = "text";
// basic_string<char> = "text";
y: string = "text";
I mean, can we just write Cppfront can translate this Cpp2 code: a: u8string = "text"; to this Cpp1 code: u8string a{u8"text"}; In this way, it won't need a new syntax divergent from Cpp1. |
Beta Was this translation helpful? Give feedback.
-
If I were using a unicode editor, and I put unicode characters between the quotes, I'd expect the compiler to warn me that my char* string literal contained illegal characters, but my unicode string literal did not. I'm not sure if this is possible, but if it is, would the prefix on the string be be required to ascertain the string type without the compiler needing wider context?
In your examples it is easy, but perhaps there are less direct assignments that could require context? Like using the same literal in an if statement to assign to different class members which have different string types? Or a templated out parameter?
Or an automatically deduced type based on a literal with only unicode characters between the quotes (was this intentional? Or is the user using a unicode text editor and they just want the char equivalent string?)
Not that I don't like your idea, just trying to find faults for discussion.
On 12 September 2023 06:31:13 Sadeq ***@***.***> wrote:
@JohelEGP<https://github.com/JohelEGP>, The underlying type can be anything. I just used basic_string as an example. So in general:
a: const *char8_t = "text";
b: basic_string<char8_t> = "text";
c: u8string = "text";
func: (const *char) = {
print("char");
}
func: (const *char8_t) = {
print("char8_t");
}
func("text"); // prints "char"
utf8: == const *char8_t;
func(utf8("text")); // prints "char8_t"
func("text".utf8()); // prints "char8_t"
func(: utf8 = "text"); // prints "char8_t"
—
Reply to this email directly, view it on GitHub<#668 (reply in thread)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AALUZQK6EKP5N25Z3AWQFBLXZ7XR7ANCNFSM6AAAAAA4RICDTU>.
You are receiving this because you are subscribed to this thread.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
Currently we have unicode prefixes in string literals:
name: = u8"Someone";
What would be wrong if we could call functions or constructors instead of unicode prefixes?
Or even with UFCS:
Or directly within declaration:
Or simply with
:
syntax:Essentially Cpp2 may be able to drop all unicode prefixes. It leads to reducing concept count.
Beta Was this translation helpful? Give feedback.
All reactions