Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 347
Lorah Attkins Avatar asked Jan 29 '17 00:01

Lorah Attkins


1 Answers

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 _.

like image 193
Barmar Avatar answered Sep 21 '22 01:09

Barmar