Date: Tue, 30 Jul 2024 20:02:17 +0200
Take this (working) program
https://godbolt.org/z/rY3hh8boG
It creates a type, which remembers both types, int and double and its value:
So it does, what you propose.
However, it wraps the feature into a new type.
auto var = make_auto<double>();
var.printTypes(); // prints double and int
cout << typeid(var).name() << endl;
cout << var << endl;
int var2 = var;
cout << var2 << endl;
d -> double
i -> int
11AutoWrapperIdiE -> AutoWrapper<double, int>
123 -> value
123 -> value
Why should this be implicitly done with existing types instead?
Lots of C++ depends on knowing the exact type.
By making two types, which were the same before suddenly different, existing code breaks.
E.g. static variables in templated functions would exist independently, where before they were shared.
Received on 2024-07-30 18:02:22