4 ms·
I write my code with the assumption that the reader does _not_ have access to a "smart" IDE. I use `auto` when the type is obvious or doesn't really matter, an
by MathMonkeyMan 2y ago
I write my code with the assumption that the reader does _not_ have access to a "smart" IDE.
I use `auto` when the type is obvious or doesn't really matter, and I seldom create aliases for types.
I feel like having verbose type names at function boundaries and using `auto` for dependent types is the sweet spot. I'll often avoid `auto` when referring to a class data member, so the reader doesn't have to refer to the definition.
void foo(const std::multimap<double, Order>& sells) {
for (const auto& [price, order] : sells) {
// ...
}
}
but also
void foo(const OrderBook& book) {
const std::multimap<double, Order>& sells = book.sells;
for (const auto& [price, order] : sells) {
// ...
}
}
`auto` is convenient for iterators. Which of the following is better?
auto iter = sells.begin();
std::multimap<double, Order>::const_iterator iter = sells.begin();