update boost
This commit is contained in:
@@ -1,89 +0,0 @@
|
||||
// Copyright 2018 Glen Joseph Fernandes
|
||||
// (glenjofe@gmail.com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#ifndef BOOST_CIRCULAR_BUFFER_ALLOCATORS_HPP
|
||||
#define BOOST_CIRCULAR_BUFFER_ALLOCATORS_HPP
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#if defined(BOOST_NO_CXX11_ALLOCATOR)
|
||||
#define BOOST_CB_NO_CXX11_ALLOCATOR
|
||||
#elif defined(BOOST_LIBSTDCXX_VERSION) && (BOOST_LIBSTDCXX_VERSION < 40800)
|
||||
#define BOOST_CB_NO_CXX11_ALLOCATOR
|
||||
#endif
|
||||
#include <limits>
|
||||
#if !defined(BOOST_CB_NO_CXX11_ALLOCATOR)
|
||||
#include <memory>
|
||||
#else
|
||||
#include <new>
|
||||
#endif
|
||||
#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
|
||||
#include <utility>
|
||||
#endif
|
||||
|
||||
namespace boost {
|
||||
namespace cb_details {
|
||||
|
||||
#if !defined(BOOST_CB_NO_CXX11_ALLOCATOR)
|
||||
template<class A>
|
||||
struct allocator_traits
|
||||
: std::allocator_traits<A> {
|
||||
using typename std::allocator_traits<A>::value_type;
|
||||
using typename std::allocator_traits<A>::size_type;
|
||||
|
||||
static size_type max_size(const A&) BOOST_NOEXCEPT {
|
||||
return (std::numeric_limits<size_type>::max)() / sizeof(value_type);
|
||||
}
|
||||
};
|
||||
#else
|
||||
template<class A>
|
||||
struct allocator_traits {
|
||||
typedef typename A::value_type value_type;
|
||||
typedef typename A::pointer pointer;
|
||||
typedef typename A::const_pointer const_pointer;
|
||||
typedef typename A::difference_type difference_type;
|
||||
typedef typename A::size_type size_type;
|
||||
|
||||
static size_type max_size(const A&) BOOST_NOEXCEPT {
|
||||
return (std::numeric_limits<size_type>::max)() / sizeof(value_type);
|
||||
}
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
|
||||
#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
|
||||
template<class U, class... Args>
|
||||
static void construct(const A&, U* ptr, Args&&... args) {
|
||||
::new((void*)ptr) U(std::forward<Args>(args)...);
|
||||
}
|
||||
#else
|
||||
template<class U, class V>
|
||||
static void construct(const A&, U* ptr, V&& value) {
|
||||
::new((void*)ptr) U(std::forward<V>(value));
|
||||
}
|
||||
#endif
|
||||
#else
|
||||
template<class U, class V>
|
||||
static void construct(const A&, U* ptr, const V& value) {
|
||||
::new((void*)ptr) U(value);
|
||||
}
|
||||
|
||||
template<class U, class V>
|
||||
static void construct(const A&, U* ptr, V& value) {
|
||||
::new((void*)ptr) U(value);
|
||||
}
|
||||
#endif
|
||||
|
||||
template<class U>
|
||||
static void destroy(const A&, U* ptr) {
|
||||
(void)ptr;
|
||||
ptr->~U();
|
||||
}
|
||||
};
|
||||
#endif
|
||||
|
||||
} // cb_details
|
||||
} // boost
|
||||
|
||||
#endif
|
||||
@@ -21,7 +21,7 @@
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/concept_check.hpp>
|
||||
#include <boost/limits.hpp>
|
||||
#include <boost/circular_buffer/allocators.hpp>
|
||||
#include <boost/core/allocator_access.hpp>
|
||||
#include <boost/core/empty_value.hpp>
|
||||
#include <boost/type_traits/is_stateless.hpp>
|
||||
#include <boost/type_traits/is_integral.hpp>
|
||||
@@ -49,14 +49,14 @@ namespace boost {
|
||||
\brief Circular buffer - a STL compliant container.
|
||||
\tparam T The type of the elements stored in the <code>circular_buffer</code>.
|
||||
\par Type Requirements T
|
||||
The <code>T</code> has to be <a href="http://www.sgi.com/tech/stl/Assignable.html">
|
||||
The <code>T</code> has to be <a href="https://www.boost.org/sgi/stl/Assignable.html">
|
||||
SGIAssignable</a> (SGI STL defined combination of <a href="../../../utility/Assignable.html">
|
||||
Assignable</a> and <a href="../../../utility/CopyConstructible.html">CopyConstructible</a>).
|
||||
Moreover <code>T</code> has to be <a href="http://www.sgi.com/tech/stl/DefaultConstructible.html">
|
||||
Moreover <code>T</code> has to be <a href="https://www.boost.org/sgi/stl/DefaultConstructible.html">
|
||||
DefaultConstructible</a> if supplied as a default parameter when invoking some of the
|
||||
<code>circular_buffer</code>'s methods e.g.
|
||||
<code>insert(iterator pos, const value_type& item = %value_type())</code>. And
|
||||
<a href="http://www.sgi.com/tech/stl/EqualityComparable.html">EqualityComparable</a> and/or
|
||||
<a href="https://www.boost.org/sgi/stl/EqualityComparable.html">EqualityComparable</a> and/or
|
||||
<a href="../../../utility/LessThanComparable.html">LessThanComparable</a> if the <code>circular_buffer</code>
|
||||
will be compared with another container.
|
||||
\tparam Alloc The allocator type used for all internal memory management.
|
||||
@@ -99,13 +99,13 @@ public:
|
||||
typedef circular_buffer<T, Alloc> this_type;
|
||||
|
||||
//! The type of elements stored in the <code>circular_buffer</code>.
|
||||
typedef typename cb_details::allocator_traits<Alloc>::value_type value_type;
|
||||
typedef typename Alloc::value_type value_type;
|
||||
|
||||
//! A pointer to an element.
|
||||
typedef typename cb_details::allocator_traits<Alloc>::pointer pointer;
|
||||
typedef typename allocator_pointer<Alloc>::type pointer;
|
||||
|
||||
//! A const pointer to the element.
|
||||
typedef typename cb_details::allocator_traits<Alloc>::const_pointer const_pointer;
|
||||
typedef typename allocator_const_pointer<Alloc>::type const_pointer;
|
||||
|
||||
//! A reference to an element.
|
||||
typedef value_type& reference;
|
||||
@@ -117,13 +117,13 @@ public:
|
||||
/*!
|
||||
(A signed integral type used to represent the distance between two iterators.)
|
||||
*/
|
||||
typedef typename cb_details::allocator_traits<Alloc>::difference_type difference_type;
|
||||
typedef typename allocator_difference_type<Alloc>::type difference_type;
|
||||
|
||||
//! The size type.
|
||||
/*!
|
||||
(An unsigned integral type that can represent any non-negative value of the container's distance type.)
|
||||
*/
|
||||
typedef typename cb_details::allocator_traits<Alloc>::size_type size_type;
|
||||
typedef typename allocator_size_type<Alloc>::type size_type;
|
||||
|
||||
//! The type of an allocator used in the <code>circular_buffer</code>.
|
||||
typedef Alloc allocator_type;
|
||||
@@ -131,10 +131,10 @@ public:
|
||||
// Iterators
|
||||
|
||||
//! A const (random access) iterator used to iterate through the <code>circular_buffer</code>.
|
||||
typedef cb_details::iterator< circular_buffer<T, Alloc>, cb_details::const_traits<cb_details::allocator_traits<Alloc> > > const_iterator;
|
||||
typedef cb_details::iterator< circular_buffer<T, Alloc>, cb_details::const_traits<Alloc> > const_iterator;
|
||||
|
||||
//! A (random access) iterator used to iterate through the <code>circular_buffer</code>.
|
||||
typedef cb_details::iterator< circular_buffer<T, Alloc>, cb_details::nonconst_traits<cb_details::allocator_traits<Alloc> > > iterator;
|
||||
typedef cb_details::iterator< circular_buffer<T, Alloc>, cb_details::nonconst_traits<Alloc> > iterator;
|
||||
|
||||
//! A const iterator used to iterate backwards through a <code>circular_buffer</code>.
|
||||
typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
|
||||
@@ -146,7 +146,7 @@ public:
|
||||
|
||||
//! An array range.
|
||||
/*!
|
||||
(A typedef for the <a href="http://www.sgi.com/tech/stl/pair.html"><code>std::pair</code></a> where
|
||||
(A typedef for the <a href="https://www.boost.org/sgi/stl/pair.html"><code>std::pair</code></a> where
|
||||
its first element is a pointer to a beginning of an array and its second element represents
|
||||
a size of the array.)
|
||||
*/
|
||||
@@ -154,7 +154,7 @@ public:
|
||||
|
||||
//! A range of a const array.
|
||||
/*!
|
||||
(A typedef for the <a href="http://www.sgi.com/tech/stl/pair.html"><code>std::pair</code></a> where
|
||||
(A typedef for the <a href="https://www.boost.org/sgi/stl/pair.html"><code>std::pair</code></a> where
|
||||
its first element is a pointer to a beginning of a const array and its second element represents
|
||||
a size of the const array.)
|
||||
*/
|
||||
@@ -287,6 +287,7 @@ public:
|
||||
*/
|
||||
const_iterator begin() const BOOST_NOEXCEPT { return const_iterator(this, empty() ? 0 : m_first); }
|
||||
|
||||
const_iterator cbegin() const BOOST_NOEXCEPT { return begin(); }
|
||||
//! Get the const iterator pointing to the end of the <code>circular_buffer</code>.
|
||||
/*!
|
||||
\return A const random access iterator pointing to the element "one behind" the last element of the <code>
|
||||
@@ -303,6 +304,7 @@ public:
|
||||
*/
|
||||
const_iterator end() const BOOST_NOEXCEPT { return const_iterator(this, 0); }
|
||||
|
||||
const_iterator cend() const BOOST_NOEXCEPT { return end(); }
|
||||
//! Get the iterator pointing to the beginning of the "reversed" <code>circular_buffer</code>.
|
||||
/*!
|
||||
\return A reverse random access iterator pointing to the last element of the <code>circular_buffer</code>.
|
||||
@@ -666,7 +668,7 @@ public:
|
||||
break;
|
||||
}
|
||||
if (is_uninitialized(dest)) {
|
||||
cb_details::allocator_traits<Alloc>::construct(alloc(), boost::to_address(dest), boost::move_if_noexcept(*src));
|
||||
boost::allocator_construct(alloc(), boost::to_address(dest), boost::move_if_noexcept(*src));
|
||||
++constructed;
|
||||
} else {
|
||||
value_type tmp = boost::move_if_noexcept(*src);
|
||||
@@ -711,7 +713,7 @@ public:
|
||||
//! Rotate elements in the <code>circular_buffer</code>.
|
||||
/*!
|
||||
A more effective implementation of
|
||||
<code><a href="http://www.sgi.com/tech/stl/rotate.html">std::rotate</a></code>.
|
||||
<code><a href="https://www.boost.org/sgi/stl/rotate.html">std::rotate</a></code>.
|
||||
\pre <code>new_begin</code> is a valid iterator pointing to the <code>circular_buffer</code> <b>except</b> its
|
||||
end.
|
||||
\post Before calling the method suppose:<br><br>
|
||||
@@ -733,7 +735,7 @@ public:
|
||||
<code>circular_buffer</code> is full.
|
||||
\par Complexity
|
||||
Linear (in <code>(std::min)(m, n)</code>); constant if the <code>circular_buffer</code> is full.
|
||||
\sa <code><a href="http://www.sgi.com/tech/stl/rotate.html">std::rotate</a></code>
|
||||
\sa <code><a href="https://www.boost.org/sgi/stl/rotate.html">std::rotate</a></code>
|
||||
*/
|
||||
void rotate(const_iterator new_begin) {
|
||||
BOOST_CB_ASSERT(new_begin.is_valid(this)); // check for uninitialized or invalidated iterator
|
||||
@@ -787,7 +789,7 @@ public:
|
||||
\sa <code>size()</code>, <code>capacity()</code>, <code>reserve()</code>
|
||||
*/
|
||||
size_type max_size() const BOOST_NOEXCEPT {
|
||||
return (std::min<size_type>)(cb_details::allocator_traits<Alloc>::max_size(alloc()), (std::numeric_limits<difference_type>::max)());
|
||||
return (std::min<size_type>)(boost::allocator_max_size(alloc()), (std::numeric_limits<difference_type>::max)());
|
||||
}
|
||||
|
||||
//! Is the <code>circular_buffer</code> empty?
|
||||
@@ -1131,7 +1133,7 @@ public:
|
||||
/*!
|
||||
\pre Valid range <code>[first, last)</code>.<br>
|
||||
<code>first</code> and <code>last</code> have to meet the requirements of
|
||||
<a href="http://www.sgi.com/tech/stl/InputIterator.html">InputIterator</a>.
|
||||
<a href="https://www.boost.org/sgi/stl/InputIterator.html">InputIterator</a>.
|
||||
\post <code>capacity() == std::distance(first, last) \&\& full() \&\& (*this)[0]== *first \&\&
|
||||
(*this)[1] == *(first + 1) \&\& ... \&\& (*this)[std::distance(first, last) - 1] == *(last - 1)</code>
|
||||
\param first The beginning of the range to be copied.
|
||||
@@ -1153,7 +1155,7 @@ public:
|
||||
/*!
|
||||
\pre Valid range <code>[first, last)</code>.<br>
|
||||
<code>first</code> and <code>last</code> have to meet the requirements of
|
||||
<a href="http://www.sgi.com/tech/stl/InputIterator.html">InputIterator</a>.
|
||||
<a href="https://www.boost.org/sgi/stl/InputIterator.html">InputIterator</a>.
|
||||
\post <code>capacity() == buffer_capacity \&\& size() \<= std::distance(first, last) \&\&
|
||||
(*this)[0]== *(last - buffer_capacity) \&\& (*this)[1] == *(last - buffer_capacity + 1) \&\& ... \&\&
|
||||
(*this)[buffer_capacity - 1] == *(last - 1)</code><br><br>
|
||||
@@ -1170,7 +1172,7 @@ public:
|
||||
\par Complexity
|
||||
Linear (in <code>std::distance(first, last)</code>; in
|
||||
<code>min[capacity, std::distance(first, last)]</code> if the <code>InputIterator</code> is a
|
||||
<a href="http://www.sgi.com/tech/stl/RandomAccessIterator.html">RandomAccessIterator</a>).
|
||||
<a href="https://www.boost.org/sgi/stl/RandomAccessIterator.html">RandomAccessIterator</a>).
|
||||
*/
|
||||
template <class InputIterator>
|
||||
circular_buffer(capacity_type buffer_capacity, InputIterator first, InputIterator last,
|
||||
@@ -1316,7 +1318,7 @@ public:
|
||||
specified range.
|
||||
\pre Valid range <code>[first, last)</code>.<br>
|
||||
<code>first</code> and <code>last</code> have to meet the requirements of
|
||||
<a href="http://www.sgi.com/tech/stl/InputIterator.html">InputIterator</a>.
|
||||
<a href="https://www.boost.org/sgi/stl/InputIterator.html">InputIterator</a>.
|
||||
\post <code>capacity() == std::distance(first, last) \&\& size() == std::distance(first, last) \&\&
|
||||
(*this)[0]== *first \&\& (*this)[1] == *(first + 1) \&\& ... \&\& (*this)[std::distance(first, last) - 1]
|
||||
== *(last - 1)</code>
|
||||
@@ -1349,7 +1351,7 @@ public:
|
||||
<code>circular_buffer</code> will be removed and replaced with copies of elements from the specified range.
|
||||
\pre Valid range <code>[first, last)</code>.<br>
|
||||
<code>first</code> and <code>last</code> have to meet the requirements of
|
||||
<a href="http://www.sgi.com/tech/stl/InputIterator.html">InputIterator</a>.
|
||||
<a href="https://www.boost.org/sgi/stl/InputIterator.html">InputIterator</a>.
|
||||
\post <code>capacity() == buffer_capacity \&\& size() \<= std::distance(first, last) \&\&
|
||||
(*this)[0]== *(last - buffer_capacity) \&\& (*this)[1] == *(last - buffer_capacity + 1) \&\& ... \&\&
|
||||
(*this)[buffer_capacity - 1] == *(last - 1)</code><br><br>
|
||||
@@ -1370,7 +1372,7 @@ public:
|
||||
\par Complexity
|
||||
Linear (in <code>std::distance(first, last)</code>; in
|
||||
<code>min[capacity, std::distance(first, last)]</code> if the <code>InputIterator</code> is a
|
||||
<a href="http://www.sgi.com/tech/stl/RandomAccessIterator.html">RandomAccessIterator</a>).
|
||||
<a href="https://www.boost.org/sgi/stl/RandomAccessIterator.html">RandomAccessIterator</a>).
|
||||
\sa <code>\link operator=(const circular_buffer&) operator=\endlink</code>,
|
||||
<code>\link assign(size_type, param_value_type) assign(size_type, const_reference)\endlink</code>,
|
||||
<code>\link assign(capacity_type, size_type, param_value_type)
|
||||
@@ -1414,6 +1416,7 @@ public:
|
||||
|
||||
// push and pop
|
||||
private:
|
||||
/*! INTERNAL ONLY */
|
||||
template <class ValT>
|
||||
void push_back_impl(ValT item) {
|
||||
if (full()) {
|
||||
@@ -1423,12 +1426,13 @@ private:
|
||||
increment(m_last);
|
||||
m_first = m_last;
|
||||
} else {
|
||||
cb_details::allocator_traits<Alloc>::construct(alloc(), boost::to_address(m_last), static_cast<ValT>(item));
|
||||
boost::allocator_construct(alloc(), boost::to_address(m_last), static_cast<ValT>(item));
|
||||
increment(m_last);
|
||||
++m_size;
|
||||
}
|
||||
}
|
||||
|
||||
/*! INTERNAL ONLY */
|
||||
template <class ValT>
|
||||
void push_front_impl(ValT item) {
|
||||
BOOST_TRY {
|
||||
@@ -1440,7 +1444,7 @@ private:
|
||||
m_last = m_first;
|
||||
} else {
|
||||
decrement(m_first);
|
||||
cb_details::allocator_traits<Alloc>::construct(alloc(), boost::to_address(m_first), static_cast<ValT>(item));
|
||||
boost::allocator_construct(alloc(), boost::to_address(m_first), static_cast<ValT>(item));
|
||||
++m_size;
|
||||
}
|
||||
} BOOST_CATCH(...) {
|
||||
@@ -1621,6 +1625,7 @@ public:
|
||||
--m_size;
|
||||
}
|
||||
private:
|
||||
/*! INTERNAL ONLY */
|
||||
template <class ValT>
|
||||
iterator insert_impl(iterator pos, ValT item) {
|
||||
BOOST_CB_ASSERT(pos.is_valid(this)); // check for uninitialized or invalidated iterator
|
||||
@@ -1791,7 +1796,7 @@ public:
|
||||
/*!
|
||||
\pre <code>pos</code> is a valid iterator pointing to the <code>circular_buffer</code> or its end.<br>
|
||||
Valid range <code>[first, last)</code> where <code>first</code> and <code>last</code> meet the
|
||||
requirements of an <a href="http://www.sgi.com/tech/stl/InputIterator.html">InputIterator</a>.
|
||||
requirements of an <a href="https://www.boost.org/sgi/stl/InputIterator.html">InputIterator</a>.
|
||||
\post Elements from the range
|
||||
<code>[first + max[0, distance(first, last) - (pos - begin()) - reserve()], last)</code> will be
|
||||
inserted at the position <code>pos</code>.<br>The number of <code>min[pos - begin(), max[0,
|
||||
@@ -1814,7 +1819,7 @@ public:
|
||||
Linear (in <code>[std::distance(pos, end()) + std::distance(first, last)]</code>; in
|
||||
<code>min[capacity(), std::distance(pos, end()) + std::distance(first, last)]</code> if the
|
||||
<code>InputIterator</code> is a
|
||||
<a href="http://www.sgi.com/tech/stl/RandomAccessIterator.html">RandomAccessIterator</a>).
|
||||
<a href="https://www.boost.org/sgi/stl/RandomAccessIterator.html">RandomAccessIterator</a>).
|
||||
\par Example
|
||||
Consider a <code>circular_buffer</code> with the capacity of 6 and the size of 4. Its internal buffer may
|
||||
look like the one below.<br><br>
|
||||
@@ -1840,6 +1845,7 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
/*! INTERNAL ONLY */
|
||||
template <class ValT>
|
||||
iterator rinsert_impl(iterator pos, ValT item) {
|
||||
BOOST_CB_ASSERT(pos.is_valid(this)); // check for uninitialized or invalidated iterator
|
||||
@@ -2035,7 +2041,7 @@ public:
|
||||
/*!
|
||||
\pre <code>pos</code> is a valid iterator pointing to the <code>circular_buffer</code> or its end.<br>
|
||||
Valid range <code>[first, last)</code> where <code>first</code> and <code>last</code> meet the
|
||||
requirements of an <a href="http://www.sgi.com/tech/stl/InputIterator.html">InputIterator</a>.
|
||||
requirements of an <a href="https://www.boost.org/sgi/stl/InputIterator.html">InputIterator</a>.
|
||||
\post Elements from the range
|
||||
<code>[first, last - max[0, distance(first, last) - (end() - pos) - reserve()])</code> will be inserted
|
||||
before the position <code>pos</code>.<br>The number of <code>min[end() - pos, max[0,
|
||||
@@ -2057,7 +2063,7 @@ public:
|
||||
Linear (in <code>[std::distance(begin(), pos) + std::distance(first, last)]</code>; in
|
||||
<code>min[capacity(), std::distance(begin(), pos) + std::distance(first, last)]</code> if the
|
||||
<code>InputIterator</code> is a
|
||||
<a href="http://www.sgi.com/tech/stl/RandomAccessIterator.html">RandomAccessIterator</a>).
|
||||
<a href="https://www.boost.org/sgi/stl/RandomAccessIterator.html">RandomAccessIterator</a>).
|
||||
\par Example
|
||||
Consider a <code>circular_buffer</code> with the capacity of 6 and the size of 4. Its internal buffer may
|
||||
look like the one below.<br><br>
|
||||
@@ -2332,20 +2338,20 @@ public:
|
||||
private:
|
||||
// Helper methods
|
||||
|
||||
//! Check if the <code>index</code> is valid.
|
||||
/*! INTERNAL ONLY */
|
||||
void check_position(size_type index) const {
|
||||
if (index >= size())
|
||||
throw_exception(std::out_of_range("circular_buffer"));
|
||||
}
|
||||
|
||||
//! Increment the pointer.
|
||||
/*! INTERNAL ONLY */
|
||||
template <class Pointer>
|
||||
void increment(Pointer& p) const {
|
||||
if (++p == m_end)
|
||||
p = m_buff;
|
||||
}
|
||||
|
||||
//! Decrement the pointer.
|
||||
/*! INTERNAL ONLY */
|
||||
template <class Pointer>
|
||||
void decrement(Pointer& p) const {
|
||||
if (p == m_buff)
|
||||
@@ -2353,30 +2359,32 @@ private:
|
||||
--p;
|
||||
}
|
||||
|
||||
//! Add <code>n</code> to the pointer.
|
||||
/*! INTERNAL ONLY */
|
||||
template <class Pointer>
|
||||
Pointer add(Pointer p, difference_type n) const {
|
||||
return p + (n < (m_end - p) ? n : n - capacity());
|
||||
return p + (n < (m_end - p) ? n : n - (m_end - m_buff));
|
||||
}
|
||||
|
||||
//! Subtract <code>n</code> from the pointer.
|
||||
/*! INTERNAL ONLY */
|
||||
template <class Pointer>
|
||||
Pointer sub(Pointer p, difference_type n) const {
|
||||
return p - (n > (p - m_buff) ? n - capacity() : n);
|
||||
return p - (n > (p - m_buff) ? n - (m_end - m_buff) : n);
|
||||
}
|
||||
|
||||
//! Map the null pointer to virtual end of circular buffer.
|
||||
/*! INTERNAL ONLY */
|
||||
pointer map_pointer(pointer p) const { return p == 0 ? m_last : p; }
|
||||
|
||||
/*! INTERNAL ONLY */
|
||||
const Alloc& alloc() const {
|
||||
return base::get();
|
||||
}
|
||||
|
||||
/*! INTERNAL ONLY */
|
||||
Alloc& alloc() {
|
||||
return base::get();
|
||||
}
|
||||
|
||||
//! Allocate memory.
|
||||
/*! INTERNAL ONLY */
|
||||
pointer allocate(size_type n) {
|
||||
if (n > max_size())
|
||||
throw_exception(std::length_error("circular_buffer"));
|
||||
@@ -2389,18 +2397,20 @@ private:
|
||||
#endif
|
||||
}
|
||||
|
||||
//! Deallocate memory.
|
||||
/*! INTERNAL ONLY */
|
||||
void deallocate(pointer p, size_type n) {
|
||||
if (p != 0)
|
||||
alloc().deallocate(p, n);
|
||||
}
|
||||
|
||||
//! Does the pointer point to the uninitialized memory?
|
||||
/*! INTERNAL ONLY */
|
||||
bool is_uninitialized(const_pointer p) const BOOST_NOEXCEPT {
|
||||
return p >= m_last && (m_first < m_last || p < m_first);
|
||||
return (m_first < m_last)
|
||||
? (p >= m_last || p < m_first)
|
||||
: (p >= m_last && p < m_first);
|
||||
}
|
||||
|
||||
//! Replace an element.
|
||||
/*! INTERNAL ONLY */
|
||||
void replace(pointer pos, param_value_type item) {
|
||||
*pos = item;
|
||||
#if BOOST_CB_ENABLE_DEBUG
|
||||
@@ -2408,7 +2418,7 @@ private:
|
||||
#endif
|
||||
}
|
||||
|
||||
//! Replace an element.
|
||||
/*! INTERNAL ONLY */
|
||||
void replace(pointer pos, rvalue_type item) {
|
||||
*pos = boost::move(item);
|
||||
#if BOOST_CB_ENABLE_DEBUG
|
||||
@@ -2416,46 +2426,38 @@ private:
|
||||
#endif
|
||||
}
|
||||
|
||||
//! Construct or replace an element.
|
||||
/*!
|
||||
<code>construct</code> has to be set to <code>true</code> if and only if
|
||||
<code>pos</code> points to an uninitialized memory.
|
||||
*/
|
||||
/*! INTERNAL ONLY */
|
||||
void construct_or_replace(bool construct, pointer pos, param_value_type item) {
|
||||
if (construct)
|
||||
cb_details::allocator_traits<Alloc>::construct(alloc(), boost::to_address(pos), item);
|
||||
boost::allocator_construct(alloc(), boost::to_address(pos), item);
|
||||
else
|
||||
replace(pos, item);
|
||||
}
|
||||
|
||||
//! Construct or replace an element.
|
||||
/*!
|
||||
<code>construct</code> has to be set to <code>true</code> if and only if
|
||||
<code>pos</code> points to an uninitialized memory.
|
||||
*/
|
||||
/*! INTERNAL ONLY */
|
||||
void construct_or_replace(bool construct, pointer pos, rvalue_type item) {
|
||||
if (construct)
|
||||
cb_details::allocator_traits<Alloc>::construct(alloc(), boost::to_address(pos), boost::move(item));
|
||||
boost::allocator_construct(alloc(), boost::to_address(pos), boost::move(item));
|
||||
else
|
||||
replace(pos, boost::move(item));
|
||||
}
|
||||
|
||||
//! Destroy an item.
|
||||
/*! INTERNAL ONLY */
|
||||
void destroy_item(pointer p) {
|
||||
cb_details::allocator_traits<Alloc>::destroy(alloc(), boost::to_address(p));
|
||||
boost::allocator_destroy(alloc(), boost::to_address(p));
|
||||
#if BOOST_CB_ENABLE_DEBUG
|
||||
invalidate_iterators(iterator(this, p));
|
||||
cb_details::do_fill_uninitialized_memory(p, sizeof(value_type));
|
||||
#endif
|
||||
}
|
||||
|
||||
//! Destroy an item only if it has been constructed.
|
||||
/*! INTERNAL ONLY */
|
||||
void destroy_if_constructed(pointer pos) {
|
||||
if (is_uninitialized(pos))
|
||||
destroy_item(pos);
|
||||
}
|
||||
|
||||
//! Destroy the whole content of the circular buffer.
|
||||
/*! INTERNAL ONLY */
|
||||
void destroy_content() {
|
||||
#if BOOST_CB_ENABLE_DEBUG
|
||||
destroy_content(false_type());
|
||||
@@ -2464,18 +2466,18 @@ private:
|
||||
#endif
|
||||
}
|
||||
|
||||
//! Specialized destroy_content method.
|
||||
/*! INTERNAL ONLY */
|
||||
void destroy_content(const true_type&) {
|
||||
m_first = add(m_first, size());
|
||||
}
|
||||
|
||||
//! Specialized destroy_content method.
|
||||
/*! INTERNAL ONLY */
|
||||
void destroy_content(const false_type&) {
|
||||
for (size_type ii = 0; ii < size(); ++ii, increment(m_first))
|
||||
destroy_item(m_first);
|
||||
}
|
||||
|
||||
//! Destroy content and free allocated memory.
|
||||
/*! INTERNAL ONLY */
|
||||
void destroy() BOOST_NOEXCEPT {
|
||||
destroy_content();
|
||||
deallocate(m_buff, capacity());
|
||||
@@ -2487,13 +2489,13 @@ private:
|
||||
#endif
|
||||
}
|
||||
|
||||
//! Initialize the internal buffer.
|
||||
/*! INTERNAL ONLY */
|
||||
void initialize_buffer(capacity_type buffer_capacity) {
|
||||
m_buff = allocate(buffer_capacity);
|
||||
m_end = m_buff + buffer_capacity;
|
||||
}
|
||||
|
||||
//! Initialize the internal buffer.
|
||||
/*! INTERNAL ONLY */
|
||||
void initialize_buffer(capacity_type buffer_capacity, param_value_type item) {
|
||||
initialize_buffer(buffer_capacity);
|
||||
BOOST_TRY {
|
||||
@@ -2505,7 +2507,7 @@ private:
|
||||
BOOST_CATCH_END
|
||||
}
|
||||
|
||||
//! Specialized initialize method.
|
||||
/*! INTERNAL ONLY */
|
||||
template <class IntegralType>
|
||||
void initialize(IntegralType n, IntegralType item, const true_type&) {
|
||||
m_size = static_cast<size_type>(n);
|
||||
@@ -2513,18 +2515,18 @@ private:
|
||||
m_first = m_last = m_buff;
|
||||
}
|
||||
|
||||
//! Specialized initialize method.
|
||||
/*! INTERNAL ONLY */
|
||||
template <class Iterator>
|
||||
void initialize(Iterator first, Iterator last, const false_type&) {
|
||||
BOOST_CB_IS_CONVERTIBLE(Iterator, value_type); // check for invalid iterator type
|
||||
#if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x581))
|
||||
#if BOOST_WORKAROUND(BOOST_BORLANDC, BOOST_TESTED_AT(0x581))
|
||||
initialize(first, last, std::iterator_traits<Iterator>::iterator_category());
|
||||
#else
|
||||
initialize(first, last, BOOST_DEDUCED_TYPENAME std::iterator_traits<Iterator>::iterator_category());
|
||||
#endif
|
||||
}
|
||||
|
||||
//! Specialized initialize method.
|
||||
/*! INTERNAL ONLY */
|
||||
template <class InputIterator>
|
||||
void initialize(InputIterator first, InputIterator last, const std::input_iterator_tag&) {
|
||||
BOOST_CB_ASSERT_TEMPLATED_ITERATOR_CONSTRUCTORS // check if the STL provides templated iterator constructors
|
||||
@@ -2534,7 +2536,7 @@ private:
|
||||
initialize(distance, boost::make_move_iterator(tmp.begin()), boost::make_move_iterator(tmp.end()), distance);
|
||||
}
|
||||
|
||||
//! Specialized initialize method.
|
||||
/*! INTERNAL ONLY */
|
||||
template <class ForwardIterator>
|
||||
void initialize(ForwardIterator first, ForwardIterator last, const std::forward_iterator_tag&) {
|
||||
BOOST_CB_ASSERT(std::distance(first, last) >= 0); // check for wrong range
|
||||
@@ -2542,7 +2544,7 @@ private:
|
||||
initialize(distance, first, last, distance);
|
||||
}
|
||||
|
||||
//! Specialized initialize method.
|
||||
/*! INTERNAL ONLY */
|
||||
template <class IntegralType>
|
||||
void initialize(capacity_type buffer_capacity, IntegralType n, IntegralType item, const true_type&) {
|
||||
BOOST_CB_ASSERT(buffer_capacity >= static_cast<size_type>(n)); // check for capacity lower than n
|
||||
@@ -2552,18 +2554,18 @@ private:
|
||||
m_last = buffer_capacity == size() ? m_buff : m_buff + size();
|
||||
}
|
||||
|
||||
//! Specialized initialize method.
|
||||
/*! INTERNAL ONLY */
|
||||
template <class Iterator>
|
||||
void initialize(capacity_type buffer_capacity, Iterator first, Iterator last, const false_type&) {
|
||||
BOOST_CB_IS_CONVERTIBLE(Iterator, value_type); // check for invalid iterator type
|
||||
#if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x581))
|
||||
#if BOOST_WORKAROUND(BOOST_BORLANDC, BOOST_TESTED_AT(0x581))
|
||||
initialize(buffer_capacity, first, last, std::iterator_traits<Iterator>::iterator_category());
|
||||
#else
|
||||
initialize(buffer_capacity, first, last, BOOST_DEDUCED_TYPENAME std::iterator_traits<Iterator>::iterator_category());
|
||||
#endif
|
||||
}
|
||||
|
||||
//! Specialized initialize method.
|
||||
/*! INTERNAL ONLY */
|
||||
template <class InputIterator>
|
||||
void initialize(capacity_type buffer_capacity,
|
||||
InputIterator first,
|
||||
@@ -2575,7 +2577,7 @@ private:
|
||||
if (buffer_capacity == 0)
|
||||
return;
|
||||
while (first != last && !full()) {
|
||||
cb_details::allocator_traits<Alloc>::construct(alloc(), boost::to_address(m_last), *first++);
|
||||
boost::allocator_construct(alloc(), boost::to_address(m_last), *first++);
|
||||
increment(m_last);
|
||||
++m_size;
|
||||
}
|
||||
@@ -2586,7 +2588,7 @@ private:
|
||||
}
|
||||
}
|
||||
|
||||
//! Specialized initialize method.
|
||||
/*! INTERNAL ONLY */
|
||||
template <class ForwardIterator>
|
||||
void initialize(capacity_type buffer_capacity,
|
||||
ForwardIterator first,
|
||||
@@ -2596,7 +2598,7 @@ private:
|
||||
initialize(buffer_capacity, first, last, std::distance(first, last));
|
||||
}
|
||||
|
||||
//! Initialize the circular buffer.
|
||||
/*! INTERNAL ONLY */
|
||||
template <class ForwardIterator>
|
||||
void initialize(capacity_type buffer_capacity,
|
||||
ForwardIterator first,
|
||||
@@ -2621,7 +2623,7 @@ private:
|
||||
m_last = m_buff;
|
||||
}
|
||||
|
||||
//! Reset the circular buffer.
|
||||
/*! INTERNAL ONLY */
|
||||
void reset(pointer buff, pointer last, capacity_type new_capacity) {
|
||||
destroy();
|
||||
m_size = last - buff;
|
||||
@@ -2630,34 +2632,34 @@ private:
|
||||
m_last = last == m_end ? m_buff : last;
|
||||
}
|
||||
|
||||
//! Specialized method for swapping the allocator.
|
||||
/*! INTERNAL ONLY */
|
||||
void swap_allocator(circular_buffer<T, Alloc>&, const true_type&) {
|
||||
// Swap is not needed because allocators have no state.
|
||||
}
|
||||
|
||||
//! Specialized method for swapping the allocator.
|
||||
/*! INTERNAL ONLY */
|
||||
void swap_allocator(circular_buffer<T, Alloc>& cb, const false_type&) {
|
||||
adl_move_swap(alloc(), cb.alloc());
|
||||
}
|
||||
|
||||
//! Specialized assign method.
|
||||
/*! INTERNAL ONLY */
|
||||
template <class IntegralType>
|
||||
void assign(IntegralType n, IntegralType item, const true_type&) {
|
||||
assign(static_cast<size_type>(n), static_cast<value_type>(item));
|
||||
}
|
||||
|
||||
//! Specialized assign method.
|
||||
/*! INTERNAL ONLY */
|
||||
template <class Iterator>
|
||||
void assign(Iterator first, Iterator last, const false_type&) {
|
||||
BOOST_CB_IS_CONVERTIBLE(Iterator, value_type); // check for invalid iterator type
|
||||
#if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x581))
|
||||
#if BOOST_WORKAROUND(BOOST_BORLANDC, BOOST_TESTED_AT(0x581))
|
||||
assign(first, last, std::iterator_traits<Iterator>::iterator_category());
|
||||
#else
|
||||
assign(first, last, BOOST_DEDUCED_TYPENAME std::iterator_traits<Iterator>::iterator_category());
|
||||
#endif
|
||||
}
|
||||
|
||||
//! Specialized assign method.
|
||||
/*! INTERNAL ONLY */
|
||||
template <class InputIterator>
|
||||
void assign(InputIterator first, InputIterator last, const std::input_iterator_tag&) {
|
||||
BOOST_CB_ASSERT_TEMPLATED_ITERATOR_CONSTRUCTORS // check if the STL provides templated iterator constructors
|
||||
@@ -2669,7 +2671,7 @@ private:
|
||||
(boost::make_move_iterator(tmp.begin()), boost::make_move_iterator(tmp.end()), alloc()));
|
||||
}
|
||||
|
||||
//! Specialized assign method.
|
||||
/*! INTERNAL ONLY */
|
||||
template <class ForwardIterator>
|
||||
void assign(ForwardIterator first, ForwardIterator last, const std::forward_iterator_tag&) {
|
||||
BOOST_CB_ASSERT(std::distance(first, last) >= 0); // check for wrong range
|
||||
@@ -2677,24 +2679,24 @@ private:
|
||||
assign_n(distance, distance, cb_details::make_assign_range(first, last, alloc()));
|
||||
}
|
||||
|
||||
//! Specialized assign method.
|
||||
/*! INTERNAL ONLY */
|
||||
template <class IntegralType>
|
||||
void assign(capacity_type new_capacity, IntegralType n, IntegralType item, const true_type&) {
|
||||
assign(new_capacity, static_cast<size_type>(n), static_cast<value_type>(item));
|
||||
}
|
||||
|
||||
//! Specialized assign method.
|
||||
/*! INTERNAL ONLY */
|
||||
template <class Iterator>
|
||||
void assign(capacity_type new_capacity, Iterator first, Iterator last, const false_type&) {
|
||||
BOOST_CB_IS_CONVERTIBLE(Iterator, value_type); // check for invalid iterator type
|
||||
#if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x581))
|
||||
#if BOOST_WORKAROUND(BOOST_BORLANDC, BOOST_TESTED_AT(0x581))
|
||||
assign(new_capacity, first, last, std::iterator_traits<Iterator>::iterator_category());
|
||||
#else
|
||||
assign(new_capacity, first, last, BOOST_DEDUCED_TYPENAME std::iterator_traits<Iterator>::iterator_category());
|
||||
#endif
|
||||
}
|
||||
|
||||
//! Specialized assign method.
|
||||
/*! INTERNAL ONLY */
|
||||
template <class InputIterator>
|
||||
void assign(capacity_type new_capacity, InputIterator first, InputIterator last, const std::input_iterator_tag&) {
|
||||
if (new_capacity == capacity()) {
|
||||
@@ -2706,7 +2708,7 @@ private:
|
||||
}
|
||||
}
|
||||
|
||||
//! Specialized assign method.
|
||||
/*! INTERNAL ONLY */
|
||||
template <class ForwardIterator>
|
||||
void assign(capacity_type new_capacity, ForwardIterator first, ForwardIterator last,
|
||||
const std::forward_iterator_tag&) {
|
||||
@@ -2720,7 +2722,7 @@ private:
|
||||
cb_details::make_assign_range(first, last, alloc()));
|
||||
}
|
||||
|
||||
//! Helper assign method.
|
||||
/*! INTERNAL ONLY */
|
||||
template <class Functor>
|
||||
void assign_n(capacity_type new_capacity, size_type n, const Functor& fnc) {
|
||||
if (new_capacity == capacity()) {
|
||||
@@ -2750,7 +2752,7 @@ private:
|
||||
m_last = add(m_buff, size());
|
||||
}
|
||||
|
||||
//! Helper insert method.
|
||||
/*! INTERNAL ONLY */
|
||||
template <class ValT>
|
||||
iterator insert_item(const iterator& pos, ValT item) {
|
||||
pointer p = pos.m_it;
|
||||
@@ -2786,24 +2788,24 @@ private:
|
||||
return iterator(this, p);
|
||||
}
|
||||
|
||||
//! Specialized insert method.
|
||||
/*! INTERNAL ONLY */
|
||||
template <class IntegralType>
|
||||
void insert(const iterator& pos, IntegralType n, IntegralType item, const true_type&) {
|
||||
insert(pos, static_cast<size_type>(n), static_cast<value_type>(item));
|
||||
}
|
||||
|
||||
//! Specialized insert method.
|
||||
/*! INTERNAL ONLY */
|
||||
template <class Iterator>
|
||||
void insert(const iterator& pos, Iterator first, Iterator last, const false_type&) {
|
||||
BOOST_CB_IS_CONVERTIBLE(Iterator, value_type); // check for invalid iterator type
|
||||
#if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x581))
|
||||
#if BOOST_WORKAROUND(BOOST_BORLANDC, BOOST_TESTED_AT(0x581))
|
||||
insert(pos, first, last, std::iterator_traits<Iterator>::iterator_category());
|
||||
#else
|
||||
insert(pos, first, last, BOOST_DEDUCED_TYPENAME std::iterator_traits<Iterator>::iterator_category());
|
||||
#endif
|
||||
}
|
||||
|
||||
//! Specialized insert method.
|
||||
/*! INTERNAL ONLY */
|
||||
template <class InputIterator>
|
||||
void insert(iterator pos, InputIterator first, InputIterator last, const std::input_iterator_tag&) {
|
||||
if (!full() || pos != begin()) {
|
||||
@@ -2812,7 +2814,7 @@ private:
|
||||
}
|
||||
}
|
||||
|
||||
//! Specialized insert method.
|
||||
/*! INTERNAL ONLY */
|
||||
template <class ForwardIterator>
|
||||
void insert(const iterator& pos, ForwardIterator first, ForwardIterator last, const std::forward_iterator_tag&) {
|
||||
BOOST_CB_ASSERT(std::distance(first, last) >= 0); // check for wrong range
|
||||
@@ -2829,7 +2831,7 @@ private:
|
||||
insert_n(pos, n, cb_details::iterator_wrapper<ForwardIterator>(first));
|
||||
}
|
||||
|
||||
//! Helper insert method.
|
||||
/*! INTERNAL ONLY */
|
||||
template <class Wrapper>
|
||||
void insert_n(const iterator& pos, size_type n, const Wrapper& wrapper) {
|
||||
size_type construct = reserve();
|
||||
@@ -2840,7 +2842,7 @@ private:
|
||||
pointer p = m_last;
|
||||
BOOST_TRY {
|
||||
for (; ii < construct; ++ii, increment(p))
|
||||
cb_details::allocator_traits<Alloc>::construct(alloc(), boost::to_address(p), *wrapper());
|
||||
boost::allocator_construct(alloc(), boost::to_address(p), *wrapper());
|
||||
for (;ii < n; ++ii, increment(p))
|
||||
replace(p, *wrapper());
|
||||
} BOOST_CATCH(...) {
|
||||
@@ -2877,24 +2879,24 @@ private:
|
||||
m_size += construct;
|
||||
}
|
||||
|
||||
//! Specialized rinsert method.
|
||||
/*! INTERNAL ONLY */
|
||||
template <class IntegralType>
|
||||
void rinsert(const iterator& pos, IntegralType n, IntegralType item, const true_type&) {
|
||||
rinsert(pos, static_cast<size_type>(n), static_cast<value_type>(item));
|
||||
}
|
||||
|
||||
//! Specialized rinsert method.
|
||||
/*! INTERNAL ONLY */
|
||||
template <class Iterator>
|
||||
void rinsert(const iterator& pos, Iterator first, Iterator last, const false_type&) {
|
||||
BOOST_CB_IS_CONVERTIBLE(Iterator, value_type); // check for invalid iterator type
|
||||
#if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x581))
|
||||
#if BOOST_WORKAROUND(BOOST_BORLANDC, BOOST_TESTED_AT(0x581))
|
||||
rinsert(pos, first, last, std::iterator_traits<Iterator>::iterator_category());
|
||||
#else
|
||||
rinsert(pos, first, last, BOOST_DEDUCED_TYPENAME std::iterator_traits<Iterator>::iterator_category());
|
||||
#endif
|
||||
}
|
||||
|
||||
//! Specialized insert method.
|
||||
/*! INTERNAL ONLY */
|
||||
template <class InputIterator>
|
||||
void rinsert(iterator pos, InputIterator first, InputIterator last, const std::input_iterator_tag&) {
|
||||
if (!full() || pos.m_it != 0) {
|
||||
@@ -2906,14 +2908,14 @@ private:
|
||||
}
|
||||
}
|
||||
|
||||
//! Specialized rinsert method.
|
||||
/*! INTERNAL ONLY */
|
||||
template <class ForwardIterator>
|
||||
void rinsert(const iterator& pos, ForwardIterator first, ForwardIterator last, const std::forward_iterator_tag&) {
|
||||
BOOST_CB_ASSERT(std::distance(first, last) >= 0); // check for wrong range
|
||||
rinsert_n(pos, std::distance(first, last), cb_details::iterator_wrapper<ForwardIterator>(first));
|
||||
}
|
||||
|
||||
//! Helper rinsert method.
|
||||
/*! INTERNAL ONLY */
|
||||
template <class Wrapper>
|
||||
void rinsert_n(const iterator& pos, size_type n, const Wrapper& wrapper) {
|
||||
if (n == 0)
|
||||
@@ -2934,7 +2936,7 @@ private:
|
||||
for (;ii > construct; --ii, increment(p))
|
||||
replace(p, *wrapper());
|
||||
for (; ii > 0; --ii, increment(p))
|
||||
cb_details::allocator_traits<Alloc>::construct(alloc(), boost::to_address(p), *wrapper());
|
||||
boost::allocator_construct(alloc(), boost::to_address(p), *wrapper());
|
||||
} BOOST_CATCH(...) {
|
||||
size_type constructed = ii < construct ? construct - ii : 0;
|
||||
m_last = add(m_last, constructed);
|
||||
@@ -2966,25 +2968,25 @@ private:
|
||||
m_size += construct;
|
||||
}
|
||||
|
||||
//! Specialized erase_begin method.
|
||||
/*! INTERNAL ONLY */
|
||||
void erase_begin(size_type n, const true_type&) {
|
||||
m_first = add(m_first, n);
|
||||
m_size -= n;
|
||||
}
|
||||
|
||||
//! Specialized erase_begin method.
|
||||
/*! INTERNAL ONLY */
|
||||
void erase_begin(size_type n, const false_type&) {
|
||||
iterator b = begin();
|
||||
rerase(b, b + n);
|
||||
}
|
||||
|
||||
//! Specialized erase_end method.
|
||||
/*! INTERNAL ONLY */
|
||||
void erase_end(size_type n, const true_type&) {
|
||||
m_last = sub(m_last, n);
|
||||
m_size -= n;
|
||||
}
|
||||
|
||||
//! Specialized erase_end method.
|
||||
/*! INTERNAL ONLY */
|
||||
void erase_end(size_type n, const false_type&) {
|
||||
iterator e = end();
|
||||
erase(e - n, e);
|
||||
@@ -2998,7 +3000,7 @@ private:
|
||||
\param lhs The <code>circular_buffer</code> to compare.
|
||||
\param rhs The <code>circular_buffer</code> to compare.
|
||||
\return <code>lhs.\link circular_buffer::size() size()\endlink == rhs.\link circular_buffer::size() size()\endlink
|
||||
&& <a href="http://www.sgi.com/tech/stl/equal.html">std::equal</a>(lhs.\link circular_buffer::begin()
|
||||
&& <a href="https://www.boost.org/sgi/stl/equal.html">std::equal</a>(lhs.\link circular_buffer::begin()
|
||||
begin()\endlink, lhs.\link circular_buffer::end() end()\endlink,
|
||||
rhs.\link circular_buffer::begin() begin()\endlink)</code>
|
||||
\throws Nothing.
|
||||
@@ -3017,7 +3019,7 @@ inline bool operator == (const circular_buffer<T, Alloc>& lhs, const circular_bu
|
||||
right one.
|
||||
\param lhs The <code>circular_buffer</code> to compare.
|
||||
\param rhs The <code>circular_buffer</code> to compare.
|
||||
\return <code><a href="http://www.sgi.com/tech/stl/lexicographical_compare.html">
|
||||
\return <code><a href="https://www.boost.org/sgi/stl/lexicographical_compare.html">
|
||||
std::lexicographical_compare</a>(lhs.\link circular_buffer::begin() begin()\endlink,
|
||||
lhs.\link circular_buffer::end() end()\endlink, rhs.\link circular_buffer::begin() begin()\endlink,
|
||||
rhs.\link circular_buffer::end() end()\endlink)</code>
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
#endif
|
||||
|
||||
#include <boost/throw_exception.hpp>
|
||||
#include <boost/circular_buffer/allocators.hpp>
|
||||
#include <boost/core/allocator_access.hpp>
|
||||
#include <boost/core/pointer_traits.hpp>
|
||||
#include <boost/move/move.hpp>
|
||||
#include <boost/type_traits/is_nothrow_move_constructible.hpp>
|
||||
@@ -36,7 +36,7 @@ namespace boost {
|
||||
|
||||
namespace cb_details {
|
||||
|
||||
template <class Traits> struct nonconst_traits;
|
||||
template <class Alloc> struct nonconst_traits;
|
||||
|
||||
template<class ForwardIterator, class Diff, class T, class Alloc>
|
||||
void uninitialized_fill_n_with_alloc(
|
||||
@@ -52,34 +52,34 @@ ForwardIterator uninitialized_move_if_noexcept(InputIterator first, InputIterato
|
||||
\struct const_traits
|
||||
\brief Defines the data types for a const iterator.
|
||||
*/
|
||||
template <class Traits>
|
||||
template <class Alloc>
|
||||
struct const_traits {
|
||||
// Basic types
|
||||
typedef typename Traits::value_type value_type;
|
||||
typedef typename Traits::const_pointer pointer;
|
||||
typedef typename Alloc::value_type value_type;
|
||||
typedef typename boost::allocator_const_pointer<Alloc>::type pointer;
|
||||
typedef const value_type& reference;
|
||||
typedef typename Traits::size_type size_type;
|
||||
typedef typename Traits::difference_type difference_type;
|
||||
typedef typename boost::allocator_size_type<Alloc>::type size_type;
|
||||
typedef typename boost::allocator_difference_type<Alloc>::type difference_type;
|
||||
|
||||
// Non-const traits
|
||||
typedef nonconst_traits<Traits> nonconst_self;
|
||||
typedef nonconst_traits<Alloc> nonconst_self;
|
||||
};
|
||||
|
||||
/*!
|
||||
\struct nonconst_traits
|
||||
\brief Defines the data types for a non-const iterator.
|
||||
*/
|
||||
template <class Traits>
|
||||
template <class Alloc>
|
||||
struct nonconst_traits {
|
||||
// Basic types
|
||||
typedef typename Traits::value_type value_type;
|
||||
typedef typename Traits::pointer pointer;
|
||||
typedef typename Alloc::value_type value_type;
|
||||
typedef typename boost::allocator_pointer<Alloc>::type pointer;
|
||||
typedef value_type& reference;
|
||||
typedef typename Traits::size_type size_type;
|
||||
typedef typename Traits::difference_type difference_type;
|
||||
typedef typename boost::allocator_size_type<Alloc>::type size_type;
|
||||
typedef typename boost::allocator_difference_type<Alloc>::type difference_type;
|
||||
|
||||
// Non-const traits
|
||||
typedef nonconst_traits<Traits> nonconst_self;
|
||||
typedef nonconst_traits<Alloc> nonconst_self;
|
||||
};
|
||||
|
||||
/*!
|
||||
@@ -114,7 +114,7 @@ private:
|
||||
*/
|
||||
template <class Value, class Alloc>
|
||||
struct assign_n {
|
||||
typedef typename allocator_traits<Alloc>::size_type size_type;
|
||||
typedef typename boost::allocator_size_type<Alloc>::type size_type;
|
||||
size_type m_n;
|
||||
Value m_item;
|
||||
Alloc& m_alloc;
|
||||
@@ -259,7 +259,10 @@ struct iterator
|
||||
#endif // #if BOOST_CB_ENABLE_DEBUG
|
||||
|
||||
//! Assign operator.
|
||||
iterator& operator = (const iterator& it) {
|
||||
#if !defined(BOOST_NO_CXX11_DEFAULTED_FUNCTIONS)
|
||||
iterator& operator=(const iterator&) = default;
|
||||
#else
|
||||
iterator& operator=(const iterator& it) {
|
||||
if (this == &it)
|
||||
return *this;
|
||||
#if BOOST_CB_ENABLE_DEBUG
|
||||
@@ -269,6 +272,7 @@ struct iterator
|
||||
m_it = it.m_it;
|
||||
return *this;
|
||||
}
|
||||
#endif
|
||||
|
||||
// Random access iterator methods
|
||||
|
||||
@@ -424,10 +428,10 @@ inline ForwardIterator uninitialized_copy(InputIterator first, InputIterator las
|
||||
ForwardIterator next = dest;
|
||||
BOOST_TRY {
|
||||
for (; first != last; ++first, ++dest)
|
||||
allocator_traits<Alloc>::construct(a, boost::to_address(dest), *first);
|
||||
boost::allocator_construct(a, boost::to_address(dest), *first);
|
||||
} BOOST_CATCH(...) {
|
||||
for (; next != dest; ++next)
|
||||
allocator_traits<Alloc>::destroy(a, boost::to_address(next));
|
||||
boost::allocator_destroy(a, boost::to_address(next));
|
||||
BOOST_RETHROW
|
||||
}
|
||||
BOOST_CATCH_END
|
||||
@@ -438,7 +442,7 @@ template<class InputIterator, class ForwardIterator, class Alloc>
|
||||
ForwardIterator uninitialized_move_if_noexcept_impl(InputIterator first, InputIterator last, ForwardIterator dest, Alloc& a,
|
||||
true_type) {
|
||||
for (; first != last; ++first, ++dest)
|
||||
allocator_traits<Alloc>::construct(a, boost::to_address(dest), boost::move(*first));
|
||||
boost::allocator_construct(a, boost::to_address(dest), boost::move(*first));
|
||||
return dest;
|
||||
}
|
||||
|
||||
@@ -454,7 +458,7 @@ ForwardIterator uninitialized_move_if_noexcept_impl(InputIterator first, InputIt
|
||||
*/
|
||||
template<class InputIterator, class ForwardIterator, class Alloc>
|
||||
ForwardIterator uninitialized_move_if_noexcept(InputIterator first, InputIterator last, ForwardIterator dest, Alloc& a) {
|
||||
typedef typename boost::is_nothrow_move_constructible<typename allocator_traits<Alloc>::value_type>::type tag_t;
|
||||
typedef typename boost::is_nothrow_move_constructible<typename Alloc::value_type>::type tag_t;
|
||||
return uninitialized_move_if_noexcept_impl(first, last, dest, a, tag_t());
|
||||
}
|
||||
|
||||
@@ -467,10 +471,10 @@ inline void uninitialized_fill_n_with_alloc(ForwardIterator first, Diff n, const
|
||||
ForwardIterator next = first;
|
||||
BOOST_TRY {
|
||||
for (; n > 0; ++first, --n)
|
||||
allocator_traits<Alloc>::construct(alloc, boost::to_address(first), item);
|
||||
boost::allocator_construct(alloc, boost::to_address(first), item);
|
||||
} BOOST_CATCH(...) {
|
||||
for (; next != first; ++next)
|
||||
allocator_traits<Alloc>::destroy(alloc, boost::to_address(next));
|
||||
boost::allocator_destroy(alloc, boost::to_address(next));
|
||||
BOOST_RETHROW
|
||||
}
|
||||
BOOST_CATCH_END
|
||||
|
||||
@@ -121,7 +121,7 @@ public:<br>
|
||||
using circular_buffer<T, Alloc>::max_size;
|
||||
using circular_buffer<T, Alloc>::empty;
|
||||
|
||||
#if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
|
||||
#if BOOST_WORKAROUND(BOOST_BORLANDC, BOOST_TESTED_AT(0x564))
|
||||
reference operator [] (size_type n) { return circular_buffer<T, Alloc>::operator[](n); }
|
||||
const_reference operator [] (size_type n) const { return circular_buffer<T, Alloc>::operator[](n); }
|
||||
#else
|
||||
@@ -453,7 +453,7 @@ public:
|
||||
/*!
|
||||
\pre Valid range <code>[first, last)</code>.<br>
|
||||
<code>first</code> and <code>last</code> have to meet the requirements of
|
||||
<a href="http://www.sgi.com/tech/stl/InputIterator.html">InputIterator</a>.
|
||||
<a href="https://www.boost.org/sgi/stl/InputIterator.html">InputIterator</a>.
|
||||
\post <code>capacity().%capacity() == std::distance(first, last) \&\& capacity().min_capacity() == 0 \&\&
|
||||
full() \&\& (*this)[0]== *first \&\& (*this)[1] == *(first + 1) \&\& ... \&\&
|
||||
(*this)[std::distance(first, last) - 1] == *(last - 1)</code><br><br>
|
||||
@@ -478,7 +478,7 @@ public:
|
||||
of allocated memory) filled with a copy of the range.
|
||||
\pre Valid range <code>[first, last)</code>.<br>
|
||||
<code>first</code> and <code>last</code> have to meet the requirements of
|
||||
<a href="http://www.sgi.com/tech/stl/InputIterator.html">InputIterator</a>.
|
||||
<a href="https://www.boost.org/sgi/stl/InputIterator.html">InputIterator</a>.
|
||||
\post <code>capacity() == capacity_ctrl \&\& size() \<= std::distance(first, last) \&\& (*this)[0]==
|
||||
*(last - capacity_ctrl.%capacity()) \&\& (*this)[1] == *(last - capacity_ctrl.%capacity() + 1) \&\& ...
|
||||
\&\& (*this)[capacity_ctrl.%capacity() - 1] == *(last - 1)</code><br><br>
|
||||
@@ -499,7 +499,7 @@ public:
|
||||
\par Complexity
|
||||
Linear (in <code>std::distance(first, last)</code>; in
|
||||
<code>min[capacity_ctrl.%capacity(), std::distance(first, last)]</code> if the <code>InputIterator</code>
|
||||
is a <a href="http://www.sgi.com/tech/stl/RandomAccessIterator.html">RandomAccessIterator</a>).
|
||||
is a <a href="https://www.boost.org/sgi/stl/RandomAccessIterator.html">RandomAccessIterator</a>).
|
||||
*/
|
||||
template <class InputIterator>
|
||||
circular_buffer_space_optimized(capacity_type capacity_ctrl, InputIterator first, InputIterator last,
|
||||
@@ -655,7 +655,7 @@ public:
|
||||
elements from the specified range.
|
||||
\pre Valid range <code>[first, last)</code>.<br>
|
||||
<code>first</code> and <code>last</code> have to meet the requirements of
|
||||
<a href="http://www.sgi.com/tech/stl/InputIterator.html">InputIterator</a>.
|
||||
<a href="https://www.boost.org/sgi/stl/InputIterator.html">InputIterator</a>.
|
||||
\post <code>capacity().%capacity() == std::distance(first, last) \&\& capacity().min_capacity() == 0 \&\&
|
||||
size() == std::distance(first, last) \&\& (*this)[0]== *first \&\& (*this)[1] == *(first + 1) \&\& ...
|
||||
\&\& (*this)[std::distance(first, last) - 1] == *(last - 1)</code><br><br>
|
||||
@@ -692,7 +692,7 @@ public:
|
||||
elements from the specified range.
|
||||
\pre Valid range <code>[first, last)</code>.<br>
|
||||
<code>first</code> and <code>last</code> have to meet the requirements of
|
||||
<a href="http://www.sgi.com/tech/stl/InputIterator.html">InputIterator</a>.
|
||||
<a href="https://www.boost.org/sgi/stl/InputIterator.html">InputIterator</a>.
|
||||
\post <code>capacity() == capacity_ctrl \&\& size() \<= std::distance(first, last) \&\&
|
||||
(*this)[0]== *(last - capacity) \&\& (*this)[1] == *(last - capacity + 1) \&\& ... \&\&
|
||||
(*this)[capacity - 1] == *(last - 1)</code><br><br>
|
||||
@@ -715,7 +715,7 @@ public:
|
||||
\par Complexity
|
||||
Linear (in <code>std::distance(first, last)</code>; in
|
||||
<code>min[capacity_ctrl.%capacity(), std::distance(first, last)]</code> if the <code>InputIterator</code>
|
||||
is a <a href="http://www.sgi.com/tech/stl/RandomAccessIterator.html">RandomAccessIterator</a>).
|
||||
is a <a href="https://www.boost.org/sgi/stl/RandomAccessIterator.html">RandomAccessIterator</a>).
|
||||
\sa <code>\link operator=(const circular_buffer_space_optimized&) operator=\endlink</code>,
|
||||
<code>\link assign(size_type, param_value_type) assign(size_type, const_reference)\endlink</code>,
|
||||
<code>\link assign(capacity_type, size_type, param_value_type)
|
||||
@@ -1114,7 +1114,7 @@ public:
|
||||
/*!
|
||||
\pre <code>pos</code> is a valid iterator pointing to the <code>circular_buffer_space_optimized</code> or its
|
||||
end.<br>Valid range <code>[first, last)</code> where <code>first</code> and <code>last</code> meet the
|
||||
requirements of an <a href="http://www.sgi.com/tech/stl/InputIterator.html">InputIterator</a>.
|
||||
requirements of an <a href="https://www.boost.org/sgi/stl/InputIterator.html">InputIterator</a>.
|
||||
\post Elements from the range
|
||||
<code>[first + max[0, distance(first, last) - (pos - begin()) - reserve()], last)</code> will be
|
||||
inserted at the position <code>pos</code>.<br>The number of <code>min[pos - begin(), max[0,
|
||||
@@ -1136,7 +1136,7 @@ public:
|
||||
Linear (in <code>[size() + std::distance(first, last)]</code>; in
|
||||
<code>min[capacity().%capacity(), size() + std::distance(first, last)]</code> if the
|
||||
<code>InputIterator</code> is a
|
||||
<a href="http://www.sgi.com/tech/stl/RandomAccessIterator.html">RandomAccessIterator</a>).
|
||||
<a href="https://www.boost.org/sgi/stl/RandomAccessIterator.html">RandomAccessIterator</a>).
|
||||
\par Example
|
||||
Consider a <code>circular_buffer_space_optimized</code> with the capacity of 6 and the size of 4. Its
|
||||
internal buffer may look like the one below.<br><br>
|
||||
@@ -1326,7 +1326,7 @@ public:
|
||||
\pre <code>pos</code> is a valid iterator pointing to the <code>circular_buffer_space_optimized</code> or its
|
||||
end.<br>
|
||||
Valid range <code>[first, last)</code> where <code>first</code> and <code>last</code> meet the
|
||||
requirements of an <a href="http://www.sgi.com/tech/stl/InputIterator.html">InputIterator</a>.
|
||||
requirements of an <a href="https://www.boost.org/sgi/stl/InputIterator.html">InputIterator</a>.
|
||||
\post Elements from the range
|
||||
<code>[first, last - max[0, distance(first, last) - (end() - pos) - reserve()])</code> will be inserted
|
||||
before the position <code>pos</code>.<br>The number of <code>min[end() - pos, max[0,
|
||||
@@ -1349,7 +1349,7 @@ public:
|
||||
Linear (in <code>[size() + std::distance(first, last)]</code>; in
|
||||
<code>min[capacity().%capacity(), size() + std::distance(first, last)]</code> if the
|
||||
<code>InputIterator</code> is a
|
||||
<a href="http://www.sgi.com/tech/stl/RandomAccessIterator.html">RandomAccessIterator</a>).
|
||||
<a href="https://www.boost.org/sgi/stl/RandomAccessIterator.html">RandomAccessIterator</a>).
|
||||
\par Example
|
||||
Consider a <code>circular_buffer_space_optimized</code> with the capacity of 6 and the size of 4. Its
|
||||
internal buffer may look like the one below.<br><br>
|
||||
@@ -1522,7 +1522,7 @@ public:
|
||||
private:
|
||||
// Helper methods
|
||||
|
||||
//! Adjust the amount of allocated memory.
|
||||
/*! INTERNAL ONLY */
|
||||
void adjust_min_capacity() {
|
||||
if (m_capacity_ctrl.min_capacity() > circular_buffer<T, Alloc>::capacity())
|
||||
circular_buffer<T, Alloc>::set_capacity(m_capacity_ctrl.min_capacity());
|
||||
@@ -1530,7 +1530,7 @@ private:
|
||||
check_high_capacity();
|
||||
}
|
||||
|
||||
//! Ensure the reserve for possible growth up.
|
||||
/*! INTERNAL ONLY */
|
||||
size_type ensure_reserve(size_type new_capacity, size_type buffer_size) const {
|
||||
if (buffer_size + new_capacity / 5 >= new_capacity)
|
||||
new_capacity *= 2; // ensure at least 20% reserve
|
||||
@@ -1539,10 +1539,7 @@ private:
|
||||
return new_capacity;
|
||||
}
|
||||
|
||||
//! Check for low capacity.
|
||||
/*
|
||||
\post If the capacity is low it will be increased.
|
||||
*/
|
||||
/*! INTERNAL ONLY */
|
||||
void check_low_capacity(size_type n = 1) {
|
||||
size_type new_size = size() + n;
|
||||
size_type new_capacity = circular_buffer<T, Alloc>::capacity();
|
||||
@@ -1558,10 +1555,7 @@ private:
|
||||
#endif
|
||||
}
|
||||
|
||||
//! Check for high capacity.
|
||||
/*
|
||||
\post If the capacity is high it will be decreased.
|
||||
*/
|
||||
/*! INTERNAL ONLY */
|
||||
void check_high_capacity() {
|
||||
size_type new_capacity = circular_buffer<T, Alloc>::capacity();
|
||||
while (new_capacity / 3 >= size()) { // (new_capacity / 3) -> avoid oscillations
|
||||
@@ -1578,33 +1572,33 @@ private:
|
||||
#endif
|
||||
}
|
||||
|
||||
//! Specialized method for reducing the capacity.
|
||||
/*! INTERNAL ONLY */
|
||||
void reduce_capacity(const true_type&) {
|
||||
circular_buffer<T, Alloc>::set_capacity((std::max)(m_capacity_ctrl.min_capacity(), size()));
|
||||
}
|
||||
|
||||
//! Specialized method for reducing the capacity.
|
||||
/*! INTERNAL ONLY */
|
||||
void reduce_capacity(const false_type&) {}
|
||||
|
||||
//! Determine the initial capacity.
|
||||
/*! INTERNAL ONLY */
|
||||
static size_type init_capacity(const capacity_type& capacity_ctrl, size_type n) {
|
||||
BOOST_CB_ASSERT(capacity_ctrl.capacity() >= n); // check for capacity lower than n
|
||||
return (std::max)(capacity_ctrl.min_capacity(), n);
|
||||
}
|
||||
|
||||
//! Specialized method for determining the initial capacity.
|
||||
/*! INTERNAL ONLY */
|
||||
template <class IntegralType>
|
||||
static size_type init_capacity(const capacity_type& capacity_ctrl, IntegralType n, IntegralType,
|
||||
const true_type&) {
|
||||
return init_capacity(capacity_ctrl, static_cast<size_type>(n));
|
||||
}
|
||||
|
||||
//! Specialized method for determining the initial capacity.
|
||||
/*! INTERNAL ONLY */
|
||||
template <class Iterator>
|
||||
static size_type init_capacity(const capacity_type& capacity_ctrl, Iterator first, Iterator last,
|
||||
const false_type&) {
|
||||
BOOST_CB_IS_CONVERTIBLE(Iterator, value_type); // check for invalid iterator type
|
||||
#if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x581))
|
||||
#if BOOST_WORKAROUND(BOOST_BORLANDC, BOOST_TESTED_AT(0x581))
|
||||
return init_capacity(capacity_ctrl, first, last, std::iterator_traits<Iterator>::iterator_category());
|
||||
#else
|
||||
return init_capacity(
|
||||
@@ -1612,14 +1606,14 @@ private:
|
||||
#endif
|
||||
}
|
||||
|
||||
//! Specialized method for determining the initial capacity.
|
||||
/*! INTERNAL ONLY */
|
||||
template <class InputIterator>
|
||||
static size_type init_capacity(const capacity_type& capacity_ctrl, InputIterator, InputIterator,
|
||||
const std::input_iterator_tag&) {
|
||||
return capacity_ctrl.capacity();
|
||||
}
|
||||
|
||||
//! Specialized method for determining the initial capacity.
|
||||
/*! INTERNAL ONLY */
|
||||
template <class ForwardIterator>
|
||||
static size_type init_capacity(const capacity_type& capacity_ctrl, ForwardIterator first, ForwardIterator last,
|
||||
const std::forward_iterator_tag&) {
|
||||
@@ -1628,13 +1622,13 @@ private:
|
||||
(std::min)(capacity_ctrl.capacity(), static_cast<size_type>(std::distance(first, last))));
|
||||
}
|
||||
|
||||
//! Specialized insert method.
|
||||
/*! INTERNAL ONLY */
|
||||
template <class IntegralType>
|
||||
void insert(const iterator& pos, IntegralType n, IntegralType item, const true_type&) {
|
||||
insert(pos, static_cast<size_type>(n), static_cast<value_type>(item));
|
||||
}
|
||||
|
||||
//! Specialized insert method.
|
||||
/*! INTERNAL ONLY */
|
||||
template <class Iterator>
|
||||
void insert(const iterator& pos, Iterator first, Iterator last, const false_type&) {
|
||||
size_type index = pos - begin();
|
||||
@@ -1642,13 +1636,13 @@ private:
|
||||
circular_buffer<T, Alloc>::insert(begin() + index, first, last);
|
||||
}
|
||||
|
||||
//! Specialized rinsert method.
|
||||
/*! INTERNAL ONLY */
|
||||
template <class IntegralType>
|
||||
void rinsert(const iterator& pos, IntegralType n, IntegralType item, const true_type&) {
|
||||
rinsert(pos, static_cast<size_type>(n), static_cast<value_type>(item));
|
||||
}
|
||||
|
||||
//! Specialized rinsert method.
|
||||
/*! INTERNAL ONLY */
|
||||
template <class Iterator>
|
||||
void rinsert(const iterator& pos, Iterator first, Iterator last, const false_type&) {
|
||||
size_type index = pos - begin();
|
||||
|
||||
Reference in New Issue
Block a user