lundi 19 novembre 2018

Use type of a variable as a template argument

I did the following:

long long int x = 0:
int digits_of_x = std::numeric_limits<long long int>::digits;

And it works fine. However this can easily introduce an error if someone changes the type of x. So I would prefer to do it like this:

long long int x = 0:
int digits_of_x = std::numeric_limits<typeof(x)>::digits;

I found the GCC extension typeof() but I want to use some standard function (up to C++17). Is there such a function?

Aucun commentaire:

Enregistrer un commentaire