- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Thanks in advance

Link Copied

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

The simple answer is: you can't get there from here.

The documentation for parallel_sort makes it clear: it has the same requirements for the sequences it sorts as std::sort, namely, the iterator by which you access the sequence must be at least a *random* *access iterator, *which is not usuallytrue of iterators attachable to lists. In particular, the algorithm underlying both std::sort and tbb::parallel_sort is based on Hoare's Quicksort algorithm, which needs to be able to partition subsequences and exchange elements of the sequence.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Which I believebasicallymeans that the container must have a random access iterator, which is not the case for std::list. The only solution I can think of is to copy the entire list into an std::vector, sort it and then copy it back, whichThe requirementson the iterator and sequence are the same as for std::sort. Specifically,RandomAccessIterator must be a random access iterator, ...

*could be*very inefficient. I think your better of either using std::vector from the beginning or using the std::list::sort function.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

{ vector tmp( x.begin(), x.end() ); sort(tmp.begin(),tmp.end()); x.assign(tmp.begin(),tmp.end()); }

was about twices as fast as x.sort().

Of course if the list is short or there is a large overhead for copying list items, then the results will not be as good. But perhapssorting avector of pointers to the items might work well (I did not try this).

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page