Suppose I want to define an integer literal which also allows for negative values, e.g. -12_km.
I.e., I would like to do
using coord_t = long long;
coord_t operator "" _km(long long int);
However, this is not accepted by my compiler (gcc).
The standard mentions a list of the allowed types for the parameter list of such a literal operator, but no signed integer type is among them.
Why is the standard like that? Why doesn't it allow for user-defined signed integer literals?
Because there are no negative integer literals in C++.
-12is actually the minus operator applying to the positive literal12. That's the very reason whyINT_MINas-INT_MAX - 1-2147483648 > 0and0 < -0x80000000in some compilersSo you need to overload the unary minus operator to use
-12_km