3 ms·
The rules are simple: Use auto when the local code shouldn't care about the type as a way of signifying that the local code shouldn't care about the type. It d
by BugsJustFindMe 2y ago
The rules are simple:
Use auto when the local code shouldn't care about the type as a way of signifying that the local code shouldn't care about the type. It doesn't happen all the time, but it does happen sometimes.
Don't use auto when the code needs to care about the type.
- okanat 2y agoWith the complexity and the performance cost considered, I don't think there is a piece of code that is worth writing in C++ that also don't need to care about types. auto introduces quite a bit complexity to already complex C++ code. It behaves completely differently in lambdas. Using it as the return types usually causes implicit and costly conversions. Using it with primitive types is basically a booby trapped temple for juniors who didn't burned numerous times and mere mortals who don't have time to learn cppreference by heart. If I don't care about types, I would use a higher level language. Yes a compiler will give warnings and whatnot, given you have a modern enough one and somehow constantly running it. It is costly in time though. CI builds are not free. Developer time is less so.