Hi Daniele,
The circular_buffer behaves like a sliding window - which is what you don't want apparently. If you want the behaviour you described have a look at array_one() and array_two() methods.
With regards,
Jan
----- Original Message ----
From: Daniele Barzotti
To: boost-users@lists.boost.org
Sent: Fri, 16 April, 2010 15:31:31
Subject: [Boost-users] [circular_buffer] About overwriting elements
Hi,
in the introductory example I see this:
int a = cb[0]; // a == 1
int b = cb[1]; // b == 2
int c = cb[2]; // c == 3
// The buffer is full now, pushing subsequent
// elements will overwrite the front-most elements.
cb.push_back(4); // Overwrite 1 with 4.
cb.push_back(5); // Overwrite 2 with 5.
// The buffer now contains 3, 4 and 5.
a = cb[0]; // a == 3
b = cb[1]; // b == 4
c = cb[2]; // c == 5
and I would ask why the 4 and 5 are in the 2nd and 3th position instead
of 1st and 2nd respectively.
I thought that it worked in the following way:
1 2 3 1 2 3 1 2 3
[A][B][C] -> push_back(D) -> [D][B][C] -> push_back(E) -> [D][E][C]
I need a circular buffer for buffering network data and I need that the
old data is replaced but doesn't change its position..
Thanks,
Daniele.
_______________________________________________
Boost-users mailing list
Boost-users@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users