2

Allright, to settle a debate what is the more incorrect way of getting the last elememt of a std::vector?

Is it this:
auto i = myVec.at(myVec.begin() + myVec.size() - 1);

or:
auto i = *(&myVec.at(0) + (myVec.size() - 1));

I think the second method is better(worse) because it has more brackets and only works on Implementations where the vector's data is laid out concurrently (that is in the c++11 spec, but I've seen some shit)

My friend argues for the first method because it takes more time. (If IO is not a bottleneck)

Comments
Add Comment