Boost logo

Boost :

From: Jan Gaspar (jga_at_[hidden])
Date: 2003-07-16 07:40:24


Hi all!

The updated implementation and docs of the circular buffer (formerly called cyclic
buffer) can be found at
http://groups.yahoo.com/group/boost/files/circular_buffer.zip

To Howard Hinnant:

Probably I won't have time for doing the circular_deque but you can achieve the
insert method by adapting the circular buffer.

template <class T> class Adaptor {
private:
    circular_buffer<T> m_buff;
public:
    typedef typename circular_buffer<T>::iterator iterator;
    typedef typename circular_buffer<T>::size_type size_type;

    Adaptor(size_type capacity) : m_buff(capacity) {}
    template <class InputIterator>
    Adaptor(size_type capacity, InputIterator first, InputIterator last)
    : m_buff(capacity, first, last) {}

    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_buff.capacity(); }
    T& operator [] (size_type index) { return m_buff[index]; }

    template <class InputIterator>
    void insert(iterator pos, InputIterator first, InputIterator last) {
        size_type new_size = size() + distance(first, last);
        if (new_size > capacity()) {
            circular_buffer<T> buff(new_size, begin(), pos);
            buff.insert(buff.end(), first, last);
            buff.insert(buff.end(), pos, end());
            m_buff.swap(buff);
        } else {
            m_buff.insert(pos, first, last);
        }
    }
};

Regards,

Jan

--
Jan Gaspar | jga_at_[hidden]
Whitestein Technologies | www.whitestein.com
Panenska 28 | SK-81103 Bratislava | Slovak Republic
Tel +421(2)5930-0735 | Fax +421(2)5443-5512

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