How to determine negative UDL in C ++ 11 (are they forbidden?)?

I'm not even sure if negative Literals specified by the user are acceptable. If not, why weren't they left?

For example, I would like to use:

auto money_i_owe_jack = -52_jpy;

This is what I tried to use gcc 4.7.2:

constexpr int64_t operator "" _jpy(long long l)
{
  return static_cast<int64_t>(l);
}

ERROR

Test_udl.cpp:60:47: error: ‘constexpr int64_t operator"" _jpy(long long int)’ has invalid argument list
+6
source share
2 answers

Integer literals must be accepted as unsigned long long. The negative sign is not part of the literal; it is applied after the fact to the return value.

constexpr int64_t operator "" _jpy(unsigned long long l)
{
  return static_cast<int64_t>(l);
}
+5
source

Regardless of whether you are user-defined or not, literals of integers and floating point are always positive.

: , . , - - 10, , (- 10) (-10). , - a - 10 <a> <-10> (. <-10> <identifier><literal>, C++ ( ).

, , , () , , , - , , -10 .

, , , , , , - , - .

+8

All Articles