Why are non underscore names reserved to the implementation for UDL and not the other way around?
Asked Answered
W

1

11

I know this is an old feature but reading on user defined literals e.g.

return_t operator "" _a(long); // Literal operator for user-defined INTEGRAL literal

I was reminded that

the leading underscore is required. (Only the Standard Library is allowed to define literals without the underscore.) (A)

This seems to break pattern since so far the implementation worked with the underscorey names and left us the good ones, for example reserved to the implementation are names that

  1. Contain a double underscore
  2. Begin with an underscore followed by a capital letter

Furthermore quote (A) is somewhat dangerous in the presence of rule (2). So why the inconsistency?

Whitehurst answered 29/1, 2017 at 0:2 Comment(1)
This is so we can get the "natural" looking suffixes in the standard library, and leave user-defined suffixes clearly visible as such.Corps
T
9

Before the idea of user-defined literals was added to the language, all the standard literals used sequences that don't begin with underscore, such as 123L for a long int literal. So to maintain consistency, standard literals get the namespace without any special prefix, and UDLs are distinguished from them by using _.

Talanian answered 29/1, 2017 at 0:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.