Search code examples
c++c++11user-defined-literals

Which user-defined-literals are predefined by the standard?


My question sounds like a contradiction, but I don't know how else to refer to the new literal syntax other than user-defined-literal.

std::string operator "" s ( const char* str, size_t len )
{
   return std::string( str, len );
}

assert( "foo"s == "bar"s );

I remember hearing that user defined literals should start with an _ prefix. That would imply that the library defines some non-prefixed literals for us.

Does the standard provide some UDLs in the the standard library?
If yes, what are they?


Solution

  • The language already use regular literals suffixes, for example 1U.

    It would become ambiguous if you were to use U as a user-defined-literal, thus the recommendation.

    integer-suffix: u, U, l, L, ll, LL

    floating-suffix: f, F, l, L