Afficher un message
Vieux 06/02/2008, 14h44   #4
Triple-DES
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: some operations present only for list<T>

On 6 Feb, 12:23, Phil Endecott <spam_from_usenet_0...@chezphil.org>
wrote:
> Triple-DES wrote:
> > On 6 Feb, 09:30, "subramanian10...@yahoo.com, India"
> > <subramanian10...@yahoo.com> wrote:
> >> There are some operations like sort, remove, remove_if which are
> >> available as list<T> member functions; but vector<T>, deque<T> do not
> >> seem have those functions. If am correct in this, what is the reason
> >> for that. Moreover sort, remove, remove_if are available in
> >> <algorithm> also. Then why does list<T> have these member operations ?

> > As for std::sort, this algorithm requires random access iterators,
> > while list only has bidirectional iterators. Therefore it needs its
> > own sort function.

>
> Does anyone know why this is not done with a specialisation of the sort
> algorithm?


It may not be impossible to do it, but I for one can't think of a good
way to implement it. The naive approach

template<typename T>
void sort(typename std::list<T>::iterator first, typename
std::list<T>::iterator last)

doesn't work because the nested type can not be deduced (14.8.2.4/4).
Obtaining the actual container from just the two iterators could also
be a problem.
  Réponse avec citation
 
Page generated in 0,04923 seconds with 9 queries