A user-defined literal suffix in C++0x should be an identifier that
_
(underscore) (17.6.4.3.5)_
followed by uppercase letter (17.6.4.3.2)
Each name that [...] begins with an underscore followed by an uppercase letter is reserved to the implementation for any use.
Is there any reason, why such a suffix may not start _
followed by a digit? I.E. _4
or _3musketeers
?
Musketeer dartagnan = "d'Artagnan"_3musketeers;
int num = 123123_4; // to be interpreted in base4 system?
string s = "gdDadndJdOhsl2"_64; // base64decoder
The precedent for identifiers of the form _<number>
is the function argument placeholder object mechanism in std::placeholders
(§20.8.9.1.3), which defines an implementation-defined number of such symbols.
This is a good thing, because it means the user cannot #define
any identifier of that form. §17.6.4.3.1/1:
A translation unit that includes a standard library header shall not #define or #undef names declared in any standard library header.
The name of the user-defined literal function is operator "" _123
, not simply _123
, so there is no direct conflict between your name and the library name if presence of the using namespace std::placeholders;
.
My 2¢, though, is that you would be better off with an operator "" _baseconv
and encoding the base within the literal, "123123_4"_baseconv
.
Edit: Looking at Johannes' (deleted) answer, there is There may be concern that _123
could be used as a macro by the implementation. This is certainly the realm of theory, as the implementation would have little to gain by such preprocessor use. Furthermore, if I'm not mistaken, the reason for hiding these symbols in std::placeholders
, not std
itself, is that such names are more likely to be used by the user, such as by inclusion of Boost Bind (which does not hide them inside a named namespace).
The tokens are not reserved for use by the implementation globally (17.6.4.3.2), and there is precedent for their use, so they are at least as safe as, say, forward
.