Code 1 is more efficient when container.size()
is faster.
However, container.size()
is fast only when the container is vector
Other containers such as list
or map
are written like code 2 because this operation is slow.
Code 1 must be accessed within the repeat statement, such as Telem=some_vector[i];
.
For this to be possible, the container must support operator[](std::size_t)
This is also not supported by other container types except vector
.
© 2024 OneMinuteCode. All rights reserved.