Search code examples
c++listweberase

Does C++ list.erase(it, it) erase something? Where to find good references?


I mean in situation when the iterators point on same element.

On http://www.cplusplus.com/reference/stl/list/erase/ say "Removes from the list container either a single element (position) or a range of elements ([first,last))." and "first, last Iterators specifying a range within the list container to be removed: [first,last). i.e., the range includes all the elements between first and last, including the element pointed by first but not the one pointed by last."

I totally don't know if I do everything wrong but for every part of my code I don't find needed information anywhere and when I want to test it by myself, I end in a situation, when I don't know what happened and after asking here and arguing for long hours I find something like "undefined behavior". So can someone help me faster, what is it now?

And I want to be better programmer and find out better source than cplusplus.com and cppreference.com, because they both suck, is there something better? I am getting crazier every day with this C++ (but I still think it's much better for speedy huge programs than Java or C), please help.


Solution

  • The Standard's own definition of ranges (24.2.1p7, emphasis mine):

    Most of the library’s algorithmic templates that operate on data structures have interfaces that use ranges. A range is a pair of iterators that designate the beginning and end of the computation. A range [i,i) is an empty range; in general, a range [i,j) refers to the elements in the data structure starting with the element pointed to by i and up to but not including the element pointed to by j.

    So assuming it is a valid iterator in or past-the-end of lst, the call lst.erase(it,it) erases an empty set of elements from lst. That is, it does nothing.