Created
June 3, 2020 19:56
-
-
Save NathanOliver1/44394f5a7c70d55abc5a655ff57bee52 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> Does this apply to user literal operators? | |
Yes and No. If we look at the grammar at the start of [\[over.literal\]][1] we have | |
operator string-literal identifier | |
operator user-defined-string-literal | |
as the different kinds of literals. The `operator string-literal identifier` way is when you have a literal like | |
operator "" _some_name | |
where there is a space bewteen the `""` and the name and in this case `_some_name` is an identifier and per [\[lex.name\]/3][2] so it cannot be used. | |
Then there is | |
operator user-defined-string-literal | |
and that is defined in [\[lex.ext\]][3] to be | |
string-literal ud-suffix | |
that gives you an operator like | |
operator ""_some_name | |
where there is no space between the `""` and the name of the literal. If we then look at [\[over.literal\]/1][4] we have | |
> [...]The `ud-suffix` of the `user-defined-string-literal` or the `identifier` in a `literal-operator-id` is called a *literal suffix identifier*. **Some literal suffix identifiers are reserved for future standardization; see [usrlit.suffix]**. A declaration whose literal-operator-id uses such a literal suffix identifier is ill-formed, no diagnostic required. | |
<sup>emphasis mine</sup> | |
and that says that only the names defined in [usrlit.suffix] are reserved. If we look at [\[usrlit.suffix\]][5] we find | |
> Literal suffix identifiers that do not start with an underscore are reserved for future standardization. | |
and since `operator ""_some_name` starts with an underscore, it is allowed. | |
[1]: https://timsong-cpp.github.io/cppwp/over.literal | |
[2]: https://timsong-cpp.github.io/cppwp/lex.name#3 | |
[3]: https://timsong-cpp.github.io/cppwp/lex.ext | |
[4]: https://timsong-cpp.github.io/cppwp/over.literal#1 | |
[5]: https://timsong-cpp.github.io/cppwp/usrlit.suffix |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment