Is there a standard way to get the size of the type a variable would be promoted to when passed as a variadic argument?
auto x = ...;
auto y = sizeof(promoted(x));
The results should be:
char -> sizeof(int)
int -> sizeof(int)
float -> sizeof(double)
...
auto s = sizeof(+x);
should do the trick for integers.
+x
makes use of the unary +
operator, which performs integer promotion just like any other arithmetic operator.
I am not aware of any standard promotion rules for float
that would apply here (in the integer promotion sense) since you can do arithmetic with them without promoting. If you always want to promote to at least double
you can try
auto s = sizeof(x + 0.);
and then distinguish between floating point and integers before you get there.
Again, I do not think that you can handle integers and floating points at once because of the different meanings of "promotion" we are applying here.
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