Re: clear() on vectors
From: joel (ploa_at_carrtol.com)
Date: 12/16/04
- Previous message: jeffc: "Re: Polymorphism"
- In reply to: Mike Wahler: "Re: clear() on vectors"
- Next in thread: Mike Wahler: "Re: clear() on vectors"
- Reply: Mike Wahler: "Re: clear() on vectors"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 16 Dec 2004 19:39:52 +0000
On Thu, 16 Dec 2004 19:17:45 GMT, "Mike Wahler"
<mkwahler@mkwahler.net> wrote:
>"joel" <ploa@carrtol.com> wrote in message
>news:sal3s01tg0mhkk3p1ej87nhv7rcsquh8bn@4ax.com...
>> i am trying to find out how clear() works .
>
>How it actually works is up to the implementation.
>
>> As it takes two iterators
>> for begin and end of the vector,
>
>No it does not. vector::clear() takes no arguments
>and does does return a value.
>
>> what is done to this range?
>
>vector::clear() erases all elements from the vector.
>
>>Is each
>> iterator
>
>
>vector::clear() doesn't take any arguments, iterator
>or otherwise. It effectively performs:
>
>erase(begin(), end());
>
>(See ISO/IEC 14882 23.1.1 Table 67 -- Sequence requirements)
>
>>sent to erase (taking one iterator) where it is destroyed?
>> Or does it just set each iterator's value to null,
>
>A 'null' value does not apply to iterators. They're
>either valid or not.
>
>> assuming that a
>> vector cannot deallocate the memory?
>
>A vector does indeed handle its own memory management
>(i.e. allocation and deallocation)
>
>Which C++ book(s) are you reading? Perhaps you need
>more or better ones.
>
>
>-Mike
>
sorry, for clear() i meant what it does after calling it.
i am trying to write a vector class that includes a erase and clear
function, without copying and ammending the header file.
as there a two overloaded functions for erase, i didnt know whether
clear() called the 2 iterator erase function, which as part of its
algorithm, was to erase each iterator by passing it to the other erase
function
in the vector include file for msvc++ 2003 it says
void clear()
{ // erase all elements
erase(begin(), end());
}
in this erase function that takes two iterators does it clear the
values like
while(i != j)
{ *i = 0;
++i;
}
return i;
then call a memory management function to destroy and deallocate the
vector?
- Previous message: jeffc: "Re: Polymorphism"
- In reply to: Mike Wahler: "Re: clear() on vectors"
- Next in thread: Mike Wahler: "Re: clear() on vectors"
- Reply: Mike Wahler: "Re: clear() on vectors"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|