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?
In a raw user-defined literal, the operator that you define accepts the literal as a sequence of char values. It's up to you to interpret that sequence as a number or string or other type. In the list of operators shown earlier in this page, _r and _t can be used to define raw literals: C++ Copy.
A literal is used for representing a fixed value in a program. A literal could be anything in a code like a, b, c2. , 'ACB', etc. Similarly, User-Defined Literals (UDL) provides literals for a variety of built-in types that are limited to integer, character, floating-point, string, boolean, and pointer.
A string literal or anonymous string is a string value in the source code of a computer program. Modern programming languages commonly use a quoted sequence of characters, formally "bracketed delimiters", as in x = "foo" , where "foo" is a string literal with value foo .
The standard library actually defines no user defined literals. We would perhaps have expected complex numbers, but no.
On the other hand, there is also a proposal to remove them again
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2011/n3250.html
so we don't yet know what happens.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With