I have:
std::map<double, Foo> map;
for (auto&& [first, second] : map) { /* ... */ }
where Foo
is a class declared elsewhere
There are 2 issues that I see as it stands:
1. Mapped type constness
second
here is Foo&
which is correct, but you can also use std::as_const to make it const Foo&
for (auto&& [first, second] : std::as_const(map)) { /* ... */ }
so this is not a problem.
2. By value copy of built-in types
first
here is const double&
which is inefficient for built-in types.
Is there a way to make first
be taken by value?
I'm sure this wasn't overlooked.