Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C++ (http://www.velocityreviews.com/forums/f39-c.html)
-   -   is this true? sort algo on STL Lists (http://www.velocityreviews.com/forums/t453149-is-this-true-sort-algo-on-stl-lists.html)

Bit byte 04-06-2006 09:11 PM

is this true? sort algo on STL Lists
 
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?


Thomas Tutone 04-06-2006 09:18 PM

Re: is this true? sort algo on STL Lists
 

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


Victor Bazarov 04-06-2006 09:19 PM

Re: is this true? sort algo on STL Lists
 
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?


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
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask




All times are GMT. The time now is 06:36 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.