I'm learning C++11, and am interested in user-defined literals. So I decided to play a bit with it. Some languages have a syntax like this:
int n = 1000_000_000;
I tried to simulate this feature in C++11.
inline constexpr unsigned long long operator "" _000 (unsigned long long n)noexcept
{
return n * 1000;
}
inline constexpr unsigned long long operator "" _000_000 (unsigned long long n)noexcept
{
return n * 1000*1000;
}
inline constexpr unsigned long long operator "" _000_000_000 (unsigned long long n)noexcept
{
return n * 1000*1000*1000;
}
int main(){
constexpr auto i = 100_000; // instead of 100000
constexpr auto j = 23_000_000; // instead of 23000000;
}
But for the general case I couldn't simulate it, i.e.
auto general_case = 123_456_789; //can't compile
My question is "Can I simulate for the general case as above using C++11?".