diff --git a/include/boost/circular_buffer/adaptor.hpp b/include/boost/circular_buffer/adaptor.hpp index 2c0256e..d0d5f71 100644 --- a/include/boost/circular_buffer/adaptor.hpp +++ b/include/boost/circular_buffer/adaptor.hpp @@ -353,7 +353,7 @@ public: */ template void insert(iterator pos, InputIterator first, InputIterator last) { - insert(pos, first, last, BOOST_DEDUCED_TYPENAME cb_details::iterator_category_traits::tag()); + insert(pos, first, last, BOOST_DEDUCED_TYPENAME cb_details::iterator_cat_traits::tag()); } //!! See the circular_buffer source documentation. @@ -388,7 +388,7 @@ public: */ template void rinsert(iterator pos, InputIterator first, InputIterator last) { - rinsert(pos, first, last, BOOST_DEDUCED_TYPENAME cb_details::iterator_category_traits::tag()); + rinsert(pos, first, last, BOOST_DEDUCED_TYPENAME cb_details::iterator_cat_traits::tag()); } //!! See the circular_buffer source documentation. @@ -501,13 +501,13 @@ private: //! Helper insert method. template - void insert(iterator pos, InputIterator n, InputIterator item, cb_details::int_iterator_tag) { + void insert(iterator pos, InputIterator n, InputIterator item, cb_details::int_tag) { insert(pos, (size_type)n, item); } //! Helper insert method. template - void insert(iterator pos, InputIterator first, InputIterator last, std::input_iterator_tag) { + void insert(iterator pos, InputIterator first, InputIterator last, cb_details::iterator_tag) { size_type index = pos - begin(); check_low_capacity(std::distance(first, last)); circular_buffer::insert(begin() + index, first, last); @@ -515,13 +515,13 @@ private: //! Helper rinsert method. template - void rinsert(iterator pos, InputIterator n, InputIterator item, cb_details::int_iterator_tag) { + void rinsert(iterator pos, InputIterator n, InputIterator item, cb_details::int_tag) { rinsert(pos, (size_type)n, item); } //! Helper rinsert method. template - void rinsert(iterator pos, InputIterator first, InputIterator last, std::input_iterator_tag) { + void rinsert(iterator pos, InputIterator first, InputIterator last, cb_details::iterator_tag) { size_type index = pos - begin(); check_low_capacity(std::distance(first, last)); circular_buffer::rinsert(begin() + index, first, last); diff --git a/include/boost/circular_buffer/base.hpp b/include/boost/circular_buffer/base.hpp index ffdf15c..c06a90f 100644 --- a/include/boost/circular_buffer/base.hpp +++ b/include/boost/circular_buffer/base.hpp @@ -557,7 +557,7 @@ public: */ template void assign(InputIterator first, InputIterator last) { - assign(first, last, BOOST_DEDUCED_TYPENAME cb_details::iterator_category_traits::tag()); + assign(first, last, BOOST_DEDUCED_TYPENAME cb_details::iterator_cat_traits::tag()); } //! Swap the contents of two circular buffers. @@ -774,7 +774,7 @@ public: template void insert(iterator pos, InputIterator first, InputIterator last) { BOOST_CB_ASSERT(pos.is_valid()); // check for uninitialized or invalidated iterator - insert(pos, first, last, BOOST_DEDUCED_TYPENAME cb_details::iterator_category_traits::tag()); + insert(pos, first, last, BOOST_DEDUCED_TYPENAME cb_details::iterator_cat_traits::tag()); } //! Insert an item before the given position. @@ -874,7 +874,7 @@ public: template void rinsert(iterator pos, InputIterator first, InputIterator last) { BOOST_CB_ASSERT(pos.is_valid()); // check for uninitialized or invalidated iterator - rinsert(pos, first, last, BOOST_DEDUCED_TYPENAME cb_details::iterator_category_traits::tag()); + rinsert(pos, first, last, BOOST_DEDUCED_TYPENAME cb_details::iterator_cat_traits::tag()); } // Erase @@ -1016,29 +1016,29 @@ private: } //! Increment the pointer. - template - void increment(Pointer0& p) const { + template + void increment(Pointer& p) const { if (++p == m_end) p = m_buff; } //! Decrement the pointer. - template - void decrement(Pointer0& p) const { + template + void decrement(Pointer& p) const { if (p == m_buff) p = m_end; --p; } //! Add n to the pointer. - template - Pointer0 add(Pointer0 p, difference_type n) const { + template + Pointer add(Pointer p, difference_type n) const { return p + (n < (m_end - p) ? n : n - capacity()); } //! Subtract n from the pointer. - template - Pointer0 sub(Pointer0 p, difference_type n) const { + template + Pointer sub(Pointer p, difference_type n) const { return p - (n > (p - m_buff) ? n - capacity() : n); } @@ -1124,17 +1124,29 @@ private: } //! Specialized assign method. - template - void assign(InputIterator n, InputIterator item, cb_details::int_iterator_tag) { + template + void assign(IntegralType n, IntegralType item, cb_details::int_tag) { assign((size_type)n, item); } + //! Specialized assign method. + template + void assign(Iterator first, Iterator last, cb_details::iterator_tag) { + BOOST_CB_IS_CONVERTIBLE(Iterator, value_type); + assign(first, last, BOOST_DEDUCED_TYPENAME BOOST_ITERATOR_CATEGORY::type()); + } + //! Specialized assign method. template void assign(InputIterator first, InputIterator last, std::input_iterator_tag) { - BOOST_CB_IS_CONVERTIBLE(InputIterator, value_type); + + } + + //! Specialized assign method. + template + void assign(ForwardIterator first, ForwardIterator last, std::forward_iterator_tag) { BOOST_CB_ASSERT(std::distance(first, last) >= 0); // check for wrong range - do_assign(std::distance(first, last), assign_range(first, last, m_alloc)); + do_assign(std::distance(first, last), assign_range(first, last, m_alloc)); } //! Helper assign method. @@ -1161,13 +1173,13 @@ private: //! Specialized insert method. template - void insert(iterator pos, InputIterator n, InputIterator item, cb_details::int_iterator_tag) { + void insert(iterator pos, InputIterator n, InputIterator item, cb_details::int_tag) { insert(pos, (size_type)n, item); } //! Specialized insert method. template - void insert(iterator pos, InputIterator first, InputIterator last, std::input_iterator_tag) { + void insert(iterator pos, InputIterator first, InputIterator last, cb_details::iterator_tag) { BOOST_CB_IS_CONVERTIBLE(InputIterator, value_type); BOOST_CB_ASSERT(std::distance(first, last) >= 0); // check for wrong range difference_type n = std::distance(first, last); @@ -1229,13 +1241,13 @@ private: //! Specialized rinsert method. template - void rinsert(iterator pos, InputIterator n, InputIterator item, cb_details::int_iterator_tag) { + void rinsert(iterator pos, InputIterator n, InputIterator item, cb_details::int_tag) { rinsert(pos, (size_type)n, item); } //! Specialized rinsert method. template - void rinsert(iterator pos, InputIterator first, InputIterator last, std::input_iterator_tag) { + void rinsert(iterator pos, InputIterator first, InputIterator last, cb_details::iterator_tag) { BOOST_CB_IS_CONVERTIBLE(InputIterator, value_type); BOOST_CB_ASSERT(std::distance(first, last) >= 0); // check for wrong range rinsert_n_item(pos, std::distance(first, last), iterator_wrapper(first)); diff --git a/include/boost/circular_buffer/debug.hpp b/include/boost/circular_buffer/debug.hpp index 02130eb..748be2d 100644 --- a/include/boost/circular_buffer/debug.hpp +++ b/include/boost/circular_buffer/debug.hpp @@ -130,11 +130,11 @@ public: } //! Invalidate every iterator conforming to the condition. - template - void invalidate_iterators(const Iterator0& it) { + template + void invalidate_iterators(const Iterator& it) { const iterator_base* previous = 0; for (const iterator_base* p = m_iterators; p != 0; p = p->next()) { - if (((Iterator0*)p)->m_it == it.m_it) { + if (((Iterator*)p)->m_it == it.m_it) { p->invalidate(); remove(p, previous); continue; diff --git a/include/boost/circular_buffer/details.hpp b/include/boost/circular_buffer/details.hpp index dbc64c5..6c940e0 100644 --- a/include/boost/circular_buffer/details.hpp +++ b/include/boost/circular_buffer/details.hpp @@ -25,47 +25,57 @@ namespace cb_details { const int UNINITIALIZED = 0xcc; /*! - \struct int_iterator_tag - \brief Identifying tag for integer types (not for iterators). + \struct iterator_tag + \brief Identifying tag for iterator types. */ -struct int_iterator_tag { +struct iterator_tag { #if BOOST_WORKAROUND(__BORLANDC__, < 0x6000) char dummy_; // BCB: by default empty structure has 8 bytes #endif }; /*! - \struct iterator_category - \brief Defines iterator category. + \struct int_tag + \brief Identifying tag for integer types. */ -template -struct iterator_category { - //! Represents iterators. - typedef std::input_iterator_tag iterator_category_tag; -}; - -template <> -struct iterator_category { - //! Represents integral types (not iterators). - typedef int_iterator_tag iterator_category_tag; +struct int_tag { +#if BOOST_WORKAROUND(__BORLANDC__, < 0x6000) + char dummy_; // BCB: by default empty structure has 8 bytes +#endif }; /*! - \struct iterator_category_traits + \struct iterator_cat + \brief Defines iterator category. +*/ +template +struct iterator_cat { + //! Represents iterators. + typedef iterator_tag iterator_cat_tag; +}; + +template <> +struct iterator_cat { + //! Represents integral types (not iterators). + typedef int_tag iterator_cat_tag; +}; + +/*! + \struct iterator_cat_traits \brief Defines the iterator category tag for the given iterator. */ template -struct iterator_category_traits { +struct iterator_cat_traits { //! Iterator category tag type. /*! Depending on the template parameter the tag distinguishes between iterators and non-iterators. If the template parameter - is an iterator, the tag is typedef for std::input_iterator_tag. + is an iterator, the tag is typedef for iterator_tag. If the parameter is not an iterator, the tag is typedef for - int_iterator_tag. + int_tag. */ - typedef typename iterator_category< - is_integral::value>::iterator_category_tag tag; + typedef typename iterator_cat< + is_integral::value>::iterator_cat_tag tag; }; template struct nonconst_traits; @@ -110,10 +120,10 @@ struct nonconst_traits { \struct helper_pointer \brief Helper pointer used in the iterator. */ -template +template struct helper_pointer { bool m_end; - typename Traits0::pointer m_it; + typename Traits::pointer m_it; }; /*!