is this true? sort algo on STL Lists

B

Bit byte

I just came accross this : "Note that the STL sort algorithm does NOT
work for lists; that's why a sort member function is supplied."

Is this true?
Has this been fixed in newer versions of the STL?
 
T

Thomas Tutone

Bit byte wrote:

I just came accross this : "Note that the STL sort algorithm does NOT
work for lists; that's why a sort member function is supplied."

Is this true?

Yes. std::sort requires random-access iterators, which std::list does
not supply.
Has this been fixed in newer versions of the STL?

There's nothing to fix. If you need to sort a list, you can use
std::list's member function std::list::sort, which will do the job.
That's been the case since the C++ standard was adopted in 1998, and it
hasn't changed.

Best regards,

Tom
 
V

Victor Bazarov

Bit said:
I just came accross this : "Note that the STL sort algorithm does NOT
work for lists; that's why a sort member function is supplied."

Is this true?

Of course. std::sort requires random-access iterators, std::list's
iterators are not of that kind.
Has this been fixed in newer versions of the STL?

Of course not.

V
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,434
Messages
2,571,691
Members
48,796
Latest member
Greg L.

Latest Threads

Top