some operations present only for list



 DEVELOP > c-Plus-Plus > some operations present only for list

LINK TO THIS PAGE  


rating :  0   |  0


  Page 1 of 1

1

 
Topic: DEVELOP > c-Plus-Plus
User: "India"
Date: 06 Feb 2008 02:30:19 AM
Object: some operations present only for list
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 ?
Kindly clarify.
Thanks
V.Subramanian
.

User: "Triple-DES"

Title: Re: some operations present only for list 06 Feb 2008 03:37:11 AM
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 ?

The algorithms in <algorithm> operate on ranges, not containers.
Therefore, an algorithm like std::remove_if will not actually remove
any elements, just copy the elements not removed to the front of the
range, and return a new end iterator.
The member functions of list naturally operate on the list itself.
Therefore list<T>::remove and list<T>::remove_if will actually erase
the elements from the list.
In general using the member functions where present will be faster,
and they often do slightly different things.
As for std::sort, this algorithm requires random access iterators,
while list only has bidirectional iterators. Therefore it needs its
own sort function.
.


  Page 1 of 1

1

 


Related Articles
 

NEWER

pg.1232     pg.940     pg.716     pg.544     pg.412     pg.311     pg.234     pg.175     pg.130     pg.96     pg.70     pg.50     pg.35     pg.24     pg.16     pg.10     pg.6     pg.3     pg.1

OLDER