Boost logo

Boost :

From: Jan Gaspar (jga_at_[hidden])
Date: 2003-08-04 04:22:44


Hi Pavel,
I agree with most of your comments.

>
> 2. in function cb_iterator::operator -(), shouldn't it be std::less instead
> of less? (actually I do not see why < isn't enough here).

I call less() just because efficiency reasons. If I called operator < it would
result in unnecessary calls to create_internal_iterator().

>
> 5. Similarly in circular_buffer::allocate(). (I wonder where
> std::length_error
> does come from?)

The STL delivered with MSVC7 does it like this. In your opinion what should it
throw?

Once again unused space overhead. What about this adaptor?

template <class T> class Adaptor {
public:
    typedef typename circular_buffer<T>::iterator iterator;
    typedef typename circular_buffer<T>::size_type size_type;
private:
 size_type m_final_capacity;
    circular_buffer<T> m_buff;
public:
    Adaptor(size_type capacity) : m_final_capacity(capacity), m_buff(1) {}

    iterator begin() { return m_buff.begin(); }
    iterator end() { return m_buff.end(); }
    size_type size() const { return m_buff.size(); }
    size_type capacity() const { return m_final_capacity; }
    T& operator [] (size_type index) { return m_buff[index]; }

 void push_back(const T& item) {
  check_capacity();
  m_buff.push_back(item);
 }

 iterator insert(iterator pos, const T& item) {
  check_capacity();
  return m_buff.insert(pos, item);
 }
private:
 void check_capacity() {
  if (m_buff.full() && m_buff.size() < m_final_capacity) {
   size_type new_capacity = m_buff.size() * 2;
   if (new_capacity > m_final_capacity)
    new_capacity = m_final_capacity;
   m_buff.set_capacity(new_capacity);
  }
 }
};

Jan


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