this one was bad advice..

http://www.cplusplus.com/reference/deque/deque/erase/

just saying..maybe call the iterators "begin" and "end", or at least don't call the second one "last" when it is not the last, even if it's explained that it is not the last to erase. end, wall, stop, onebehindlast or anything like that.
In tend to name the parameters 'begin' and 'end'.

Koenig and Moo (C++ Report, Ruminations on C++) call them 'start' and 'beyond'.

The IS consistently uses the terms 'first' and 'last'. Programmers quickly get used to the idea that 'last', as normally used in C++, is really one beyond the actual last element, and avoid writing stuff like:
1
2
3
4
5
6
if( !vec.empty() )
{
     auto first = vec.begin() ; // iterator to the first item
     auto last = vec.end() - 1 ; // iterator to the actual last element
     // ...
}
closed account (E0p9LyTq)
Then complain to the ISO standards committee, they were the ones who chose that wording.
closed account (1vD3vCM9)
You can also get all the contents of a Vector or an Array with an for each loop:
1
2
3
4
for(const auto& it : vec)
{
std::cout << it << "\n";
}
Last edited on
Topic archived. No new replies allowed.