Boost logo

Boost :

From: Pavel Vozenilek (pavel_vozenilek_at_[hidden])
Date: 2004-03-08 15:16:18


"David Abrahams" <dave_at_[hidden]> wrote

> No, I'm saying that their values can go away without destruction: you
> could replace their values in the buffer using assignment instead of
> destroy + construct. There's no a priori reason they have to be
> destroyed.
>
> When I erase objects from a std::vector, the objects being erased
> don't neccessarily get destroyed. They may be assigned. For
> example, here's STLPort's vector<T>::erase(iterator) implementation:
>
[snip code]
>
> Notice that only the last element of the vector is destroyed.
>

Quoting from similar discussion on c.l.c++.m: http://tinyurl.com/2c3na

--- quote about vector::erase ---
The standard says this: "The destructor of T is called the number of
times equal to the number of the elements erased, but the assignment
operator of T is called the number of times equal to the number of
elements in the vector after the erased elements."
------------------------------------

With circular buffer the destructor wouldn't be called at all,
in similar circumstance.

Eample:
   Circular buffer of size 3.
   You create 100 of objects and push them in.
    You would get:
      - 100 constructors called,
      - 97 copy constructors called,
      - 3 destructors called.

/Pavel


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk