Consider this example:
template<typename T> auto f(T u, T v = T()) { return v; }
int main() {
double a; float b; int c; long d; // all possible numerical types here
auto res1 = f(a); // is res1 == 0.0?
auto res2 = f(b); // is res2 == 0.0?
auto res3 = f(c); // is res3 == 0?
auto res4 = f(d); // is res4 == 0?
}
Is there a guarantee from the Standard that T()
will default construct a zero numerical value whenever T
is a numerical type?
If not, how can I make sure that if T
is numerical, then the default argument for 'v' is v = 0
, and if T
is not numerical, then
v = T()
?