4 ms·
C++ auto isn't type inference, as so often in C++ it's something weirder which they call type deduction. In languages with type inference when it could be A or
by tialaramex 1y ago
C++ auto isn't type inference, as so often in C++ it's something weirder which they call type deduction.
In languages with type inference when it could be A or B and it's left to infer the type the compiler just always says it could be A or B, so the programmer needs to disambiguate.
But with deduction in some cases C++ will deduce that you meant A even though you could instead have explicitly chosen B here instead, and too bad if you did mean B because that's not what it deduced.
- coolThingsFirst 1y agoCan you show me some examples where the deduction is not the expected type?
- tialaramex 1y agoHere's an easy to understand example https://cpp.godbolt.org/z/hTaPbM3a4 https://cpp.godbolt.org/z/hTaPbM3a4