4 ms·
For std::vector, they should compile to the same thing, the iterator is just a pointer to a flat array. For std::map (ie. red-black tree) or something more comp
by exDM69 10y ago
For std::vector, they should compile to the same thing, the iterator is just a pointer to a flat array. For std::map (ie. red-black tree) or something more complex, it might make a bigger difference. But even then, the iterator is quite light weight (just a pointer) so copying it is not a big deal.
- nandno 10y agoEven for std::map gcc generates identical code: https://godbolt.org/g/C6kooc https://godbolt.org/g/C6kooc https://godbolt.org/g/7RS5PQ https://godbolt.org/g/7RS5PQ godbolt is a great resource to see just how good modern compilers are.
- SamReidHughes 10y agoI wouldn't say "even" -- that's just another type where the iterator is a trivially copyable/destructable object.