circular_buffer icon indicating copy to clipboard operation
circular_buffer copied to clipboard

full() returns false even if the circular buffer is full

Open f18m opened this issue 6 years ago • 1 comments

Hi, I have created a boost::circular_buffer<my_class_type> using the default ctor. Then I call set_capacity(100) and then I push_back() a thousand elements: the size() of the circular buffer is reported as 99 and thus the function full() always return false.

I think this is very misleading: my belief is that instead of having:

bool full() const BOOST_NOEXCEPT { return capacity() == size(); }

we should have:

bool full() const BOOST_NOEXCEPT { return capacity()-1 == size(); }

What am I missing?

Thanks, Francesco

f18m avatar Oct 23 '18 10:10 f18m

I'm not able to reproduce this. Using boost 1.70 and gcc 9.1, the following test has no failures:

BOOST_AUTO_TEST_CASE(cb_full_test) {
    boost::circular_buffer<int> q;
    q.set_capacity(100);
    BOOST_REQUIRE_EQUAL(100u, q.capacity());
    for (int i = 0; i < 1000; ++i) {
        q.push_back(i);
    }
    BOOST_CHECK_EQUAL(100u, q.size());
    BOOST_CHECK(q.full());
}

usefulcat avatar Feb 04 '21 18:02 usefulcat