diff --git a/doc/TODO b/doc/TODO index c414b39..697360b 100644 --- a/doc/TODO +++ b/doc/TODO @@ -78,15 +78,19 @@ t21 docs: consider better documentation for the "overwrite" term; add glossary t22 REJECTED - postponed to later version implement a "hook" for the overwrite operation (maybe as an adaptor) -t23 amend the source code according to the formal review (line 1578); use +t23 DONE - but the new iterator not applied (because of compilation problems + with VC6); only some improvements from the new iterator taken + amend the source code according to the formal review (line 1578); use the new iterator if possible -t24 ammend the test in order to compile with the new iterator if really +t24 REJECTED + ammend the test in order to compile with the new iterator if really needed (line 1857) t25 add constructor taking just two iterators as a parameter -t26 change the current implementation of "overwrite" operation -> overwrite +t26 DONE + change the current implementation of "overwrite" operation -> overwrite will be equivalent to assign t27 docs: apply the DefaultConstructible and Assignable type requirements @@ -139,7 +143,7 @@ t40 DONE - verify t41 REJECTED - not important; causing problems with generated documentation typedef for circular_buffer (line 4450) -t42 documentation may add some rationale on its internal data structures +t42 docs: documentation may add some rationale on its internal data structures and their advantage over std::deque t43 REJECTED - fixed another way diff --git a/include/boost/circular_buffer/adaptor.hpp b/include/boost/circular_buffer/adaptor.hpp index 81b1016..5878af3 100644 --- a/include/boost/circular_buffer/adaptor.hpp +++ b/include/boost/circular_buffer/adaptor.hpp @@ -505,7 +505,7 @@ private: //! Specialized insert method. template void insert(iterator pos, InputIterator n, InputIterator item, cb_details::int_tag) { - insert(pos, (size_type)n, item); + insert(pos, static_cast(n), item); } //! Specialized insert method. @@ -519,7 +519,7 @@ private: //! Specialized rinsert method. template void rinsert(iterator pos, InputIterator n, InputIterator item, cb_details::int_tag) { - rinsert(pos, (size_type)n, item); + rinsert(pos, static_cast(n), item); } //! Specialized rinsert method. diff --git a/include/boost/circular_buffer/base.hpp b/include/boost/circular_buffer/base.hpp index 2cf846c..1ebfafe 100644 --- a/include/boost/circular_buffer/base.hpp +++ b/include/boost/circular_buffer/base.hpp @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #if !defined(BOOST_NO_EXCEPTIONS) @@ -328,7 +329,9 @@ public: size_type size() const { return m_size; } //! Return the largest possible size (or capacity) of the circular buffer. - size_type max_size() const { return m_alloc.max_size(); } + size_type max_size() const { + return std::min(m_alloc.max_size(), static_cast(std::numeric_limits::max())); + } //! Is the circular buffer empty? /*! @@ -1199,7 +1202,7 @@ private: //! Specialized assign method. template void assign(IntegralType n, IntegralType item, cb_details::int_tag) { - assign((size_type)n, item); + assign(static_cast(n), item); } //! Specialized assign method. @@ -1248,7 +1251,7 @@ private: //! Specialized insert method. template void insert(iterator pos, IntegralType n, IntegralType item, cb_details::int_tag) { - insert(pos, (size_type)n, item); + insert(pos, static_cast(n), item); } //! Specialized insert method. @@ -1331,7 +1334,7 @@ private: //! Specialized rinsert method. template void rinsert(iterator pos, IntegralType n, IntegralType item, cb_details::int_tag) { - rinsert(pos, (size_type)n, item); + rinsert(pos, static_cast(n), item); } //! Specialized rinsert method. diff --git a/include/boost/circular_buffer/details.hpp b/include/boost/circular_buffer/details.hpp index 8bbd2c2..a773217 100644 --- a/include/boost/circular_buffer/details.hpp +++ b/include/boost/circular_buffer/details.hpp @@ -227,9 +227,9 @@ public: helper_pointer lhs = create_helper_pointer(*this); helper_pointer rhs = create_helper_pointer(it); if (less(rhs, lhs) && lhs.m_it <= rhs.m_it) - return lhs.m_it + m_buff->capacity() - rhs.m_it; + return (lhs.m_it - rhs.m_it) + static_cast(m_buff->capacity()); if (less(lhs, rhs) && lhs.m_it >= rhs.m_it) - return lhs.m_it - m_buff->capacity() - rhs.m_it; + return (lhs.m_it - rhs.m_it) - static_cast(m_buff->capacity()); return lhs.m_it - rhs.m_it; } @@ -355,39 +355,32 @@ private: return helper; } - //! Compare two pointers. - /*! - \return 1 if p1 is greater than p2. - \return 0 if p1 is equal to p2. - \return -1 if p1 is lower than p2. - */ - template - static difference_type compare(Pointer0 p1, Pointer1 p2) { - return p1 < p2 ? -1 : (p1 > p2 ? 1 : 0); - } - //! Less. template bool less(const InternalIterator0& lhs, const InternalIterator1& rhs) const { - switch (compare(lhs.m_it, m_buff->m_first)) { - case -1: - switch (compare(rhs.m_it, m_buff->m_first)) { - case -1: return lhs.m_it < rhs.m_it; - case 0: return rhs.m_end; - case 1: return false; - } - case 0: - switch (compare(rhs.m_it, m_buff->m_first)) { - case -1: return !lhs.m_end; - case 0: return !lhs.m_end && rhs.m_end; - case 1: return !lhs.m_end; - } - case 1: - switch (compare(rhs.m_it, m_buff->m_first)) { - case -1: return true; - case 0: return rhs.m_end; - case 1: return lhs.m_it < rhs.m_it; - } + difference_type ldiff = lhs.m_it - m_buff->m_first; + difference_type rdiff = rhs.m_it - m_buff->m_first; + if (ldiff < 0) { + if (rdiff < 0) + return lhs.m_it < rhs.m_it; + else if (rdiff == 0) + return rhs.m_end; + else + return false; + } else if (ldiff == 0) { + if (rdiff < 0) + return !lhs.m_end; + else if (rdiff == 0) + return !lhs.m_end && rhs.m_end; + else + return !lhs.m_end; + } else { // ldiff > 0 + if (rdiff < 0) + return true; + else if (rdiff == 0) + return rhs.m_end; + else + return lhs.m_it < rhs.m_it; } return false; } diff --git a/test/common.cpp b/test/common.cpp index 4661d44..82eec1f 100644 --- a/test/common.cpp +++ b/test/common.cpp @@ -129,16 +129,19 @@ void constructor_and_element_access_test() { void size_test() { - CB_CONTAINER cb(3); - cb.push_back(1); - cb.push_back(2); - cb.push_back(3); - cb.push_back(4); + CB_CONTAINER cb1(3); + cb1.push_back(1); + cb1.push_back(2); + cb1.push_back(3); + cb1.push_back(4); + CB_CONTAINER cb2(5); - BOOST_CHECK(cb.size() == 3); - BOOST_CHECK(cb.max_size() == cb.get_allocator().max_size()); + BOOST_CHECK(cb1.size() == 3); + BOOST_CHECK(cb2.size() == 0); + BOOST_CHECK(cb1.max_size() == cb2.max_size()); - generic_test(cb); + generic_test(cb1); + generic_test(cb2); } void boundary_capacity_test() {