User-defined literals, underscores, and global names

后端 未结 1 711
無奈伤痛
無奈伤痛 2021-01-11 19:50

In C++11, we get user-defined literals. The C++ standard has examples of these, such as:

long double operator \"\" _w(long double);

And it

相关标签:
1条回答
  • 2021-01-11 20:07

    What's in a name? 3 Basic concepts [basic] tells us:

    4 A name is a use of an identifier (2.11), operator-function-id (13.5), literal-operator-id (13.5.8), conversion-function-id (12.3.2), or template-id (14.2) that denotes an entity or label (6.6.4, 6.1).

    which we cross-reference with 13.5.8 User-defined literals [over.literal]:

    literal-operator-id:
    operator "" identifier

    While the name of a literal operator involves an identifier, that identifier does not denote an entity. (Or it's a different identifier and different name that denotes another entity or label altogether.) As such the name of a literal operator never starts with an underscore.

    Something like operator""__w is problematic but this is not new: int i__0; is reserved as well.

    0 讨论(0)
提交回复
热议问题