Do Pointers which point to elements of a std::list remain valid if I call the sort() method over the list? Is there a guarantee for this (standard)? It seems to work under Visual Studio 2012.
2 Answers
From "Working Draft C++, 2012-11-02"
23.3.5.5 list operations [list.ops]
void sort();
template <class Compare> void sort(Compare comp);
28 Requires:operator<(for the first version) or comp (for the second version) shall define a strict weak ordering (25.4).
29 Effects: Sorts the list according to theoperator<or aComparefunction object. Does not affect the validity of iterators and references.
30 Remarks: Stable.
31 Complexity: Approximately N log(N ) comparisons, whereN == size().