c++language-lawyeruser-defined-literals

Reserved Names & User Literals


The C++ Standard reserves names beginning with an underscore followed by a capital letter in all scopes.

Does this apply to user literal operators?

e.g.

int _MyInt; // reserved, violation

template < char... >
auto operator "" _MyInt ( ); // reserved???

Solution

  • No, it allows the use of an underscore followed by a capital letter (which is otherwise a reserved identifier).

    Source

    I've only found an example, not a formal paragraph, in the standard supporting the above:

    [over.literal]

    double operator""_Bq(long double);    // OK: does not use the reserved identifier _­Bq
    double operator"" _Bq(long double);   // uses the reserved identifier _­Bq 
    

    So, as long as you don't put a space between "" and _Ud it's ok - according to the example that is.