Boost logo

Boost Users :

Subject: Re: [Boost-users] circular_buffer, debug and invalid iterator checking
From: Anthony Foglia (AFoglia_at_[hidden])
Date: 2010-11-17 16:40:45


Still working on my circular_buffer iterator invalidation problems, and
another issue arose. As I mentioned before my class is roughly

class MyContainer {
   private:
     circular_buffer<T> my_buffer;
     vector<circular_buffer<T>::const_iterator> my_range_ends;
   // omitted
}

I'm trying to add a swap method, and the obvious approach does not work:

void MyContainter::swap(MyContainer & other) {
     using std::swap;
     swap(my_buffer, other.my_buffer);
     swap(my_range_ends, other.my_range_ends);
}

This is unsurprising, because of the iterator invalidation rules. So
I'll need to manually figure out the distances and create temporary
vectors to hold my_range_ends. But this just seems like too much
trouble if I'm not in debug mode. If the BOOST_CB_ENABLE_DEBUG macro
hadn't been undefined by circular_buffer.hpp I could wrap my hand-coded
iterator swapping in #if...#endif, and otherwise just use std::swap.

I think this is a valid use case for leaving that macro defined. Any
reasons I should not file a ticket requesting the change?

-- 
Anthony Foglia
Princeton Consultants
(609) 987-8787 x233

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