Re: clear() on vectors

From: joel (ploa_at_carrtol.com)
Date: 12/16/04

  • Next message: Mike Wahler: "Re: clear() on vectors"
    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?


  • Next message: Mike Wahler: "Re: clear() on vectors"

    Relevant Pages

    • Re: clear() on vectors
      ... "joel" wrote in message ... > vector cannot deallocate the memory? ... A vector does indeed handle its own memory management ...
      (alt.comp.lang.learn.c-cpp)
    • Re: clear() on vectors
      ... >> i am trying to write a vector class that includes a erase and clear ... >>without copying and ammending the header file. ... >> clearcalled the 2 iterator erase function, ...
      (alt.comp.lang.learn.c-cpp)
    • Re: clear() on vectors
      ... > i am trying to write a vector class that includes a erase and clear ... > clearcalled the 2 iterator erase function, ... > then call a memory management function to destroy and deallocate the ...
      (alt.comp.lang.learn.c-cpp)
    • Re: Help with some logic, best way to update a container.
      ... you could use make_pair to avoid having to specify the template ... Now that I look at my code, I see that indeed I use the <iterator, bool> return from ... you might implement in a map, as 65=1 (treating the letters as integers because you gave ... the documentation is sloppy; the erase method does not state this behavior. ...
      (microsoft.public.vc.mfc)
    • Re: Help with some logic, best way to update a container.
      ... you could use make_pair to avoid having to specify the template ... you might implement in a map, as 65=1 (treating the letters as integers because you gave ... Incrementing iter is undefined after you erase it. ... For containers whose erase returns an iterator, ...
      (microsoft.public.vc.mfc)