ALiX wrote:
I am using a std::list<MyClass> where objects of type MyClass can be
big in size. Can using std::list<>::sort result in objects inside the
list being copied around or does the list merely reassign internal
pointers? Is there any such demands/guarantees from the standard?
Regards,
ALiX
Here is everything the standard has to say about list's sort member.
void sort();
template <class Compare> void sort(Compare comp);
Requires: operator< (for the first version) or comp (for the second
version) defines a strict weak
ordering (25.3).
Effects: Sorts the list according to the operator< or a Compare function
object.
Notes: Stable: the relative order of the equivalent elements is
preserved. If an exception is thrown the
order of the elements in the list is indeterminate.
Complexity: Approximately NlogN comparisons, where N == size().
My interpretation is that copying of objects is not forbidden (even if
most implementations optimize such that it doesn't happen).