Boost logo

Boost Users :

From: Abir Basak (abirbasak_at_[hidden])
Date: 2007-11-17 14:32:02


Hi,
  One more question, what is the rule for circular buffer iterator
validation ? Though I had gone through the document, and which gives
some rule related to this, I need to know a few thing like this ,
I have a buffer which has enough memory to store all, the elements I
push onto it. Thus no memory re-allocation is needed (it is fixed
buffer, not the space optimized one), and no memory overwriting when
it is full, and thus no debug time assert due to that.
 int_buf buf(5);
        buf.push_back(1);
        buf.push_back(2);
        int_buf::const_iterator ite = buf.end();
        int_buf::const_iterator itb = ite-2;
        buf.push_back(3);
        buf.push_back(4);
std::for_each(itb,ite,std::cout<<_1<<"\t");
This case, I expect the iterators should not be invalidated, and print 1 2
However it prints 1 2 3 4. Why it is so ?
I need to push a few elements at a time to the buffer, and store a
boost::sub_range for this eg itb ,ite. and pop_front the same chunk. I
can make ensure that the buffer never gets full. WIll it be possible
in any way to store such iterator pair (I can't do this to deque as
that allocates memory and invalidates iterators)? Any other way the
same can be achieved (eg using some container aware iterator pair, or
container adapter)?
 I am also interested to the same for circular_buffer_space_optimized,
where memory allocation might occur, when minimum memory limit is
exhausted, but can ensure that never it is full (i.e no overwrite
occurs).
any boost library will help for that , where iterator invalidation
occurs only due to memory movement, not due to invalid element
location?

Thanking you.
abir basak

-- 
Abir Basak, Member IEEE
B. Tech , IIT KGP
Software Engineer, Read Ink Technologies

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net