mirror of
https://github.com/boostorg/circular_buffer.git
synced 2026-02-03 09:02:12 +00:00
Compare commits
15 Commits
boost-1.69
...
boost-1.73
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7808ab19dc | ||
|
|
7be41ca8f9 | ||
|
|
6ccd04cd89 | ||
|
|
7e56abf99b | ||
|
|
0818faec5c | ||
|
|
7cdb7b260c | ||
|
|
81e4b9590f | ||
|
|
3d3b5bffd4 | ||
|
|
03a5c8494e | ||
|
|
14379c5eac | ||
|
|
061ac223a1 | ||
|
|
3dc0e1c56b | ||
|
|
b07fbd056a | ||
|
|
541a0e99fb | ||
|
|
3b9280c0e0 |
60
.travis.yml
60
.travis.yml
@@ -5,6 +5,8 @@ language: cpp
|
||||
|
||||
sudo: false
|
||||
|
||||
dist: trusty
|
||||
|
||||
python: "2.7"
|
||||
|
||||
branches:
|
||||
@@ -97,7 +99,6 @@ matrix:
|
||||
- ubuntu-toolchain-r-test
|
||||
|
||||
- os: linux
|
||||
dist: trusty
|
||||
compiler: g++-7
|
||||
env: TOOLSET=gcc COMPILER=g++-7 CXXSTD=03,11,14,17
|
||||
addons:
|
||||
@@ -109,7 +110,17 @@ matrix:
|
||||
|
||||
- os: linux
|
||||
compiler: g++-8
|
||||
env: TOOLSET=gcc COMPILER=g++-8 CXXSTD=03,11,14,17
|
||||
env: TOOLSET=gcc COMPILER=g++-8 CXXSTD=03,11,14
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- g++-8
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
|
||||
- os: linux
|
||||
compiler: g++-8
|
||||
env: TOOLSET=gcc COMPILER=g++-8 CXXSTD=17,2a
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
@@ -121,6 +132,22 @@ matrix:
|
||||
compiler: clang++
|
||||
env: TOOLSET=clang COMPILER=clang++ CXXSTD=03,11
|
||||
|
||||
- os: linux
|
||||
compiler: /usr/bin/clang++
|
||||
env: TOOLSET=clang COMPILER=/usr/bin/clang++ CXXSTD=03,11
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- clang-3.3
|
||||
|
||||
- os: linux
|
||||
compiler: /usr/bin/clang++
|
||||
env: TOOLSET=clang COMPILER=/usr/bin/clang++ CXXSTD=03,11
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- clang-3.4
|
||||
|
||||
- os: linux
|
||||
compiler: clang++-3.5
|
||||
env: TOOLSET=clang COMPILER=clang++-3.5 CXXSTD=03,11,14,1z
|
||||
@@ -131,6 +158,7 @@ matrix:
|
||||
- libstdc++-4.9-dev
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
- llvm-toolchain-precise-3.5
|
||||
|
||||
- os: linux
|
||||
compiler: clang++-3.6
|
||||
@@ -139,9 +167,20 @@ matrix:
|
||||
apt:
|
||||
packages:
|
||||
- clang-3.6
|
||||
- libstdc++-4.9-dev
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
- llvm-toolchain-precise-3.6
|
||||
|
||||
- os: linux
|
||||
compiler: clang++-3.7
|
||||
env: TOOLSET=clang COMPILER=clang++-3.7 CXXSTD=03,11,14,1z
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- clang-3.7
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
- llvm-toolchain-precise-3.7
|
||||
|
||||
- os: linux
|
||||
compiler: clang++-3.8
|
||||
@@ -153,6 +192,7 @@ matrix:
|
||||
- libstdc++-4.9-dev
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
- llvm-toolchain-precise-3.8
|
||||
|
||||
- os: linux
|
||||
compiler: clang++-3.9
|
||||
@@ -164,6 +204,7 @@ matrix:
|
||||
- libstdc++-4.9-dev
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
- llvm-toolchain-precise-3.9
|
||||
|
||||
- os: linux
|
||||
compiler: clang++-4.0
|
||||
@@ -189,7 +230,7 @@ matrix:
|
||||
|
||||
- os: linux
|
||||
compiler: clang++-6.0
|
||||
env: TOOLSET=clang COMPILER=clang++-6.0 CXXSTD=03,11,14,17
|
||||
env: TOOLSET=clang COMPILER=clang++-6.0 CXXSTD=03,11,14,17,2a
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
@@ -198,6 +239,17 @@ matrix:
|
||||
- ubuntu-toolchain-r-test
|
||||
- llvm-toolchain-trusty-6.0
|
||||
|
||||
- os: linux
|
||||
compiler: clang++-7
|
||||
env: TOOLSET=clang COMPILER=clang++-7 CXXSTD=03,11,14,17,2a
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- clang-7
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
- llvm-toolchain-trusty-7
|
||||
|
||||
- os: linux
|
||||
compiler: clang++-libc++
|
||||
env: TOOLSET=clang COMPILER=clang++-libc++ CXXSTD=03,11,14,1z
|
||||
|
||||
@@ -12,13 +12,13 @@ branches:
|
||||
|
||||
environment:
|
||||
matrix:
|
||||
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2013
|
||||
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
|
||||
TOOLSET: msvc-9.0
|
||||
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2013
|
||||
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
|
||||
TOOLSET: msvc-10.0
|
||||
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2013
|
||||
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
|
||||
TOOLSET: msvc-11.0
|
||||
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2013
|
||||
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
|
||||
TOOLSET: msvc-12.0
|
||||
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
|
||||
TOOLSET: msvc-14.0
|
||||
|
||||
@@ -67,8 +67,8 @@ new data is written starting at the beginning of the buffer and overwriting the
|
||||
|
||||
[classref boost::circular_buffer] is a STL compliant container.
|
||||
|
||||
It is a kind of sequence similar to [@http://www.sgi.com/tech/stl/List.html std::list]
|
||||
or [@http://www.sgi.com/tech/stl/Deque.html std::deque].
|
||||
It is a kind of sequence similar to [@https://www.boost.org/sgi/stl/List.html std::list]
|
||||
or [@https://www.boost.org/sgi/stl/Deque.html std::deque].
|
||||
It supports random access iterators, constant time insert and erase operations
|
||||
at the beginning or the end of the buffer and interoperability with std algorithms.
|
||||
|
||||
@@ -470,9 +470,9 @@ The __cbso is defined in the file [@boost:boost/circular_buffer/space_optimized.
|
||||
|
||||
[section:concepts Modelled Concepts]
|
||||
|
||||
[@http://www.sgi.com/tech/stl/RandomAccessContainer.html Random Access Container],
|
||||
[@http://www.sgi.com/tech/stl/FrontInsertionSequence.html Front Insertion Sequence], and
|
||||
[@http://www.sgi.com/tech/stl/BackInsertionSequence.html Back Insertion sequence]
|
||||
[@https://www.boost.org/sgi/stl/RandomAccessContainer.html Random Access Container],
|
||||
[@https://www.boost.org/sgi/stl/FrontInsertionSequence.html Front Insertion Sequence], and
|
||||
[@https://www.boost.org/sgi/stl/BackInsertionSequence.html Back Insertion sequence]
|
||||
|
||||
[endsect] [/section:concepts Modelled Concepts]
|
||||
|
||||
@@ -483,10 +483,10 @@ The __cbso is defined in the file [@boost:boost/circular_buffer/space_optimized.
|
||||
[[T] [The type of the elements stored in the circular_buffer.
|
||||
The T has to be [@boost:libs/utility/Assignable.html Assignable]
|
||||
and [@boost:libs/utility/CopyConstructible.html CopyConstructible].
|
||||
Moreover T has to be [@http://www.sgi.com/tech/stl/DefaultConstructible.html DefaultConstructible]
|
||||
Moreover T has to be [@https://www.boost.org/sgi/stl/DefaultConstructible.html DefaultConstructible]
|
||||
if supplied as a default parameter when invoking some of the circular_buffer's methods,
|
||||
e.g. `insert(iterator pos, const value_type& item = value_type())`.
|
||||
And [@http://www.sgi.com/tech/stl/EqualityComparable.html EqualityComparable]
|
||||
And [@https://www.boost.org/sgi/stl/EqualityComparable.html EqualityComparable]
|
||||
and/or [@boost:libs/utility/LessThanComparable.html LessThanComparable]
|
||||
if the circular_buffer will be compared with another container.]]
|
||||
[[Alloc] [The allocator type used for all internal memory management.
|
||||
|
||||
@@ -29,8 +29,6 @@ doxygen autodoc
|
||||
[ glob ../../../boost/circular_buffer.hpp ]
|
||||
[ glob ../../../boost/circular_buffer/base.hpp ]
|
||||
[ glob ../../../boost/circular_buffer/space_optimized.hpp ]
|
||||
[ glob ../../../boost/circular_buffer/details.hpp ] # Needed for capacity_control at least.
|
||||
[ glob ../../../boost/circular_buffer/debug.hpp ] # not needed?
|
||||
|
||||
:
|
||||
# Pass some setting parameters to Doxygen.
|
||||
|
||||
@@ -11,8 +11,8 @@
|
||||
#include <boost/thread/mutex.hpp>
|
||||
#include <boost/thread/condition.hpp>
|
||||
#include <boost/thread/thread.hpp>
|
||||
#include <boost/timer/timer.hpp>
|
||||
#include <boost/call_traits.hpp>
|
||||
#include <boost/progress.hpp>
|
||||
#include <boost/bind.hpp>
|
||||
#include <deque>
|
||||
#include <list>
|
||||
@@ -229,7 +229,7 @@ template<class Buffer>
|
||||
void fifo_test(Buffer* buffer) {
|
||||
|
||||
// Start of measurement
|
||||
boost::progress_timer progress;
|
||||
boost::timer::auto_cpu_timer progress;
|
||||
|
||||
// Initialize the buffer with some values before launching producer and consumer threads.
|
||||
for (unsigned long i = QUEUE_SIZE / 2L; i > 0; --i) {
|
||||
|
||||
@@ -19,6 +19,7 @@ as an underlying container of the bounded buffer.
|
||||
#include <boost/bind.hpp>
|
||||
|
||||
#include <boost/timer/timer.hpp> // for auto_cpu_timer
|
||||
#include <iostream>
|
||||
|
||||
template <class T>
|
||||
class bounded_buffer
|
||||
|
||||
@@ -35,7 +35,7 @@ project
|
||||
<toolset>msvc:<cxxflags>/wd4305
|
||||
;
|
||||
|
||||
run bounded_buffer_comparison.cpp ;
|
||||
run bounded_buffer_comparison.cpp ../../timer/build//boost_timer ;
|
||||
run circular_buffer_iter_example.cpp ;
|
||||
run circular_buffer_sum_example.cpp ;
|
||||
run circular_buffer_bound_example.cpp ../../thread/build//boost_thread ../../timer/build//boost_timer ;
|
||||
|
||||
@@ -8,6 +8,10 @@
|
||||
|
||||
// See www.boost.org/libs/circular_buffer for documentation.
|
||||
|
||||
/*! @file
|
||||
Includes <boost/circular_buffer/base.hpp>
|
||||
*/
|
||||
|
||||
#if !defined(BOOST_CIRCULAR_BUFFER_HPP)
|
||||
#define BOOST_CIRCULAR_BUFFER_HPP
|
||||
|
||||
@@ -19,12 +23,12 @@
|
||||
#include <boost/config/workaround.hpp>
|
||||
#include <boost/static_assert.hpp>
|
||||
|
||||
// BOOST_CB_ENABLE_DEBUG: Debug support control.
|
||||
/*! Debug support control. */
|
||||
#if !defined(BOOST_CB_ENABLE_DEBUG)
|
||||
#define BOOST_CB_ENABLE_DEBUG 0
|
||||
#endif
|
||||
|
||||
// BOOST_CB_ASSERT: Runtime assertion.
|
||||
/*! INTERNAL ONLY */
|
||||
#if BOOST_CB_ENABLE_DEBUG
|
||||
#include <boost/assert.hpp>
|
||||
#define BOOST_CB_ASSERT(Expr) BOOST_ASSERT(Expr)
|
||||
@@ -32,7 +36,7 @@
|
||||
#define BOOST_CB_ASSERT(Expr) ((void)0)
|
||||
#endif
|
||||
|
||||
// BOOST_CB_IS_CONVERTIBLE: Check if Iterator::value_type is convertible to Type.
|
||||
/*! INTERNAL ONLY */
|
||||
#if BOOST_WORKAROUND(__BORLANDC__, <= 0x0550) || BOOST_WORKAROUND(__MWERKS__, <= 0x2407)
|
||||
#define BOOST_CB_IS_CONVERTIBLE(Iterator, Type) ((void)0)
|
||||
#else
|
||||
@@ -42,8 +46,7 @@
|
||||
BOOST_STATIC_ASSERT((is_convertible<typename std::iterator_traits<Iterator>::value_type, Type>::value))
|
||||
#endif
|
||||
|
||||
// BOOST_CB_ASSERT_TEMPLATED_ITERATOR_CONSTRUCTORS:
|
||||
// Check if the STL provides templated iterator constructors for its containers.
|
||||
/*! INTERNAL ONLY */
|
||||
#if defined(BOOST_NO_TEMPLATED_ITERATOR_CONSTRUCTORS)
|
||||
#define BOOST_CB_ASSERT_TEMPLATED_ITERATOR_CONSTRUCTORS BOOST_STATIC_ASSERT(false);
|
||||
#else
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
#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
|
||||
@@ -28,16 +27,7 @@ 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);
|
||||
}
|
||||
};
|
||||
using std::allocator_traits;
|
||||
#else
|
||||
template<class A>
|
||||
struct allocator_traits {
|
||||
@@ -47,8 +37,8 @@ struct allocator_traits {
|
||||
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);
|
||||
static size_type max_size(const A& a) BOOST_NOEXCEPT {
|
||||
return a.max_size();
|
||||
}
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
|
||||
|
||||
@@ -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.
|
||||
@@ -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.)
|
||||
*/
|
||||
@@ -711,7 +711,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 +733,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
|
||||
@@ -1131,7 +1131,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 +1153,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 +1170,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 +1316,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 +1349,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 +1370,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 +1414,7 @@ public:
|
||||
|
||||
// push and pop
|
||||
private:
|
||||
/*! INTERNAL ONLY */
|
||||
template <class ValT>
|
||||
void push_back_impl(ValT item) {
|
||||
if (full()) {
|
||||
@@ -1429,6 +1430,7 @@ private:
|
||||
}
|
||||
}
|
||||
|
||||
/*! INTERNAL ONLY */
|
||||
template <class ValT>
|
||||
void push_front_impl(ValT item) {
|
||||
BOOST_TRY {
|
||||
@@ -1621,6 +1623,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 +1794,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 +1817,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 +1843,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 +2039,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 +2061,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 +2336,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 +2357,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 +2395,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 +2416,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,11 +2424,7 @@ 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);
|
||||
@@ -2428,11 +2432,7 @@ private:
|
||||
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));
|
||||
@@ -2440,7 +2440,7 @@ private:
|
||||
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));
|
||||
#if BOOST_CB_ENABLE_DEBUG
|
||||
@@ -2449,13 +2449,13 @@ private:
|
||||
#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 +2464,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 +2487,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 +2505,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,7 +2513,7 @@ 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
|
||||
@@ -2524,7 +2524,7 @@ private:
|
||||
#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 +2534,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 +2542,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,7 +2552,7 @@ 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
|
||||
@@ -2563,7 +2563,7 @@ private:
|
||||
#endif
|
||||
}
|
||||
|
||||
//! Specialized initialize method.
|
||||
/*! INTERNAL ONLY */
|
||||
template <class InputIterator>
|
||||
void initialize(capacity_type buffer_capacity,
|
||||
InputIterator first,
|
||||
@@ -2586,7 +2586,7 @@ private:
|
||||
}
|
||||
}
|
||||
|
||||
//! Specialized initialize method.
|
||||
/*! INTERNAL ONLY */
|
||||
template <class ForwardIterator>
|
||||
void initialize(capacity_type buffer_capacity,
|
||||
ForwardIterator first,
|
||||
@@ -2596,7 +2596,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 +2621,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,23 +2630,23 @@ 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
|
||||
@@ -2657,7 +2657,7 @@ private:
|
||||
#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 +2669,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,13 +2677,13 @@ 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
|
||||
@@ -2694,7 +2694,7 @@ private:
|
||||
#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 +2706,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 +2720,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 +2750,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,13 +2786,13 @@ 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
|
||||
@@ -2803,7 +2803,7 @@ private:
|
||||
#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 +2812,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 +2829,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();
|
||||
@@ -2877,13 +2877,13 @@ 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
|
||||
@@ -2894,7 +2894,7 @@ private:
|
||||
#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 +2906,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)
|
||||
@@ -2966,25 +2966,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 +2998,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 +3017,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>
|
||||
|
||||
@@ -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,28 +1572,28 @@ 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&) {
|
||||
@@ -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();
|
||||
|
||||
@@ -25,11 +25,11 @@ void iterator_constructor_and_assign_test() {
|
||||
circular_buffer<MyInteger>::const_iterator end1 = cb.end();
|
||||
circular_buffer<MyInteger>::const_iterator end2 = end1;
|
||||
|
||||
BOOST_CHECK(itCopy == it);
|
||||
BOOST_CHECK(cit == it);
|
||||
BOOST_CHECK(end1 == end2);
|
||||
BOOST_CHECK(it != end1);
|
||||
BOOST_CHECK(cit != end2);
|
||||
BOOST_TEST(itCopy == it);
|
||||
BOOST_TEST(cit == it);
|
||||
BOOST_TEST(end1 == end2);
|
||||
BOOST_TEST(it != end1);
|
||||
BOOST_TEST(cit != end2);
|
||||
}
|
||||
|
||||
void iterator_reference_test() {
|
||||
@@ -38,14 +38,14 @@ void iterator_reference_test() {
|
||||
circular_buffer<Dummy>::iterator it = cb.begin();
|
||||
circular_buffer<Dummy>::const_iterator cit = cb.begin() + 1;
|
||||
|
||||
BOOST_CHECK((*it).m_n == Dummy::eVar);
|
||||
BOOST_CHECK((*it).fnc() == Dummy::eFnc);
|
||||
BOOST_CHECK((*cit).const_fnc() == Dummy::eConst);
|
||||
BOOST_CHECK((*it).virtual_fnc() == Dummy::eVirtual);
|
||||
BOOST_CHECK(it->m_n == Dummy::eVar);
|
||||
BOOST_CHECK(it->fnc() == Dummy::eFnc);
|
||||
BOOST_CHECK(cit->const_fnc() == Dummy::eConst);
|
||||
BOOST_CHECK(it->virtual_fnc() == Dummy::eVirtual);
|
||||
BOOST_TEST((*it).m_n == Dummy::eVar);
|
||||
BOOST_TEST((*it).fnc() == Dummy::eFnc);
|
||||
BOOST_TEST((*cit).const_fnc() == Dummy::eConst);
|
||||
BOOST_TEST((*it).virtual_fnc() == Dummy::eVirtual);
|
||||
BOOST_TEST(it->m_n == Dummy::eVar);
|
||||
BOOST_TEST(it->fnc() == Dummy::eFnc);
|
||||
BOOST_TEST(cit->const_fnc() == Dummy::eConst);
|
||||
BOOST_TEST(it->virtual_fnc() == Dummy::eVirtual);
|
||||
}
|
||||
|
||||
void iterator_difference_test() {
|
||||
@@ -57,16 +57,16 @@ void iterator_difference_test() {
|
||||
circular_buffer<MyInteger>::const_iterator begin = cb.begin();
|
||||
circular_buffer<MyInteger>::iterator end = cb.end();
|
||||
|
||||
BOOST_CHECK(begin - begin == 0);
|
||||
BOOST_CHECK(end - cb.begin() == 5);
|
||||
BOOST_CHECK(end - end == 0);
|
||||
BOOST_CHECK(begin - cb.end() == -5);
|
||||
BOOST_CHECK(it1 - cb.begin() == 2);
|
||||
BOOST_CHECK(it1 - begin == 2);
|
||||
BOOST_CHECK(end - it1 == 3);
|
||||
BOOST_CHECK(it2 - it1 == 1);
|
||||
BOOST_CHECK(it1 - it2 == -1);
|
||||
BOOST_CHECK(it2 - it2 == 0);
|
||||
BOOST_TEST(begin - begin == 0);
|
||||
BOOST_TEST(end - cb.begin() == 5);
|
||||
BOOST_TEST(end - end == 0);
|
||||
BOOST_TEST(begin - cb.end() == -5);
|
||||
BOOST_TEST(it1 - cb.begin() == 2);
|
||||
BOOST_TEST(it1 - begin == 2);
|
||||
BOOST_TEST(end - it1 == 3);
|
||||
BOOST_TEST(it2 - it1 == 1);
|
||||
BOOST_TEST(it1 - it2 == -1);
|
||||
BOOST_TEST(it2 - it2 == 0);
|
||||
}
|
||||
|
||||
void iterator_increment_test() {
|
||||
@@ -80,9 +80,9 @@ void iterator_increment_test() {
|
||||
it2++;
|
||||
++it3;
|
||||
|
||||
BOOST_CHECK(it1 == cb.begin() + 1);
|
||||
BOOST_CHECK(it2 == cb.begin() + 6);
|
||||
BOOST_CHECK(it3 == cb.end());
|
||||
BOOST_TEST(it1 == cb.begin() + 1);
|
||||
BOOST_TEST(it2 == cb.begin() + 6);
|
||||
BOOST_TEST(it3 == cb.end());
|
||||
}
|
||||
|
||||
void iterator_decrement_test() {
|
||||
@@ -96,9 +96,9 @@ void iterator_decrement_test() {
|
||||
it2--;
|
||||
--it3;
|
||||
|
||||
BOOST_CHECK(it1 == cb.end() - 1);
|
||||
BOOST_CHECK(it2 == cb.end() - 6);
|
||||
BOOST_CHECK(it3 == cb.begin());
|
||||
BOOST_TEST(it1 == cb.end() - 1);
|
||||
BOOST_TEST(it2 == cb.end() - 6);
|
||||
BOOST_TEST(it3 == cb.begin());
|
||||
}
|
||||
|
||||
void iterator_addition_test() {
|
||||
@@ -115,12 +115,12 @@ void iterator_addition_test() {
|
||||
it3 += 5;
|
||||
it4 += -2;
|
||||
|
||||
BOOST_CHECK(it1 == 5 + cb.begin());
|
||||
BOOST_CHECK(it2 == cb.end());
|
||||
BOOST_CHECK(it3 == cb.end());
|
||||
BOOST_CHECK(it4 + 3 == cb.end());
|
||||
BOOST_CHECK((-3) + it4 == cb.begin() + 4);
|
||||
BOOST_CHECK(cb.begin() + 0 == cb.begin());
|
||||
BOOST_TEST(it1 == 5 + cb.begin());
|
||||
BOOST_TEST(it2 == cb.end());
|
||||
BOOST_TEST(it3 == cb.end());
|
||||
BOOST_TEST(it4 + 3 == cb.end());
|
||||
BOOST_TEST((-3) + it4 == cb.begin() + 4);
|
||||
BOOST_TEST(cb.begin() + 0 == cb.begin());
|
||||
}
|
||||
|
||||
void iterator_subtraction_test() {
|
||||
@@ -137,12 +137,12 @@ void iterator_subtraction_test() {
|
||||
it2 -= 0;
|
||||
it3 -= 5;
|
||||
|
||||
BOOST_CHECK(it1 == cb.begin() + 2);
|
||||
BOOST_CHECK(it2 == cb.end());
|
||||
BOOST_CHECK(it3 == cb.begin());
|
||||
BOOST_CHECK(it4 - 7 == cb.begin());
|
||||
BOOST_CHECK(it4 - (-3) == cb.end());
|
||||
BOOST_CHECK(cb.begin() - 0 == cb.begin());
|
||||
BOOST_TEST(it1 == cb.begin() + 2);
|
||||
BOOST_TEST(it2 == cb.end());
|
||||
BOOST_TEST(it3 == cb.begin());
|
||||
BOOST_TEST(it4 - 7 == cb.begin());
|
||||
BOOST_TEST(it4 - (-3) == cb.end());
|
||||
BOOST_TEST(cb.begin() - 0 == cb.begin());
|
||||
}
|
||||
|
||||
void iterator_element_access_test() {
|
||||
@@ -156,9 +156,9 @@ void iterator_element_access_test() {
|
||||
cb.push_back(6);
|
||||
circular_buffer<MyInteger>::iterator it = cb.begin() + 1;
|
||||
|
||||
BOOST_CHECK(it[0] == 2);
|
||||
BOOST_CHECK(it[-1] == 1);
|
||||
BOOST_CHECK(it[2] == 4);
|
||||
BOOST_TEST(it[0] == 2);
|
||||
BOOST_TEST(it[-1] == 1);
|
||||
BOOST_TEST(it[2] == 4);
|
||||
}
|
||||
|
||||
void iterator_comparison_test() {
|
||||
@@ -169,26 +169,26 @@ void iterator_comparison_test() {
|
||||
circular_buffer<MyInteger>::const_iterator begin = cb.begin();
|
||||
circular_buffer<MyInteger>::iterator end = cb.end();
|
||||
|
||||
BOOST_CHECK(begin == begin);
|
||||
BOOST_CHECK(end > cb.begin());
|
||||
BOOST_CHECK(begin < end);
|
||||
BOOST_CHECK(end > begin);
|
||||
BOOST_CHECK(end == end);
|
||||
BOOST_CHECK(begin < cb.end());
|
||||
BOOST_CHECK(!(begin + 1 > cb.end()));
|
||||
BOOST_CHECK(it > cb.begin());
|
||||
BOOST_CHECK(end > it);
|
||||
BOOST_CHECK(begin >= begin);
|
||||
BOOST_CHECK(end >= cb.begin());
|
||||
BOOST_CHECK(end <= end);
|
||||
BOOST_CHECK(begin <= cb.end());
|
||||
BOOST_CHECK(it >= cb.begin());
|
||||
BOOST_CHECK(end >= it);
|
||||
BOOST_CHECK(!(begin + 4 < begin + 4));
|
||||
BOOST_CHECK(begin + 4 < begin + 5);
|
||||
BOOST_CHECK(!(begin + 5 < begin + 4));
|
||||
BOOST_CHECK(it < end - 1);
|
||||
BOOST_CHECK(!(end - 1 < it));
|
||||
BOOST_TEST(begin == begin);
|
||||
BOOST_TEST(end > cb.begin());
|
||||
BOOST_TEST(begin < end);
|
||||
BOOST_TEST(end > begin);
|
||||
BOOST_TEST(end == end);
|
||||
BOOST_TEST(begin < cb.end());
|
||||
BOOST_TEST(!(begin + 1 > cb.end()));
|
||||
BOOST_TEST(it > cb.begin());
|
||||
BOOST_TEST(end > it);
|
||||
BOOST_TEST(begin >= begin);
|
||||
BOOST_TEST(end >= cb.begin());
|
||||
BOOST_TEST(end <= end);
|
||||
BOOST_TEST(begin <= cb.end());
|
||||
BOOST_TEST(it >= cb.begin());
|
||||
BOOST_TEST(end >= it);
|
||||
BOOST_TEST(!(begin + 4 < begin + 4));
|
||||
BOOST_TEST(begin + 4 < begin + 5);
|
||||
BOOST_TEST(!(begin + 5 < begin + 4));
|
||||
BOOST_TEST(it < end - 1);
|
||||
BOOST_TEST(!(end - 1 < it));
|
||||
}
|
||||
|
||||
void iterator_invalidation_test() {
|
||||
@@ -202,12 +202,12 @@ void iterator_invalidation_test() {
|
||||
circular_buffer<MyInteger>::const_iterator it5;
|
||||
circular_buffer<MyInteger>::const_iterator it6;
|
||||
|
||||
BOOST_CHECK(it1.is_valid(0));
|
||||
BOOST_CHECK(it2.is_valid(0));
|
||||
BOOST_CHECK(it3.is_valid(0));
|
||||
BOOST_CHECK(it4.is_valid(0));
|
||||
BOOST_CHECK(it5.is_valid(0));
|
||||
BOOST_CHECK(it6.is_valid(0));
|
||||
BOOST_TEST(it1.is_valid(0));
|
||||
BOOST_TEST(it2.is_valid(0));
|
||||
BOOST_TEST(it3.is_valid(0));
|
||||
BOOST_TEST(it4.is_valid(0));
|
||||
BOOST_TEST(it5.is_valid(0));
|
||||
BOOST_TEST(it6.is_valid(0));
|
||||
|
||||
{
|
||||
circular_buffer<MyInteger> cb(5, 0);
|
||||
@@ -220,49 +220,49 @@ void iterator_invalidation_test() {
|
||||
it5 = it2;
|
||||
it6 = it1;
|
||||
|
||||
BOOST_CHECK(it1.is_valid(&cb));
|
||||
BOOST_CHECK(it2.is_valid(&ccb));
|
||||
BOOST_CHECK(it3.is_valid(&cb));
|
||||
BOOST_CHECK(it4.is_valid(&cb));
|
||||
BOOST_CHECK(it5.is_valid(&ccb));
|
||||
BOOST_CHECK(it6.is_valid(&cb));
|
||||
BOOST_TEST(it1.is_valid(&cb));
|
||||
BOOST_TEST(it2.is_valid(&ccb));
|
||||
BOOST_TEST(it3.is_valid(&cb));
|
||||
BOOST_TEST(it4.is_valid(&cb));
|
||||
BOOST_TEST(it5.is_valid(&ccb));
|
||||
BOOST_TEST(it6.is_valid(&cb));
|
||||
}
|
||||
|
||||
BOOST_CHECK(it1.is_valid(0));
|
||||
BOOST_CHECK(it2.is_valid(0));
|
||||
BOOST_CHECK(it3.is_valid(0));
|
||||
BOOST_CHECK(it4.is_valid(0));
|
||||
BOOST_CHECK(it5.is_valid(0));
|
||||
BOOST_CHECK(it6.is_valid(0));
|
||||
BOOST_TEST(it1.is_valid(0));
|
||||
BOOST_TEST(it2.is_valid(0));
|
||||
BOOST_TEST(it3.is_valid(0));
|
||||
BOOST_TEST(it4.is_valid(0));
|
||||
BOOST_TEST(it5.is_valid(0));
|
||||
BOOST_TEST(it6.is_valid(0));
|
||||
|
||||
circular_buffer<MyInteger> cb(10, 0);
|
||||
it1 = cb.end();
|
||||
cb.clear();
|
||||
BOOST_CHECK(it1.is_valid(&cb));
|
||||
BOOST_TEST(it1.is_valid(&cb));
|
||||
cb.push_back(1);
|
||||
cb.push_back(2);
|
||||
cb.push_back(3);
|
||||
int i = 0;
|
||||
for (it2 = cb.begin(); it2 != it1; it2++, i++);
|
||||
BOOST_CHECK(i == 3);
|
||||
BOOST_TEST(i == 3);
|
||||
|
||||
circular_buffer<MyInteger> cb1(10, 0);
|
||||
circular_buffer<MyInteger> cb2(20, 0);
|
||||
it1 = cb1.end();
|
||||
it2 = cb2.begin();
|
||||
BOOST_CHECK(it1.is_valid(&cb1));
|
||||
BOOST_CHECK(it2.is_valid(&cb2));
|
||||
BOOST_TEST(it1.is_valid(&cb1));
|
||||
BOOST_TEST(it2.is_valid(&cb2));
|
||||
|
||||
cb1.swap(cb2);
|
||||
BOOST_CHECK(!it1.is_valid(&cb1));
|
||||
BOOST_CHECK(!it2.is_valid(&cb2));
|
||||
BOOST_TEST(!it1.is_valid(&cb1));
|
||||
BOOST_TEST(!it2.is_valid(&cb2));
|
||||
|
||||
it1 = cb1.begin() + 3;
|
||||
it2 = cb1.begin();
|
||||
cb1.push_back(1);
|
||||
BOOST_CHECK(it1.is_valid(&cb1));
|
||||
BOOST_CHECK(!it2.is_valid(&cb1));
|
||||
BOOST_CHECK(*it2.m_it == 1);
|
||||
BOOST_TEST(it1.is_valid(&cb1));
|
||||
BOOST_TEST(!it2.is_valid(&cb1));
|
||||
BOOST_TEST(*it2.m_it == 1);
|
||||
|
||||
circular_buffer<MyInteger> cb3(5);
|
||||
cb3.push_back(1);
|
||||
@@ -273,16 +273,16 @@ void iterator_invalidation_test() {
|
||||
it1 = cb3.begin() + 2;
|
||||
it2 = cb3.begin();
|
||||
cb3.insert(cb3.begin() + 3, 6);
|
||||
BOOST_CHECK(it1.is_valid(&cb3));
|
||||
BOOST_CHECK(!it2.is_valid(&cb3));
|
||||
BOOST_CHECK(*it2.m_it == 5);
|
||||
BOOST_TEST(it1.is_valid(&cb3));
|
||||
BOOST_TEST(!it2.is_valid(&cb3));
|
||||
BOOST_TEST(*it2.m_it == 5);
|
||||
|
||||
it1 = cb3.begin() + 3;
|
||||
it2 = cb3.end() - 1;
|
||||
cb3.push_front(7);
|
||||
BOOST_CHECK(it1.is_valid(&cb3));
|
||||
BOOST_CHECK(!it2.is_valid(&cb3));
|
||||
BOOST_CHECK(*it2.m_it == 7);
|
||||
BOOST_TEST(it1.is_valid(&cb3));
|
||||
BOOST_TEST(!it2.is_valid(&cb3));
|
||||
BOOST_TEST(*it2.m_it == 7);
|
||||
|
||||
circular_buffer<MyInteger> cb4(5);
|
||||
cb4.push_back(1);
|
||||
@@ -293,51 +293,51 @@ void iterator_invalidation_test() {
|
||||
it1 = cb4.begin() + 3;
|
||||
it2 = cb4.begin();
|
||||
cb4.rinsert(cb4.begin() + 2, 6);
|
||||
BOOST_CHECK(it1.is_valid(&cb4));
|
||||
BOOST_CHECK(!it2.is_valid(&cb4));
|
||||
BOOST_CHECK(*it2.m_it == 2);
|
||||
BOOST_TEST(it1.is_valid(&cb4));
|
||||
BOOST_TEST(!it2.is_valid(&cb4));
|
||||
BOOST_TEST(*it2.m_it == 2);
|
||||
|
||||
it1 = cb1.begin() + 5;
|
||||
it2 = cb1.end() - 1;
|
||||
cb1.pop_back();
|
||||
BOOST_CHECK(it1.is_valid(&cb1));
|
||||
BOOST_CHECK(!it2.is_valid(&cb1));
|
||||
BOOST_TEST(it1.is_valid(&cb1));
|
||||
BOOST_TEST(!it2.is_valid(&cb1));
|
||||
|
||||
it1 = cb1.begin() + 5;
|
||||
it2 = cb1.begin();
|
||||
cb1.pop_front();
|
||||
BOOST_CHECK(it1.is_valid(&cb1));
|
||||
BOOST_CHECK(!it2.is_valid(&cb1));
|
||||
BOOST_TEST(it1.is_valid(&cb1));
|
||||
BOOST_TEST(!it2.is_valid(&cb1));
|
||||
|
||||
circular_buffer<MyInteger> cb5(20, 0);
|
||||
it1 = cb5.begin() + 5;
|
||||
it2 = it3 = cb5.begin() + 15;
|
||||
cb5.erase(cb5.begin() + 10);
|
||||
BOOST_CHECK(it1.is_valid(&cb5));
|
||||
BOOST_CHECK(!it2.is_valid(&cb5));
|
||||
BOOST_CHECK(!it3.is_valid(&cb5));
|
||||
BOOST_TEST(it1.is_valid(&cb5));
|
||||
BOOST_TEST(!it2.is_valid(&cb5));
|
||||
BOOST_TEST(!it3.is_valid(&cb5));
|
||||
|
||||
it1 = cb5.begin() + 1;
|
||||
it2 = it3 = cb5.begin() + 8;
|
||||
cb5.erase(cb5.begin() + 3, cb5.begin() + 7);
|
||||
BOOST_CHECK(it1.is_valid(&cb5));
|
||||
BOOST_CHECK(!it2.is_valid(&cb5));
|
||||
BOOST_CHECK(!it3.is_valid(&cb5));
|
||||
BOOST_TEST(it1.is_valid(&cb5));
|
||||
BOOST_TEST(!it2.is_valid(&cb5));
|
||||
BOOST_TEST(!it3.is_valid(&cb5));
|
||||
|
||||
circular_buffer<MyInteger> cb6(20, 0);
|
||||
it4 = it1 = cb6.begin() + 5;
|
||||
it2 = cb6.begin() + 15;
|
||||
cb6.rerase(cb6.begin() + 10);
|
||||
BOOST_CHECK(!it1.is_valid(&cb6));
|
||||
BOOST_CHECK(!it4.is_valid(&cb6));
|
||||
BOOST_CHECK(it2.is_valid(&cb6));
|
||||
BOOST_TEST(!it1.is_valid(&cb6));
|
||||
BOOST_TEST(!it4.is_valid(&cb6));
|
||||
BOOST_TEST(it2.is_valid(&cb6));
|
||||
|
||||
it4 = it1 = cb6.begin() + 1;
|
||||
it2 = cb6.begin() + 8;
|
||||
cb6.rerase(cb6.begin() + 3, cb6.begin() + 7);
|
||||
BOOST_CHECK(!it1.is_valid(&cb6));
|
||||
BOOST_CHECK(!it4.is_valid(&cb6));
|
||||
BOOST_CHECK(it2.is_valid(&cb6));
|
||||
BOOST_TEST(!it1.is_valid(&cb6));
|
||||
BOOST_TEST(!it4.is_valid(&cb6));
|
||||
BOOST_TEST(it2.is_valid(&cb6));
|
||||
|
||||
circular_buffer<MyInteger> cb7(10, 1);
|
||||
cb7.push_back(2);
|
||||
@@ -347,16 +347,16 @@ void iterator_invalidation_test() {
|
||||
it2 = cb7.begin();
|
||||
it3 = cb7.begin() + 6;
|
||||
cb7.linearize();
|
||||
BOOST_CHECK(it1.is_valid(&cb7));
|
||||
BOOST_CHECK(!it2.is_valid(&cb7));
|
||||
BOOST_CHECK(!it3.is_valid(&cb7));
|
||||
BOOST_TEST(it1.is_valid(&cb7));
|
||||
BOOST_TEST(!it2.is_valid(&cb7));
|
||||
BOOST_TEST(!it3.is_valid(&cb7));
|
||||
it1 = cb7.end();
|
||||
it2 = cb7.begin();
|
||||
it3 = cb7.begin() + 6;
|
||||
cb7.linearize();
|
||||
BOOST_CHECK(it1.is_valid(&cb7));
|
||||
BOOST_CHECK(it2.is_valid(&cb7));
|
||||
BOOST_CHECK(it3.is_valid(&cb7));
|
||||
BOOST_TEST(it1.is_valid(&cb7));
|
||||
BOOST_TEST(it2.is_valid(&cb7));
|
||||
BOOST_TEST(it3.is_valid(&cb7));
|
||||
|
||||
cb7.push_back(5);
|
||||
cb7.push_back(6);
|
||||
@@ -364,21 +364,21 @@ void iterator_invalidation_test() {
|
||||
it2 = cb7.begin();
|
||||
it3 = cb7.begin() + 6;
|
||||
cb7.set_capacity(10);
|
||||
BOOST_CHECK(it1.is_valid(&cb7));
|
||||
BOOST_CHECK(it2.is_valid(&cb7));
|
||||
BOOST_CHECK(it3.is_valid(&cb7));
|
||||
BOOST_TEST(it1.is_valid(&cb7));
|
||||
BOOST_TEST(it2.is_valid(&cb7));
|
||||
BOOST_TEST(it3.is_valid(&cb7));
|
||||
cb7.set_capacity(20);
|
||||
BOOST_CHECK(it1.is_valid(&cb7));
|
||||
BOOST_CHECK(!it2.is_valid(&cb7));
|
||||
BOOST_CHECK(!it3.is_valid(&cb7));
|
||||
BOOST_TEST(it1.is_valid(&cb7));
|
||||
BOOST_TEST(!it2.is_valid(&cb7));
|
||||
BOOST_TEST(!it3.is_valid(&cb7));
|
||||
cb7.push_back(7);
|
||||
it1 = cb7.end();
|
||||
it2 = cb7.begin();
|
||||
it3 = cb7.begin() + 6;
|
||||
cb7.set_capacity(10);
|
||||
BOOST_CHECK(it1.is_valid(&cb7));
|
||||
BOOST_CHECK(!it2.is_valid(&cb7));
|
||||
BOOST_CHECK(!it3.is_valid(&cb7));
|
||||
BOOST_TEST(it1.is_valid(&cb7));
|
||||
BOOST_TEST(!it2.is_valid(&cb7));
|
||||
BOOST_TEST(!it3.is_valid(&cb7));
|
||||
|
||||
cb7.push_back(8);
|
||||
cb7.push_back(9);
|
||||
@@ -386,21 +386,21 @@ void iterator_invalidation_test() {
|
||||
it2 = cb7.begin();
|
||||
it3 = cb7.begin() + 6;
|
||||
cb7.rset_capacity(10);
|
||||
BOOST_CHECK(it1.is_valid(&cb7));
|
||||
BOOST_CHECK(it2.is_valid(&cb7));
|
||||
BOOST_CHECK(it3.is_valid(&cb7));
|
||||
BOOST_TEST(it1.is_valid(&cb7));
|
||||
BOOST_TEST(it2.is_valid(&cb7));
|
||||
BOOST_TEST(it3.is_valid(&cb7));
|
||||
cb7.rset_capacity(20);
|
||||
BOOST_CHECK(it1.is_valid(&cb7));
|
||||
BOOST_CHECK(!it2.is_valid(&cb7));
|
||||
BOOST_CHECK(!it3.is_valid(&cb7));
|
||||
BOOST_TEST(it1.is_valid(&cb7));
|
||||
BOOST_TEST(!it2.is_valid(&cb7));
|
||||
BOOST_TEST(!it3.is_valid(&cb7));
|
||||
cb7.push_back(10);
|
||||
it1 = cb7.end();
|
||||
it2 = cb7.begin();
|
||||
it3 = cb7.begin() + 6;
|
||||
cb7.rset_capacity(10);
|
||||
BOOST_CHECK(it1.is_valid(&cb7));
|
||||
BOOST_CHECK(!it2.is_valid(&cb7));
|
||||
BOOST_CHECK(!it3.is_valid(&cb7));
|
||||
BOOST_TEST(it1.is_valid(&cb7));
|
||||
BOOST_TEST(!it2.is_valid(&cb7));
|
||||
BOOST_TEST(!it3.is_valid(&cb7));
|
||||
|
||||
circular_buffer<MyInteger> cb8(10, 1);
|
||||
cb8.push_back(2);
|
||||
@@ -409,23 +409,23 @@ void iterator_invalidation_test() {
|
||||
it2 = cb8.begin();
|
||||
it3 = cb8.begin() + 6;
|
||||
cb8.resize(10);
|
||||
BOOST_CHECK(it1.is_valid(&cb8));
|
||||
BOOST_CHECK(it2.is_valid(&cb8));
|
||||
BOOST_CHECK(it3.is_valid(&cb8));
|
||||
BOOST_TEST(it1.is_valid(&cb8));
|
||||
BOOST_TEST(it2.is_valid(&cb8));
|
||||
BOOST_TEST(it3.is_valid(&cb8));
|
||||
cb8.resize(20);
|
||||
BOOST_CHECK(it1.is_valid(&cb8));
|
||||
BOOST_CHECK(!it2.is_valid(&cb8));
|
||||
BOOST_CHECK(!it3.is_valid(&cb8));
|
||||
BOOST_TEST(it1.is_valid(&cb8));
|
||||
BOOST_TEST(!it2.is_valid(&cb8));
|
||||
BOOST_TEST(!it3.is_valid(&cb8));
|
||||
cb8.push_back(4);
|
||||
it1 = cb8.end();
|
||||
it2 = cb8.begin();
|
||||
it3 = cb8.begin() + 6;
|
||||
it4 = cb8.begin() + 12;
|
||||
cb8.resize(10);
|
||||
BOOST_CHECK(it1.is_valid(&cb8));
|
||||
BOOST_CHECK(it2.is_valid(&cb8));
|
||||
BOOST_CHECK(it3.is_valid(&cb8));
|
||||
BOOST_CHECK(!it4.is_valid(&cb8));
|
||||
BOOST_TEST(it1.is_valid(&cb8));
|
||||
BOOST_TEST(it2.is_valid(&cb8));
|
||||
BOOST_TEST(it3.is_valid(&cb8));
|
||||
BOOST_TEST(!it4.is_valid(&cb8));
|
||||
|
||||
cb8.set_capacity(10);
|
||||
cb8.push_back(5);
|
||||
@@ -434,23 +434,23 @@ void iterator_invalidation_test() {
|
||||
it2 = cb8.begin();
|
||||
it3 = cb8.begin() + 6;
|
||||
cb8.rresize(10);
|
||||
BOOST_CHECK(it1.is_valid(&cb8));
|
||||
BOOST_CHECK(it2.is_valid(&cb8));
|
||||
BOOST_CHECK(it3.is_valid(&cb8));
|
||||
BOOST_TEST(it1.is_valid(&cb8));
|
||||
BOOST_TEST(it2.is_valid(&cb8));
|
||||
BOOST_TEST(it3.is_valid(&cb8));
|
||||
cb8.rresize(20);
|
||||
BOOST_CHECK(it1.is_valid(&cb8));
|
||||
BOOST_CHECK(!it2.is_valid(&cb8));
|
||||
BOOST_CHECK(!it3.is_valid(&cb8));
|
||||
BOOST_TEST(it1.is_valid(&cb8));
|
||||
BOOST_TEST(!it2.is_valid(&cb8));
|
||||
BOOST_TEST(!it3.is_valid(&cb8));
|
||||
cb8.push_back(7);
|
||||
it1 = cb8.end();
|
||||
it2 = cb8.begin();
|
||||
it3 = cb8.begin() + 6;
|
||||
it4 = cb8.begin() + 12;
|
||||
cb8.rresize(10);
|
||||
BOOST_CHECK(it1.is_valid(&cb8));
|
||||
BOOST_CHECK(!it2.is_valid(&cb8));
|
||||
BOOST_CHECK(!it3.is_valid(&cb8));
|
||||
BOOST_CHECK(it4.is_valid(&cb8));
|
||||
BOOST_TEST(it1.is_valid(&cb8));
|
||||
BOOST_TEST(!it2.is_valid(&cb8));
|
||||
BOOST_TEST(!it3.is_valid(&cb8));
|
||||
BOOST_TEST(it4.is_valid(&cb8));
|
||||
|
||||
circular_buffer<MyInteger> cb9(15, 1);
|
||||
it1 = cb9.end();
|
||||
@@ -458,10 +458,10 @@ void iterator_invalidation_test() {
|
||||
it3 = cb9.begin() + 6;
|
||||
it4 = cb9.begin() + 12;
|
||||
cb9 = cb8;
|
||||
BOOST_CHECK(it1.is_valid(&cb9));
|
||||
BOOST_CHECK(!it2.is_valid(&cb9));
|
||||
BOOST_CHECK(!it3.is_valid(&cb9));
|
||||
BOOST_CHECK(!it4.is_valid(&cb9));
|
||||
BOOST_TEST(it1.is_valid(&cb9));
|
||||
BOOST_TEST(!it2.is_valid(&cb9));
|
||||
BOOST_TEST(!it3.is_valid(&cb9));
|
||||
BOOST_TEST(!it4.is_valid(&cb9));
|
||||
|
||||
circular_buffer<MyInteger> cb10(10, 1);
|
||||
it1 = cb10.end();
|
||||
@@ -469,10 +469,10 @@ void iterator_invalidation_test() {
|
||||
it3 = cb10.begin() + 3;
|
||||
it4 = cb10.begin() + 7;
|
||||
cb10.assign(5, 2);
|
||||
BOOST_CHECK(it1.is_valid(&cb10));
|
||||
BOOST_CHECK(!it2.is_valid(&cb10));
|
||||
BOOST_CHECK(!it3.is_valid(&cb10));
|
||||
BOOST_CHECK(!it4.is_valid(&cb10));
|
||||
BOOST_TEST(it1.is_valid(&cb10));
|
||||
BOOST_TEST(!it2.is_valid(&cb10));
|
||||
BOOST_TEST(!it3.is_valid(&cb10));
|
||||
BOOST_TEST(!it4.is_valid(&cb10));
|
||||
|
||||
circular_buffer<MyInteger> cb11(10, 1);
|
||||
it1 = cb11.end();
|
||||
@@ -480,10 +480,10 @@ void iterator_invalidation_test() {
|
||||
it3 = cb11.begin() + 3;
|
||||
it4 = cb11.begin() + 7;
|
||||
cb11.assign(15, 5, 2);
|
||||
BOOST_CHECK(it1.is_valid(&cb11));
|
||||
BOOST_CHECK(!it2.is_valid(&cb11));
|
||||
BOOST_CHECK(!it3.is_valid(&cb11));
|
||||
BOOST_CHECK(!it4.is_valid(&cb11));
|
||||
BOOST_TEST(it1.is_valid(&cb11));
|
||||
BOOST_TEST(!it2.is_valid(&cb11));
|
||||
BOOST_TEST(!it3.is_valid(&cb11));
|
||||
BOOST_TEST(!it4.is_valid(&cb11));
|
||||
|
||||
circular_buffer<MyInteger> cb12(10, 1);
|
||||
it1 = cb12.end();
|
||||
@@ -491,10 +491,10 @@ void iterator_invalidation_test() {
|
||||
it3 = cb12.begin() + 3;
|
||||
it4 = cb12.begin() + 7;
|
||||
cb12.assign(cb11.begin(), cb11.end());
|
||||
BOOST_CHECK(it1.is_valid(&cb12));
|
||||
BOOST_CHECK(!it2.is_valid(&cb12));
|
||||
BOOST_CHECK(!it3.is_valid(&cb12));
|
||||
BOOST_CHECK(!it4.is_valid(&cb12));
|
||||
BOOST_TEST(it1.is_valid(&cb12));
|
||||
BOOST_TEST(!it2.is_valid(&cb12));
|
||||
BOOST_TEST(!it3.is_valid(&cb12));
|
||||
BOOST_TEST(!it4.is_valid(&cb12));
|
||||
|
||||
circular_buffer<MyInteger> cb13(10, 1);
|
||||
it1 = cb13.end();
|
||||
@@ -502,10 +502,10 @@ void iterator_invalidation_test() {
|
||||
it3 = cb13.begin() + 3;
|
||||
it4 = cb13.begin() + 7;
|
||||
cb13.assign(15, cb11.begin(), cb11.end());
|
||||
BOOST_CHECK(it1.is_valid(&cb13));
|
||||
BOOST_CHECK(!it2.is_valid(&cb13));
|
||||
BOOST_CHECK(!it3.is_valid(&cb13));
|
||||
BOOST_CHECK(!it4.is_valid(&cb13));
|
||||
BOOST_TEST(it1.is_valid(&cb13));
|
||||
BOOST_TEST(!it2.is_valid(&cb13));
|
||||
BOOST_TEST(!it3.is_valid(&cb13));
|
||||
BOOST_TEST(!it4.is_valid(&cb13));
|
||||
|
||||
circular_buffer<MyInteger> cb14(10);
|
||||
cb14.push_back(1);
|
||||
@@ -520,10 +520,10 @@ void iterator_invalidation_test() {
|
||||
it3 = cb14.begin() + 1;
|
||||
it4 = cb14.begin() + 5;
|
||||
cb14.rotate(it2);
|
||||
BOOST_CHECK(it1.is_valid(&cb14));
|
||||
BOOST_CHECK(it2.is_valid(&cb14));
|
||||
BOOST_CHECK(!it3.is_valid(&cb14));
|
||||
BOOST_CHECK(it4.is_valid(&cb14));
|
||||
BOOST_TEST(it1.is_valid(&cb14));
|
||||
BOOST_TEST(it2.is_valid(&cb14));
|
||||
BOOST_TEST(!it3.is_valid(&cb14));
|
||||
BOOST_TEST(it4.is_valid(&cb14));
|
||||
|
||||
circular_buffer<MyInteger> cb15(7);
|
||||
cb15.push_back(1);
|
||||
@@ -540,10 +540,10 @@ void iterator_invalidation_test() {
|
||||
it3 = cb15.begin() + 1;
|
||||
it4 = cb15.begin() + 5;
|
||||
cb15.rotate(it3);
|
||||
BOOST_CHECK(it1.is_valid(&cb15));
|
||||
BOOST_CHECK(it2.is_valid(&cb15));
|
||||
BOOST_CHECK(it3.is_valid(&cb15));
|
||||
BOOST_CHECK(it4.is_valid(&cb15));
|
||||
BOOST_TEST(it1.is_valid(&cb15));
|
||||
BOOST_TEST(it2.is_valid(&cb15));
|
||||
BOOST_TEST(it3.is_valid(&cb15));
|
||||
BOOST_TEST(it4.is_valid(&cb15));
|
||||
|
||||
circular_buffer<MyInteger> cb16(10);
|
||||
cb16.push_back(1);
|
||||
@@ -558,10 +558,10 @@ void iterator_invalidation_test() {
|
||||
it3 = cb16.begin();
|
||||
it4 = cb16.begin() + 5;
|
||||
cb16.rotate(it4);
|
||||
BOOST_CHECK(it1.is_valid(&cb16));
|
||||
BOOST_CHECK(!it2.is_valid(&cb16));
|
||||
BOOST_CHECK(it3.is_valid(&cb16));
|
||||
BOOST_CHECK(!it4.is_valid(&cb16));
|
||||
BOOST_TEST(it1.is_valid(&cb16));
|
||||
BOOST_TEST(!it2.is_valid(&cb16));
|
||||
BOOST_TEST(it3.is_valid(&cb16));
|
||||
BOOST_TEST(!it4.is_valid(&cb16));
|
||||
|
||||
#endif // #if BOOST_CB_ENABLE_DEBUG
|
||||
}
|
||||
@@ -573,168 +573,168 @@ void exception_safety_test() {
|
||||
|
||||
circular_buffer<MyInteger> cb1(3, 5);
|
||||
MyInteger::set_exception_trigger(3);
|
||||
BOOST_CHECK_THROW(cb1.set_capacity(5), std::exception);
|
||||
BOOST_CHECK(cb1.capacity() == 3);
|
||||
BOOST_TEST_THROWS(cb1.set_capacity(5), std::exception);
|
||||
BOOST_TEST(cb1.capacity() == 3);
|
||||
MyInteger::set_exception_trigger(3);
|
||||
BOOST_CHECK_THROW(cb1.rset_capacity(5), std::exception);
|
||||
BOOST_CHECK(cb1.capacity() == 3);
|
||||
BOOST_TEST_THROWS(cb1.rset_capacity(5), std::exception);
|
||||
BOOST_TEST(cb1.capacity() == 3);
|
||||
generic_test(cb1);
|
||||
|
||||
MyInteger::set_exception_trigger(3);
|
||||
BOOST_CHECK_THROW(circular_buffer<MyInteger> cb2(5, 10), std::exception);
|
||||
BOOST_TEST_THROWS(circular_buffer<MyInteger> cb2(5, 10), std::exception);
|
||||
|
||||
circular_buffer<MyInteger> cb3(5, 10);
|
||||
MyInteger::set_exception_trigger(3);
|
||||
BOOST_CHECK_THROW(circular_buffer<MyInteger> cb4(cb3), std::exception);
|
||||
BOOST_TEST_THROWS(circular_buffer<MyInteger> cb4(cb3), std::exception);
|
||||
|
||||
vector<MyInteger> v(5, MyInteger(10));
|
||||
MyInteger::set_exception_trigger(3);
|
||||
BOOST_CHECK_THROW(circular_buffer<MyInteger> cb5(8, v.begin(), v.end()), std::exception);
|
||||
BOOST_TEST_THROWS(circular_buffer<MyInteger> cb5(8, v.begin(), v.end()), std::exception);
|
||||
|
||||
circular_buffer<MyInteger> cb6(5, 10);
|
||||
circular_buffer<MyInteger> cb7(8, 3);
|
||||
MyInteger::set_exception_trigger(3);
|
||||
BOOST_CHECK_THROW(cb7 = cb6, std::exception);
|
||||
BOOST_CHECK(cb7.size() == 8);
|
||||
BOOST_CHECK(cb7.capacity() == 8);
|
||||
BOOST_CHECK(cb7[0] == 3);
|
||||
BOOST_CHECK(cb7[7] == 3);
|
||||
BOOST_TEST_THROWS(cb7 = cb6, std::exception);
|
||||
BOOST_TEST(cb7.size() == 8);
|
||||
BOOST_TEST(cb7.capacity() == 8);
|
||||
BOOST_TEST(cb7[0] == 3);
|
||||
BOOST_TEST(cb7[7] == 3);
|
||||
generic_test(cb7);
|
||||
|
||||
circular_buffer<MyInteger> cb8(5, 10);
|
||||
MyInteger::set_exception_trigger(2);
|
||||
BOOST_CHECK_THROW(cb8.push_front(1), std::exception);
|
||||
BOOST_TEST_THROWS(cb8.push_front(1), std::exception);
|
||||
|
||||
circular_buffer<MyInteger> cb9(5);
|
||||
cb9.push_back(1);
|
||||
cb9.push_back(2);
|
||||
cb9.push_back(3);
|
||||
MyInteger::set_exception_trigger(3);
|
||||
BOOST_CHECK_THROW(cb9.insert(cb9.begin() + 1, 4), std::exception);
|
||||
BOOST_TEST_THROWS(cb9.insert(cb9.begin() + 1, 4), std::exception);
|
||||
|
||||
circular_buffer<MyInteger> cb10(5);
|
||||
cb10.push_back(1);
|
||||
cb10.push_back(2);
|
||||
cb10.push_back(3);
|
||||
MyInteger::set_exception_trigger(3);
|
||||
BOOST_CHECK_THROW(cb10.rinsert(cb10.begin() + 1, 4), std::exception);
|
||||
BOOST_TEST_THROWS(cb10.rinsert(cb10.begin() + 1, 4), std::exception);
|
||||
|
||||
circular_buffer<MyInteger> cb11(5);
|
||||
cb11.push_back(1);
|
||||
cb11.push_back(2);
|
||||
MyInteger::set_exception_trigger(2);
|
||||
BOOST_CHECK_THROW(cb11.rinsert(cb11.begin(), 1), std::exception);
|
||||
BOOST_TEST_THROWS(cb11.rinsert(cb11.begin(), 1), std::exception);
|
||||
|
||||
circular_buffer<MyInteger> cb12(5, 1);
|
||||
MyInteger::set_exception_trigger(3);
|
||||
BOOST_CHECK_THROW(cb12.assign(4, 2), std::exception);
|
||||
BOOST_TEST_THROWS(cb12.assign(4, 2), std::exception);
|
||||
|
||||
circular_buffer<MyInteger> cb13(5, 1);
|
||||
MyInteger::set_exception_trigger(3);
|
||||
BOOST_CHECK_THROW(cb13.assign(6, 2), std::exception);
|
||||
BOOST_TEST_THROWS(cb13.assign(6, 2), std::exception);
|
||||
|
||||
circular_buffer<MyInteger> cb14(5);
|
||||
cb14.push_back(1);
|
||||
cb14.push_back(2);
|
||||
MyInteger::set_exception_trigger(3);
|
||||
BOOST_CHECK_THROW(cb14.insert(cb14.begin(), 10, 3), std::exception);
|
||||
BOOST_TEST_THROWS(cb14.insert(cb14.begin(), 10, 3), std::exception);
|
||||
|
||||
circular_buffer<MyInteger> cb15(5);
|
||||
cb15.push_back(1);
|
||||
cb15.push_back(2);
|
||||
MyInteger::set_exception_trigger(3);
|
||||
BOOST_CHECK_THROW(cb15.insert(cb15.end(), 10, 3), std::exception);
|
||||
BOOST_TEST_THROWS(cb15.insert(cb15.end(), 10, 3), std::exception);
|
||||
|
||||
circular_buffer<MyInteger> cb16(5);
|
||||
cb16.push_back(1);
|
||||
cb16.push_back(2);
|
||||
MyInteger::set_exception_trigger(3);
|
||||
BOOST_CHECK_THROW(cb16.rinsert(cb16.begin(), 10, 3), std::exception);
|
||||
BOOST_TEST_THROWS(cb16.rinsert(cb16.begin(), 10, 3), std::exception);
|
||||
|
||||
circular_buffer<MyInteger> cb17(5);
|
||||
cb17.push_back(1);
|
||||
cb17.push_back(2);
|
||||
MyInteger::set_exception_trigger(3);
|
||||
BOOST_CHECK_THROW(cb17.rinsert(cb17.end(), 10, 3), std::exception);
|
||||
BOOST_TEST_THROWS(cb17.rinsert(cb17.end(), 10, 3), std::exception);
|
||||
|
||||
circular_buffer<MyInteger> cb18(5, 0);
|
||||
cb18.push_back(1);
|
||||
cb18.push_back(2);
|
||||
cb18.pop_front();
|
||||
MyInteger::set_exception_trigger(4);
|
||||
BOOST_CHECK_THROW(cb18.linearize(), std::exception);
|
||||
BOOST_TEST_THROWS(cb18.linearize(), std::exception);
|
||||
|
||||
circular_buffer<MyInteger> cb19(5, 0);
|
||||
cb19.push_back(1);
|
||||
cb19.push_back(2);
|
||||
MyInteger::set_exception_trigger(5);
|
||||
BOOST_CHECK_THROW(cb19.linearize(), std::exception);
|
||||
BOOST_TEST_THROWS(cb19.linearize(), std::exception);
|
||||
|
||||
circular_buffer<MyInteger> cb20(5, 0);
|
||||
cb20.push_back(1);
|
||||
cb20.push_back(2);
|
||||
MyInteger::set_exception_trigger(6);
|
||||
BOOST_CHECK_THROW(cb20.linearize(), std::exception);
|
||||
BOOST_TEST_THROWS(cb20.linearize(), std::exception);
|
||||
|
||||
circular_buffer<MyInteger> cb21(5);
|
||||
cb21.push_back(1);
|
||||
cb21.push_back(2);
|
||||
cb21.push_back(3);
|
||||
MyInteger::set_exception_trigger(2);
|
||||
BOOST_CHECK_THROW(cb21.insert(cb21.begin() + 1, 4), std::exception);
|
||||
BOOST_TEST_THROWS(cb21.insert(cb21.begin() + 1, 4), std::exception);
|
||||
|
||||
circular_buffer<MyInteger> cb22(5);
|
||||
cb22.push_back(1);
|
||||
cb22.push_back(2);
|
||||
cb22.push_back(3);
|
||||
MyInteger::set_exception_trigger(2);
|
||||
BOOST_CHECK_THROW(cb22.insert(cb22.end(), 4), std::exception);
|
||||
BOOST_TEST_THROWS(cb22.insert(cb22.end(), 4), std::exception);
|
||||
|
||||
circular_buffer<MyInteger> cb23(5, 0);
|
||||
MyInteger::set_exception_trigger(2);
|
||||
BOOST_CHECK_THROW(cb23.insert(cb23.begin() + 1, 4), std::exception);
|
||||
BOOST_TEST_THROWS(cb23.insert(cb23.begin() + 1, 4), std::exception);
|
||||
|
||||
circular_buffer<MyInteger> cb24(5);
|
||||
cb24.push_back(1);
|
||||
cb24.push_back(2);
|
||||
cb24.push_back(3);
|
||||
MyInteger::set_exception_trigger(2);
|
||||
BOOST_CHECK_THROW(cb24.rinsert(cb24.begin() + 1, 4), std::exception);
|
||||
BOOST_TEST_THROWS(cb24.rinsert(cb24.begin() + 1, 4), std::exception);
|
||||
|
||||
circular_buffer<MyInteger> cb25(5, 0);
|
||||
MyInteger::set_exception_trigger(2);
|
||||
BOOST_CHECK_THROW(cb25.rinsert(cb25.begin() + 3, 4), std::exception);
|
||||
BOOST_TEST_THROWS(cb25.rinsert(cb25.begin() + 3, 4), std::exception);
|
||||
|
||||
circular_buffer<MyInteger> cb26(5);
|
||||
cb26.push_back(1);
|
||||
cb26.push_back(2);
|
||||
MyInteger::set_exception_trigger(5);
|
||||
BOOST_CHECK_THROW(cb26.insert(cb26.begin(), 10, 3), std::exception);
|
||||
BOOST_TEST_THROWS(cb26.insert(cb26.begin(), 10, 3), std::exception);
|
||||
|
||||
circular_buffer<MyInteger> cb27(5);
|
||||
cb27.push_back(1);
|
||||
cb27.push_back(2);
|
||||
MyInteger::set_exception_trigger(5);
|
||||
BOOST_CHECK_THROW(cb27.insert(cb27.end(), 10, 3), std::exception);
|
||||
BOOST_TEST_THROWS(cb27.insert(cb27.end(), 10, 3), std::exception);
|
||||
|
||||
circular_buffer<MyInteger> cb28(5);
|
||||
cb28.push_back(1);
|
||||
cb28.push_back(2);
|
||||
MyInteger::set_exception_trigger(5);
|
||||
BOOST_CHECK_THROW(cb28.rinsert(cb28.begin(), 10, 3), std::exception);
|
||||
BOOST_TEST_THROWS(cb28.rinsert(cb28.begin(), 10, 3), std::exception);
|
||||
|
||||
circular_buffer<MyInteger> cb29(5);
|
||||
cb29.push_back(1);
|
||||
cb29.push_back(2);
|
||||
MyInteger::set_exception_trigger(5);
|
||||
BOOST_CHECK_THROW(cb29.rinsert(cb29.end(), 10, 3), std::exception);
|
||||
BOOST_TEST_THROWS(cb29.rinsert(cb29.end(), 10, 3), std::exception);
|
||||
|
||||
circular_buffer<MyInteger> cb30(10);
|
||||
cb30.push_back(1);
|
||||
cb30.push_back(2);
|
||||
cb30.push_back(3);
|
||||
MyInteger::set_exception_trigger(2);
|
||||
BOOST_CHECK_THROW(cb30.rinsert(cb30.begin(), 10, 3), std::exception);
|
||||
BOOST_TEST_THROWS(cb30.rinsert(cb30.begin(), 10, 3), std::exception);
|
||||
|
||||
#endif // #if !defined(BOOST_NO_EXCEPTIONS)
|
||||
}
|
||||
@@ -752,84 +752,84 @@ void move_container_values_resetting_impl() {
|
||||
cb1.push_back();
|
||||
|
||||
cb1.push_back(boost::move(var));
|
||||
BOOST_CHECK(!cb1.back().is_moved());
|
||||
BOOST_CHECK(var.is_moved());
|
||||
BOOST_CHECK(cb1.size() == 1);
|
||||
BOOST_TEST(!cb1.back().is_moved());
|
||||
BOOST_TEST(var.is_moved());
|
||||
BOOST_TEST(cb1.size() == 1);
|
||||
var = boost::move(cb1.back());
|
||||
BOOST_CHECK(cb1.back().is_moved());
|
||||
BOOST_TEST(cb1.back().is_moved());
|
||||
|
||||
cb1.push_front(boost::move(var));
|
||||
BOOST_CHECK(!cb1.front().is_moved());
|
||||
BOOST_CHECK(var.is_moved());
|
||||
BOOST_CHECK(cb1.size() == 1);
|
||||
BOOST_TEST(!cb1.front().is_moved());
|
||||
BOOST_TEST(var.is_moved());
|
||||
BOOST_TEST(cb1.size() == 1);
|
||||
var = boost::move(cb1.back());
|
||||
BOOST_CHECK(cb1.back().is_moved());
|
||||
BOOST_TEST(cb1.back().is_moved());
|
||||
|
||||
cb1.push_back();
|
||||
BOOST_CHECK(!cb1.back().is_moved());
|
||||
BOOST_CHECK(cb1.size() == 1);
|
||||
BOOST_TEST(!cb1.back().is_moved());
|
||||
BOOST_TEST(cb1.size() == 1);
|
||||
var = boost::move(cb1.back());
|
||||
BOOST_CHECK(cb1.back().is_moved());
|
||||
BOOST_TEST(cb1.back().is_moved());
|
||||
|
||||
cb1.push_front();
|
||||
BOOST_CHECK(!cb1.front().is_moved());
|
||||
BOOST_CHECK(cb1.size() == 1);
|
||||
BOOST_TEST(!cb1.front().is_moved());
|
||||
BOOST_TEST(cb1.size() == 1);
|
||||
var = boost::move(cb1.back());
|
||||
BOOST_CHECK(cb1.back().is_moved());
|
||||
BOOST_TEST(cb1.back().is_moved());
|
||||
|
||||
|
||||
cb1.insert(cb1.begin());
|
||||
// If the circular_buffer is full and the pos points to begin(),
|
||||
// then the item will not be inserted.
|
||||
BOOST_CHECK(cb1.front().is_moved());
|
||||
BOOST_CHECK(cb1.size() == 1);
|
||||
BOOST_TEST(cb1.front().is_moved());
|
||||
BOOST_TEST(cb1.size() == 1);
|
||||
var = boost::move(cb1.back());
|
||||
BOOST_CHECK(cb1.back().is_moved());
|
||||
BOOST_TEST(cb1.back().is_moved());
|
||||
|
||||
cb1.insert(cb1.begin(), boost::move(var));
|
||||
// If the circular_buffer is full and the pos points to begin(),
|
||||
// then the item will not be inserted.
|
||||
BOOST_CHECK(cb1.front().is_moved());
|
||||
BOOST_CHECK(cb1.size() == 1);
|
||||
BOOST_TEST(cb1.front().is_moved());
|
||||
BOOST_TEST(cb1.size() == 1);
|
||||
var = boost::move(cb1.back());
|
||||
BOOST_CHECK(cb1.back().is_moved());
|
||||
BOOST_TEST(cb1.back().is_moved());
|
||||
|
||||
cb1.rinsert(cb1.begin());
|
||||
BOOST_CHECK(!cb1.back().is_moved());
|
||||
BOOST_CHECK(cb1.size() == 1);
|
||||
BOOST_TEST(!cb1.back().is_moved());
|
||||
BOOST_TEST(cb1.size() == 1);
|
||||
var = boost::move(cb1.back());
|
||||
BOOST_CHECK(cb1.back().is_moved());
|
||||
BOOST_TEST(cb1.back().is_moved());
|
||||
|
||||
var.reinit();
|
||||
cb1.rinsert(cb1.begin(), boost::move(var));
|
||||
BOOST_CHECK(!cb1.back().is_moved());
|
||||
BOOST_CHECK(cb1.size() == 1);
|
||||
BOOST_TEST(!cb1.back().is_moved());
|
||||
BOOST_TEST(cb1.size() == 1);
|
||||
var = boost::move(cb1.back());
|
||||
BOOST_CHECK(cb1.back().is_moved());
|
||||
BOOST_TEST(cb1.back().is_moved());
|
||||
|
||||
cb1.rinsert(cb1.end());
|
||||
BOOST_CHECK(cb1.back().is_moved());
|
||||
BOOST_CHECK(cb1.size() == 1);
|
||||
BOOST_TEST(cb1.back().is_moved());
|
||||
BOOST_TEST(cb1.size() == 1);
|
||||
var = boost::move(cb1.back());
|
||||
BOOST_CHECK(cb1.back().is_moved());
|
||||
BOOST_TEST(cb1.back().is_moved());
|
||||
|
||||
var.reinit();
|
||||
cb1.rinsert(cb1.end(), boost::move(var));
|
||||
BOOST_CHECK(cb1.back().is_moved());
|
||||
BOOST_CHECK(cb1.size() == 1);
|
||||
BOOST_TEST(cb1.back().is_moved());
|
||||
BOOST_TEST(cb1.size() == 1);
|
||||
var = boost::move(cb1.back());
|
||||
BOOST_CHECK(cb1.back().is_moved());
|
||||
BOOST_TEST(cb1.back().is_moved());
|
||||
cb1.push_back();
|
||||
BOOST_CHECK(!cb1[0].is_moved());
|
||||
BOOST_TEST(!cb1[0].is_moved());
|
||||
|
||||
const int val = cb1[0].value();
|
||||
cb1.linearize();
|
||||
BOOST_CHECK(!cb1[0].is_moved());
|
||||
BOOST_CHECK(cb1[0].value() == val);
|
||||
BOOST_TEST(!cb1[0].is_moved());
|
||||
BOOST_TEST(cb1[0].value() == val);
|
||||
|
||||
cb1.rotate(cb1.begin());
|
||||
BOOST_CHECK(!cb1[0].is_moved());
|
||||
BOOST_CHECK(cb1[0].value() == val);
|
||||
BOOST_TEST(!cb1[0].is_moved());
|
||||
BOOST_TEST(cb1[0].value() == val);
|
||||
}
|
||||
|
||||
void move_container_values_resetting_except() {
|
||||
@@ -841,25 +841,22 @@ void move_container_values_resetting_noexcept() {
|
||||
}
|
||||
|
||||
// test main
|
||||
test_suite* init_unit_test_suite(int /*argc*/, char* /*argv*/[]) {
|
||||
|
||||
test_suite* tests = BOOST_TEST_SUITE("Unit tests for the circular_buffer.");
|
||||
add_common_tests(tests);
|
||||
|
||||
tests->add(BOOST_TEST_CASE(&iterator_constructor_and_assign_test));
|
||||
tests->add(BOOST_TEST_CASE(&iterator_reference_test));
|
||||
tests->add(BOOST_TEST_CASE(&iterator_difference_test));
|
||||
tests->add(BOOST_TEST_CASE(&iterator_increment_test));
|
||||
tests->add(BOOST_TEST_CASE(&iterator_decrement_test));
|
||||
tests->add(BOOST_TEST_CASE(&iterator_addition_test));
|
||||
tests->add(BOOST_TEST_CASE(&iterator_subtraction_test));
|
||||
tests->add(BOOST_TEST_CASE(&iterator_element_access_test));
|
||||
tests->add(BOOST_TEST_CASE(&iterator_comparison_test));
|
||||
tests->add(BOOST_TEST_CASE(&iterator_invalidation_test));
|
||||
tests->add(BOOST_TEST_CASE(&exception_safety_test));
|
||||
tests->add(BOOST_TEST_CASE(&move_container_values_except));
|
||||
tests->add(BOOST_TEST_CASE(&move_container_values_resetting_except));
|
||||
tests->add(BOOST_TEST_CASE(&move_container_values_resetting_noexcept));
|
||||
|
||||
return tests;
|
||||
int main()
|
||||
{
|
||||
run_common_tests();
|
||||
iterator_constructor_and_assign_test();
|
||||
iterator_reference_test();
|
||||
iterator_difference_test();
|
||||
iterator_increment_test();
|
||||
iterator_decrement_test();
|
||||
iterator_addition_test();
|
||||
iterator_subtraction_test();
|
||||
iterator_element_access_test();
|
||||
iterator_comparison_test();
|
||||
iterator_invalidation_test();
|
||||
exception_safety_test();
|
||||
move_container_values_except();
|
||||
move_container_values_resetting_except();
|
||||
move_container_values_resetting_noexcept();
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
||||
@@ -11,8 +11,8 @@
|
||||
#include <boost/thread/mutex.hpp>
|
||||
#include <boost/thread/condition_variable.hpp>
|
||||
#include <boost/thread/thread.hpp>
|
||||
#include <boost/timer/timer.hpp>
|
||||
#include <boost/call_traits.hpp>
|
||||
#include <boost/progress.hpp>
|
||||
#include <boost/bind.hpp>
|
||||
#include <deque>
|
||||
#include <list>
|
||||
@@ -229,7 +229,7 @@ template<class Buffer>
|
||||
void fifo_test(Buffer* buffer) {
|
||||
|
||||
// Start of measurement
|
||||
boost::progress_timer progress;
|
||||
boost::timer::auto_cpu_timer progress;
|
||||
|
||||
// Initialize the buffer with some values before launching producer and consumer threads.
|
||||
for (unsigned long i = QUEUE_SIZE / 2L; i > 0; --i) {
|
||||
|
||||
1704
test/common.ipp
1704
test/common.ipp
File diff suppressed because it is too large
Load Diff
@@ -25,35 +25,35 @@ void erase_begin_test() {
|
||||
|
||||
cb1.erase_begin(2);
|
||||
|
||||
BOOST_CHECK(cb1.size() == 3);
|
||||
BOOST_CHECK(cb1[0] == 4);
|
||||
BOOST_CHECK(cb1[1] == 5);
|
||||
BOOST_CHECK(cb1[2] == 6);
|
||||
BOOST_TEST(cb1.size() == 3);
|
||||
BOOST_TEST(cb1[0] == 4);
|
||||
BOOST_TEST(cb1[1] == 5);
|
||||
BOOST_TEST(cb1[2] == 6);
|
||||
|
||||
cb1.erase_begin(3);
|
||||
BOOST_CHECK(cb1.empty());
|
||||
BOOST_CHECK(*p == 2);
|
||||
BOOST_CHECK(*(p + 1) == 3);
|
||||
BOOST_CHECK(*(p + 2) == 4);
|
||||
BOOST_TEST(cb1.empty());
|
||||
BOOST_TEST(*p == 2);
|
||||
BOOST_TEST(*(p + 1) == 3);
|
||||
BOOST_TEST(*(p + 2) == 4);
|
||||
|
||||
cb1.push_back(10);
|
||||
cb1.push_back(11);
|
||||
cb1.push_back(12);
|
||||
|
||||
BOOST_CHECK(cb1.size() == 3);
|
||||
BOOST_CHECK(cb1[0] == 10);
|
||||
BOOST_CHECK(cb1[1] == 11);
|
||||
BOOST_CHECK(cb1[2] == 12);
|
||||
BOOST_TEST(cb1.size() == 3);
|
||||
BOOST_TEST(cb1[0] == 10);
|
||||
BOOST_TEST(cb1[1] == 11);
|
||||
BOOST_TEST(cb1[2] == 12);
|
||||
|
||||
circular_buffer<InstanceCounter> cb2(5, InstanceCounter());
|
||||
|
||||
BOOST_CHECK(cb2.size() == 5);
|
||||
BOOST_CHECK(InstanceCounter::count() == 5);
|
||||
BOOST_TEST(cb2.size() == 5);
|
||||
BOOST_TEST(InstanceCounter::count() == 5);
|
||||
|
||||
cb2.erase_begin(2);
|
||||
|
||||
BOOST_CHECK(cb2.size() == 3);
|
||||
BOOST_CHECK(InstanceCounter::count() == 3);
|
||||
BOOST_TEST(cb2.size() == 3);
|
||||
BOOST_TEST(InstanceCounter::count() == 3);
|
||||
|
||||
circular_buffer<MyInteger> cb3(5);
|
||||
cb3.push_back(1);
|
||||
@@ -64,10 +64,10 @@ void erase_begin_test() {
|
||||
cb3.push_back(6);
|
||||
cb3.erase_begin(2);
|
||||
|
||||
BOOST_CHECK(cb3.size() == 3);
|
||||
BOOST_CHECK(cb3[0] == 4);
|
||||
BOOST_CHECK(cb3[1] == 5);
|
||||
BOOST_CHECK(cb3[2] == 6);
|
||||
BOOST_TEST(cb3.size() == 3);
|
||||
BOOST_TEST(cb3[0] == 4);
|
||||
BOOST_TEST(cb3[1] == 5);
|
||||
BOOST_TEST(cb3[2] == 6);
|
||||
}
|
||||
|
||||
void erase_end_test() {
|
||||
@@ -84,35 +84,35 @@ void erase_end_test() {
|
||||
|
||||
cb1.erase_end(2);
|
||||
|
||||
BOOST_CHECK(cb1.size() == 3);
|
||||
BOOST_CHECK(cb1[0] == 2);
|
||||
BOOST_CHECK(cb1[1] == 3);
|
||||
BOOST_CHECK(cb1[2] ==4);
|
||||
BOOST_TEST(cb1.size() == 3);
|
||||
BOOST_TEST(cb1[0] == 2);
|
||||
BOOST_TEST(cb1[1] == 3);
|
||||
BOOST_TEST(cb1[2] ==4);
|
||||
|
||||
cb1.erase_end(3);
|
||||
BOOST_CHECK(cb1.empty());
|
||||
BOOST_CHECK(*p == 5);
|
||||
BOOST_CHECK(*(p - 1) == 4);
|
||||
BOOST_CHECK(*(p - 2) == 3);
|
||||
BOOST_TEST(cb1.empty());
|
||||
BOOST_TEST(*p == 5);
|
||||
BOOST_TEST(*(p - 1) == 4);
|
||||
BOOST_TEST(*(p - 2) == 3);
|
||||
|
||||
cb1.push_back(10);
|
||||
cb1.push_back(11);
|
||||
cb1.push_back(12);
|
||||
|
||||
BOOST_CHECK(cb1.size() == 3);
|
||||
BOOST_CHECK(cb1[0] == 10);
|
||||
BOOST_CHECK(cb1[1] == 11);
|
||||
BOOST_CHECK(cb1[2] == 12);
|
||||
BOOST_TEST(cb1.size() == 3);
|
||||
BOOST_TEST(cb1[0] == 10);
|
||||
BOOST_TEST(cb1[1] == 11);
|
||||
BOOST_TEST(cb1[2] == 12);
|
||||
|
||||
circular_buffer<InstanceCounter> cb2(5, InstanceCounter());
|
||||
|
||||
BOOST_CHECK(cb2.size() == 5);
|
||||
BOOST_CHECK(InstanceCounter::count() == 5);
|
||||
BOOST_TEST(cb2.size() == 5);
|
||||
BOOST_TEST(InstanceCounter::count() == 5);
|
||||
|
||||
cb2.erase_end(2);
|
||||
|
||||
BOOST_CHECK(cb2.size() == 3);
|
||||
BOOST_CHECK(InstanceCounter::count() == 3);
|
||||
BOOST_TEST(cb2.size() == 3);
|
||||
BOOST_TEST(InstanceCounter::count() == 3);
|
||||
|
||||
circular_buffer<MyInteger> cb3(5);
|
||||
cb3.push_back(1);
|
||||
@@ -123,10 +123,10 @@ void erase_end_test() {
|
||||
cb3.push_back(6);
|
||||
cb3.erase_end(2);
|
||||
|
||||
BOOST_CHECK(cb3.size() == 3);
|
||||
BOOST_CHECK(cb3[0] == 2);
|
||||
BOOST_CHECK(cb3[1] == 3);
|
||||
BOOST_CHECK(cb3[2] == 4);
|
||||
BOOST_TEST(cb3.size() == 3);
|
||||
BOOST_TEST(cb3[0] == 2);
|
||||
BOOST_TEST(cb3[1] == 3);
|
||||
BOOST_TEST(cb3[2] == 4);
|
||||
}
|
||||
|
||||
void clear_test() {
|
||||
@@ -143,22 +143,22 @@ void clear_test() {
|
||||
|
||||
cb1.clear();
|
||||
|
||||
BOOST_CHECK(cb1.empty());
|
||||
BOOST_CHECK(*p == 2);
|
||||
BOOST_CHECK(*(p + 1) == 3);
|
||||
BOOST_CHECK(*(p + 2) == 4);
|
||||
BOOST_CHECK(*(p + 3) == 5);
|
||||
BOOST_CHECK(*(p - 1) == 6);
|
||||
BOOST_TEST(cb1.empty());
|
||||
BOOST_TEST(*p == 2);
|
||||
BOOST_TEST(*(p + 1) == 3);
|
||||
BOOST_TEST(*(p + 2) == 4);
|
||||
BOOST_TEST(*(p + 3) == 5);
|
||||
BOOST_TEST(*(p - 1) == 6);
|
||||
|
||||
circular_buffer<InstanceCounter> cb2(5, InstanceCounter());
|
||||
|
||||
BOOST_CHECK(cb2.size() == 5);
|
||||
BOOST_CHECK(InstanceCounter::count() == 5);
|
||||
BOOST_TEST(cb2.size() == 5);
|
||||
BOOST_TEST(InstanceCounter::count() == 5);
|
||||
|
||||
cb2.clear();
|
||||
|
||||
BOOST_CHECK(cb2.empty());
|
||||
BOOST_CHECK(InstanceCounter::count() == 0);
|
||||
BOOST_TEST(cb2.empty());
|
||||
BOOST_TEST(InstanceCounter::count() == 0);
|
||||
|
||||
circular_buffer<MyInteger> cb3(5);
|
||||
cb3.push_back(1);
|
||||
@@ -169,17 +169,14 @@ void clear_test() {
|
||||
cb3.push_back(6);
|
||||
cb3.clear();
|
||||
|
||||
BOOST_CHECK(cb3.empty());
|
||||
BOOST_TEST(cb3.empty());
|
||||
}
|
||||
|
||||
// test main
|
||||
test_suite* init_unit_test_suite(int /*argc*/, char* /*argv*/[]) {
|
||||
|
||||
test_suite* tests = BOOST_TEST_SUITE("Unit tests for erase_begin/end and clear methods of the circular_buffer.");
|
||||
|
||||
tests->add(BOOST_TEST_CASE(&erase_begin_test));
|
||||
tests->add(BOOST_TEST_CASE(&erase_end_test));
|
||||
tests->add(BOOST_TEST_CASE(&clear_test));
|
||||
|
||||
return tests;
|
||||
int main()
|
||||
{
|
||||
erase_begin_test();
|
||||
erase_end_test();
|
||||
clear_test();
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
||||
@@ -22,11 +22,11 @@ void validity_example_test() {
|
||||
|
||||
circular_buffer<int>::iterator it = cb.begin();
|
||||
|
||||
BOOST_CHECK(*it == 1);
|
||||
BOOST_TEST(*it == 1);
|
||||
|
||||
cb.push_back(4);
|
||||
|
||||
BOOST_CHECK(*it == 4);
|
||||
BOOST_TEST(*it == 4);
|
||||
}
|
||||
|
||||
void validity_insert_test() {
|
||||
@@ -46,13 +46,13 @@ void validity_insert_test() {
|
||||
|
||||
// memory placement: { 1, 4, 2, 3 }
|
||||
// circular buffer: { 1, 4, 2, 3 }
|
||||
BOOST_CHECK(*it1 == 1);
|
||||
BOOST_CHECK(*it2 == 4);
|
||||
BOOST_CHECK(*it3 == 2);
|
||||
BOOST_CHECK(cb[0] == 1);
|
||||
BOOST_CHECK(cb[1] == 4);
|
||||
BOOST_CHECK(cb[2] == 2);
|
||||
BOOST_CHECK(cb[3] == 3);
|
||||
BOOST_TEST(*it1 == 1);
|
||||
BOOST_TEST(*it2 == 4);
|
||||
BOOST_TEST(*it3 == 2);
|
||||
BOOST_TEST(cb[0] == 1);
|
||||
BOOST_TEST(cb[1] == 4);
|
||||
BOOST_TEST(cb[2] == 2);
|
||||
BOOST_TEST(cb[3] == 3);
|
||||
|
||||
// it4 -> 3
|
||||
circular_buffer<int>::iterator it4 = it1 + 3;
|
||||
@@ -61,14 +61,14 @@ void validity_insert_test() {
|
||||
|
||||
// memory placement: { 3, 5, 4, 2 }
|
||||
// circular buffer: { 5, 4, 2, 3 }
|
||||
BOOST_CHECK(*it1 == 3);
|
||||
BOOST_CHECK(*it2 == 5);
|
||||
BOOST_CHECK(*it3 == 4);
|
||||
BOOST_CHECK(*it4 == 2);
|
||||
BOOST_CHECK(cb[0] == 5);
|
||||
BOOST_CHECK(cb[1] == 4);
|
||||
BOOST_CHECK(cb[2] == 2);
|
||||
BOOST_CHECK(cb[3] == 3);
|
||||
BOOST_TEST(*it1 == 3);
|
||||
BOOST_TEST(*it2 == 5);
|
||||
BOOST_TEST(*it3 == 4);
|
||||
BOOST_TEST(*it4 == 2);
|
||||
BOOST_TEST(cb[0] == 5);
|
||||
BOOST_TEST(cb[1] == 4);
|
||||
BOOST_TEST(cb[2] == 2);
|
||||
BOOST_TEST(cb[3] == 3);
|
||||
}
|
||||
|
||||
void validity_insert_n_test() {
|
||||
@@ -89,14 +89,14 @@ void validity_insert_n_test() {
|
||||
|
||||
// memory placement: { 1, 4, 4, 2, 3 }
|
||||
// circular buffer: { 1, 4, 4, 2, 3 }
|
||||
BOOST_CHECK(*it1 == 1);
|
||||
BOOST_CHECK(*it2 == 4);
|
||||
BOOST_CHECK(*it3 == 4);
|
||||
BOOST_CHECK(cb[0] == 1);
|
||||
BOOST_CHECK(cb[1] == 4);
|
||||
BOOST_CHECK(cb[2] == 4);
|
||||
BOOST_CHECK(cb[3] == 2);
|
||||
BOOST_CHECK(cb[4] == 3);
|
||||
BOOST_TEST(*it1 == 1);
|
||||
BOOST_TEST(*it2 == 4);
|
||||
BOOST_TEST(*it3 == 4);
|
||||
BOOST_TEST(cb[0] == 1);
|
||||
BOOST_TEST(cb[1] == 4);
|
||||
BOOST_TEST(cb[2] == 4);
|
||||
BOOST_TEST(cb[3] == 2);
|
||||
BOOST_TEST(cb[4] == 3);
|
||||
|
||||
// it4 -> 2, it5 -> 3
|
||||
circular_buffer<int>::iterator it4 = it1 + 3;
|
||||
@@ -106,16 +106,16 @@ void validity_insert_n_test() {
|
||||
|
||||
// memory placement: { 3, 5, 4, 4, 2 } - 5 inserted only once
|
||||
// circular buffer: { 5, 4, 4, 2, 3 }
|
||||
BOOST_CHECK(*it1 == 3);
|
||||
BOOST_CHECK(*it2 == 5);
|
||||
BOOST_CHECK(*it3 == 4);
|
||||
BOOST_CHECK(*it4 == 4);
|
||||
BOOST_CHECK(*it5 == 2);
|
||||
BOOST_CHECK(cb[0] == 5);
|
||||
BOOST_CHECK(cb[1] == 4);
|
||||
BOOST_CHECK(cb[2] == 4);
|
||||
BOOST_CHECK(cb[3] == 2);
|
||||
BOOST_CHECK(cb[4] == 3);
|
||||
BOOST_TEST(*it1 == 3);
|
||||
BOOST_TEST(*it2 == 5);
|
||||
BOOST_TEST(*it3 == 4);
|
||||
BOOST_TEST(*it4 == 4);
|
||||
BOOST_TEST(*it5 == 2);
|
||||
BOOST_TEST(cb[0] == 5);
|
||||
BOOST_TEST(cb[1] == 4);
|
||||
BOOST_TEST(cb[2] == 4);
|
||||
BOOST_TEST(cb[3] == 2);
|
||||
BOOST_TEST(cb[4] == 3);
|
||||
}
|
||||
|
||||
void validity_insert_range_test() {
|
||||
@@ -145,14 +145,14 @@ void validity_insert_range_test() {
|
||||
|
||||
// memory placement: { 1, 4, 5, 2, 3 }
|
||||
// circular buffer: { 1, 4, 5, 2, 3 }
|
||||
BOOST_CHECK(*it11 == 1);
|
||||
BOOST_CHECK(*it12 == 4);
|
||||
BOOST_CHECK(*it13 == 5);
|
||||
BOOST_CHECK(cb1[0] == 1);
|
||||
BOOST_CHECK(cb1[1] == 4);
|
||||
BOOST_CHECK(cb1[2] == 5);
|
||||
BOOST_CHECK(cb1[3] == 2);
|
||||
BOOST_CHECK(cb1[4] == 3);
|
||||
BOOST_TEST(*it11 == 1);
|
||||
BOOST_TEST(*it12 == 4);
|
||||
BOOST_TEST(*it13 == 5);
|
||||
BOOST_TEST(cb1[0] == 1);
|
||||
BOOST_TEST(cb1[1] == 4);
|
||||
BOOST_TEST(cb1[2] == 5);
|
||||
BOOST_TEST(cb1[3] == 2);
|
||||
BOOST_TEST(cb1[4] == 3);
|
||||
|
||||
// it14 -> 2, it15 -> 3
|
||||
circular_buffer<int>::iterator it14 = it11 + 3;
|
||||
@@ -162,16 +162,16 @@ void validity_insert_range_test() {
|
||||
|
||||
// memory placement: { 3, 7, 4, 5, 2 } - 7 inserted only
|
||||
// circular buffer: { 7, 4, 5, 2, 3 }
|
||||
BOOST_CHECK(*it11 == 3);
|
||||
BOOST_CHECK(*it12 == 7);
|
||||
BOOST_CHECK(*it13 == 4);
|
||||
BOOST_CHECK(*it14 == 5);
|
||||
BOOST_CHECK(*it15 == 2);
|
||||
BOOST_CHECK(cb1[0] == 7);
|
||||
BOOST_CHECK(cb1[1] == 4);
|
||||
BOOST_CHECK(cb1[2] == 5);
|
||||
BOOST_CHECK(cb1[3] == 2);
|
||||
BOOST_CHECK(cb1[4] == 3);
|
||||
BOOST_TEST(*it11 == 3);
|
||||
BOOST_TEST(*it12 == 7);
|
||||
BOOST_TEST(*it13 == 4);
|
||||
BOOST_TEST(*it14 == 5);
|
||||
BOOST_TEST(*it15 == 2);
|
||||
BOOST_TEST(cb1[0] == 7);
|
||||
BOOST_TEST(cb1[1] == 4);
|
||||
BOOST_TEST(cb1[2] == 5);
|
||||
BOOST_TEST(cb1[3] == 2);
|
||||
BOOST_TEST(cb1[4] == 3);
|
||||
|
||||
// memory placement: { 1, 2, 3 }
|
||||
// circular buffer: { 1, 2, 3 }
|
||||
@@ -189,14 +189,14 @@ void validity_insert_range_test() {
|
||||
|
||||
// memory placement: { 1, 4, 5, 2, 3 }
|
||||
// circular buffer: { 1, 4, 5, 2, 3 }
|
||||
BOOST_CHECK(*it21 == 1);
|
||||
BOOST_CHECK(*it22 == 4);
|
||||
BOOST_CHECK(*it23 == 5);
|
||||
BOOST_CHECK(cb2[0] == 1);
|
||||
BOOST_CHECK(cb2[1] == 4);
|
||||
BOOST_CHECK(cb2[2] == 5);
|
||||
BOOST_CHECK(cb2[3] == 2);
|
||||
BOOST_CHECK(cb2[4] == 3);
|
||||
BOOST_TEST(*it21 == 1);
|
||||
BOOST_TEST(*it22 == 4);
|
||||
BOOST_TEST(*it23 == 5);
|
||||
BOOST_TEST(cb2[0] == 1);
|
||||
BOOST_TEST(cb2[1] == 4);
|
||||
BOOST_TEST(cb2[2] == 5);
|
||||
BOOST_TEST(cb2[3] == 2);
|
||||
BOOST_TEST(cb2[4] == 3);
|
||||
|
||||
// it24 -> 2, it25 -> 3
|
||||
circular_buffer<int>::iterator it24 = it21 + 3;
|
||||
@@ -206,16 +206,16 @@ void validity_insert_range_test() {
|
||||
|
||||
// memory placement: { 2, 3, 7, 4, 5 } - using input iterator inserts all items even if they are later replaced
|
||||
// circular buffer: { 7, 4, 5, 2, 3 }
|
||||
BOOST_CHECK(*it21 == 2);
|
||||
BOOST_CHECK(*it22 == 3);
|
||||
BOOST_CHECK(*it23 == 7);
|
||||
BOOST_CHECK(*it24 == 4);
|
||||
BOOST_CHECK(*it25 == 5);
|
||||
BOOST_CHECK(cb2[0] == 7);
|
||||
BOOST_CHECK(cb2[1] == 4);
|
||||
BOOST_CHECK(cb2[2] == 5);
|
||||
BOOST_CHECK(cb2[3] == 2);
|
||||
BOOST_CHECK(cb2[4] == 3);
|
||||
BOOST_TEST(*it21 == 2);
|
||||
BOOST_TEST(*it22 == 3);
|
||||
BOOST_TEST(*it23 == 7);
|
||||
BOOST_TEST(*it24 == 4);
|
||||
BOOST_TEST(*it25 == 5);
|
||||
BOOST_TEST(cb2[0] == 7);
|
||||
BOOST_TEST(cb2[1] == 4);
|
||||
BOOST_TEST(cb2[2] == 5);
|
||||
BOOST_TEST(cb2[3] == 2);
|
||||
BOOST_TEST(cb2[4] == 3);
|
||||
}
|
||||
|
||||
void validity_rinsert_test() {
|
||||
@@ -235,13 +235,13 @@ void validity_rinsert_test() {
|
||||
|
||||
// memory placement: { 2, 4, 3, 1 }
|
||||
// circular buffer: { 1, 2, 4, 3 }
|
||||
BOOST_CHECK(*it1 == 2);
|
||||
BOOST_CHECK(*it2 == 4);
|
||||
BOOST_CHECK(*it3 == 3);
|
||||
BOOST_CHECK(cb[0] == 1);
|
||||
BOOST_CHECK(cb[1] == 2);
|
||||
BOOST_CHECK(cb[2] == 4);
|
||||
BOOST_CHECK(cb[3] == 3);
|
||||
BOOST_TEST(*it1 == 2);
|
||||
BOOST_TEST(*it2 == 4);
|
||||
BOOST_TEST(*it3 == 3);
|
||||
BOOST_TEST(cb[0] == 1);
|
||||
BOOST_TEST(cb[1] == 2);
|
||||
BOOST_TEST(cb[2] == 4);
|
||||
BOOST_TEST(cb[3] == 3);
|
||||
|
||||
// it4 -> 1
|
||||
circular_buffer<int>::iterator it4 = it1 - 1;
|
||||
@@ -250,14 +250,14 @@ void validity_rinsert_test() {
|
||||
|
||||
// memory placement: { 5, 4, 1, 2 }
|
||||
// circular buffer: { 1, 2, 5, 4 }
|
||||
BOOST_CHECK(*it1 == 5);
|
||||
BOOST_CHECK(*it2 == 4);
|
||||
BOOST_CHECK(*it3 == 1);
|
||||
BOOST_CHECK(*it4 == 2);
|
||||
BOOST_CHECK(cb[0] == 1);
|
||||
BOOST_CHECK(cb[1] == 2);
|
||||
BOOST_CHECK(cb[2] == 5);
|
||||
BOOST_CHECK(cb[3] == 4);
|
||||
BOOST_TEST(*it1 == 5);
|
||||
BOOST_TEST(*it2 == 4);
|
||||
BOOST_TEST(*it3 == 1);
|
||||
BOOST_TEST(*it4 == 2);
|
||||
BOOST_TEST(cb[0] == 1);
|
||||
BOOST_TEST(cb[1] == 2);
|
||||
BOOST_TEST(cb[2] == 5);
|
||||
BOOST_TEST(cb[3] == 4);
|
||||
}
|
||||
|
||||
void validity_rinsert_n_test() {
|
||||
@@ -278,14 +278,14 @@ void validity_rinsert_n_test() {
|
||||
|
||||
// memory placement: { 4, 4, 3, 1, 2 }
|
||||
// circular buffer: { 1, 2, 4, 4, 3 }
|
||||
BOOST_CHECK(*it1 == 4);
|
||||
BOOST_CHECK(*it2 == 4);
|
||||
BOOST_CHECK(*it3 == 3);
|
||||
BOOST_CHECK(cb[0] == 1);
|
||||
BOOST_CHECK(cb[1] == 2);
|
||||
BOOST_CHECK(cb[2] == 4);
|
||||
BOOST_CHECK(cb[3] == 4);
|
||||
BOOST_CHECK(cb[4] == 3);
|
||||
BOOST_TEST(*it1 == 4);
|
||||
BOOST_TEST(*it2 == 4);
|
||||
BOOST_TEST(*it3 == 3);
|
||||
BOOST_TEST(cb[0] == 1);
|
||||
BOOST_TEST(cb[1] == 2);
|
||||
BOOST_TEST(cb[2] == 4);
|
||||
BOOST_TEST(cb[3] == 4);
|
||||
BOOST_TEST(cb[4] == 3);
|
||||
|
||||
// it4 -> 1, it5 -> 2
|
||||
circular_buffer<int>::iterator it4 = it1 - 2;
|
||||
@@ -295,16 +295,16 @@ void validity_rinsert_n_test() {
|
||||
|
||||
// memory placement: { 4, 5, 1, 2, 4 } - 5 inserted only once
|
||||
// circular buffer: { 1, 2, 4, 4, 5 }
|
||||
BOOST_CHECK(*it1 == 4);
|
||||
BOOST_CHECK(*it2 == 5);
|
||||
BOOST_CHECK(*it3 == 1);
|
||||
BOOST_CHECK(*it4 == 2);
|
||||
BOOST_CHECK(*it5 == 4);
|
||||
BOOST_CHECK(cb[0] == 1);
|
||||
BOOST_CHECK(cb[1] == 2);
|
||||
BOOST_CHECK(cb[2] == 4);
|
||||
BOOST_CHECK(cb[3] == 4);
|
||||
BOOST_CHECK(cb[4] == 5);
|
||||
BOOST_TEST(*it1 == 4);
|
||||
BOOST_TEST(*it2 == 5);
|
||||
BOOST_TEST(*it3 == 1);
|
||||
BOOST_TEST(*it4 == 2);
|
||||
BOOST_TEST(*it5 == 4);
|
||||
BOOST_TEST(cb[0] == 1);
|
||||
BOOST_TEST(cb[1] == 2);
|
||||
BOOST_TEST(cb[2] == 4);
|
||||
BOOST_TEST(cb[3] == 4);
|
||||
BOOST_TEST(cb[4] == 5);
|
||||
}
|
||||
|
||||
void validity_rinsert_range_test() {
|
||||
@@ -334,14 +334,14 @@ void validity_rinsert_range_test() {
|
||||
|
||||
// memory placement: { 4, 5, 3, 1, 2 }
|
||||
// circular buffer: { 1, 2, 4, 5, 3 }
|
||||
BOOST_CHECK(*it11 == 4);
|
||||
BOOST_CHECK(*it12 == 5);
|
||||
BOOST_CHECK(*it13 == 3);
|
||||
BOOST_CHECK(cb1[0] == 1);
|
||||
BOOST_CHECK(cb1[1] == 2);
|
||||
BOOST_CHECK(cb1[2] == 4);
|
||||
BOOST_CHECK(cb1[3] == 5);
|
||||
BOOST_CHECK(cb1[4] == 3);
|
||||
BOOST_TEST(*it11 == 4);
|
||||
BOOST_TEST(*it12 == 5);
|
||||
BOOST_TEST(*it13 == 3);
|
||||
BOOST_TEST(cb1[0] == 1);
|
||||
BOOST_TEST(cb1[1] == 2);
|
||||
BOOST_TEST(cb1[2] == 4);
|
||||
BOOST_TEST(cb1[3] == 5);
|
||||
BOOST_TEST(cb1[4] == 3);
|
||||
|
||||
// it14 -> 1, it15 -> 2
|
||||
circular_buffer<int>::iterator it14 = it11 - 2;
|
||||
@@ -351,16 +351,16 @@ void validity_rinsert_range_test() {
|
||||
|
||||
// memory placement: { 5, 6, 1, 2, 4 } - 6 inserted only
|
||||
// circular buffer: { 1, 2, 4, 5, 6 }
|
||||
BOOST_CHECK(*it11 == 5);
|
||||
BOOST_CHECK(*it12 == 6);
|
||||
BOOST_CHECK(*it13 == 1);
|
||||
BOOST_CHECK(*it14 == 2);
|
||||
BOOST_CHECK(*it15 == 4);
|
||||
BOOST_CHECK(cb1[0] == 1);
|
||||
BOOST_CHECK(cb1[1] == 2);
|
||||
BOOST_CHECK(cb1[2] == 4);
|
||||
BOOST_CHECK(cb1[3] == 5);
|
||||
BOOST_CHECK(cb1[4] == 6);
|
||||
BOOST_TEST(*it11 == 5);
|
||||
BOOST_TEST(*it12 == 6);
|
||||
BOOST_TEST(*it13 == 1);
|
||||
BOOST_TEST(*it14 == 2);
|
||||
BOOST_TEST(*it15 == 4);
|
||||
BOOST_TEST(cb1[0] == 1);
|
||||
BOOST_TEST(cb1[1] == 2);
|
||||
BOOST_TEST(cb1[2] == 4);
|
||||
BOOST_TEST(cb1[3] == 5);
|
||||
BOOST_TEST(cb1[4] == 6);
|
||||
|
||||
// memory placement: { 1, 2, 3 }
|
||||
// circular buffer: { 1, 2, 3 }
|
||||
@@ -378,14 +378,14 @@ void validity_rinsert_range_test() {
|
||||
|
||||
// memory placement: { 4, 5, 3, 1, 2 }
|
||||
// circular buffer: { 1, 2, 4, 5, 3 }
|
||||
BOOST_CHECK(*it21 == 4);
|
||||
BOOST_CHECK(*it22 == 5);
|
||||
BOOST_CHECK(*it23 == 3);
|
||||
BOOST_CHECK(cb2[0] == 1);
|
||||
BOOST_CHECK(cb2[1] == 2);
|
||||
BOOST_CHECK(cb2[2] == 4);
|
||||
BOOST_CHECK(cb2[3] == 5);
|
||||
BOOST_CHECK(cb2[4] == 3);
|
||||
BOOST_TEST(*it21 == 4);
|
||||
BOOST_TEST(*it22 == 5);
|
||||
BOOST_TEST(*it23 == 3);
|
||||
BOOST_TEST(cb2[0] == 1);
|
||||
BOOST_TEST(cb2[1] == 2);
|
||||
BOOST_TEST(cb2[2] == 4);
|
||||
BOOST_TEST(cb2[3] == 5);
|
||||
BOOST_TEST(cb2[4] == 3);
|
||||
|
||||
// it24 -> 1, it25 -> 2
|
||||
circular_buffer<int>::iterator it24 = it21 - 2;
|
||||
@@ -395,16 +395,16 @@ void validity_rinsert_range_test() {
|
||||
|
||||
// memory placement: { 5, 6, 1, 2, 4 }
|
||||
// circular buffer: { 1, 2, 4, 5, 6 }
|
||||
BOOST_CHECK(*it21 == 5);
|
||||
BOOST_CHECK(*it22 == 6);
|
||||
BOOST_CHECK(*it23 == 1);
|
||||
BOOST_CHECK(*it24 == 2);
|
||||
BOOST_CHECK(*it25 == 4);
|
||||
BOOST_CHECK(cb2[0] == 1);
|
||||
BOOST_CHECK(cb2[1] == 2);
|
||||
BOOST_CHECK(cb2[2] == 4);
|
||||
BOOST_CHECK(cb2[3] == 5);
|
||||
BOOST_CHECK(cb2[4] == 6);
|
||||
BOOST_TEST(*it21 == 5);
|
||||
BOOST_TEST(*it22 == 6);
|
||||
BOOST_TEST(*it23 == 1);
|
||||
BOOST_TEST(*it24 == 2);
|
||||
BOOST_TEST(*it25 == 4);
|
||||
BOOST_TEST(cb2[0] == 1);
|
||||
BOOST_TEST(cb2[1] == 2);
|
||||
BOOST_TEST(cb2[2] == 4);
|
||||
BOOST_TEST(cb2[3] == 5);
|
||||
BOOST_TEST(cb2[4] == 6);
|
||||
}
|
||||
|
||||
void validity_erase_test() {
|
||||
@@ -430,14 +430,14 @@ void validity_erase_test() {
|
||||
|
||||
// memory placement: { 5, X, 1, 3, 4 }
|
||||
// circular buffer: { 1, 3, 4, 5 }
|
||||
BOOST_CHECK(*it1 == 1);
|
||||
BOOST_CHECK(*it2 == 3);
|
||||
BOOST_CHECK(*it3 == 4);
|
||||
BOOST_CHECK(*it4 == 5);
|
||||
BOOST_CHECK(cb[0] == 1);
|
||||
BOOST_CHECK(cb[1] == 3);
|
||||
BOOST_CHECK(cb[2] == 4);
|
||||
BOOST_CHECK(cb[3] == 5);
|
||||
BOOST_TEST(*it1 == 1);
|
||||
BOOST_TEST(*it2 == 3);
|
||||
BOOST_TEST(*it3 == 4);
|
||||
BOOST_TEST(*it4 == 5);
|
||||
BOOST_TEST(cb[0] == 1);
|
||||
BOOST_TEST(cb[1] == 3);
|
||||
BOOST_TEST(cb[2] == 4);
|
||||
BOOST_TEST(cb[3] == 5);
|
||||
}
|
||||
|
||||
void validity_erase_range_test() {
|
||||
@@ -465,14 +465,14 @@ void validity_erase_range_test() {
|
||||
|
||||
// memory placement: { 6, X, X, 1, 2, 5 }
|
||||
// circular buffer: { 1, 2, 5, 6 }
|
||||
BOOST_CHECK(*it1 == 1);
|
||||
BOOST_CHECK(*it2 == 2);
|
||||
BOOST_CHECK(*it3 == 5);
|
||||
BOOST_CHECK(*it4 == 6);
|
||||
BOOST_CHECK(cb[0] == 1);
|
||||
BOOST_CHECK(cb[1] == 2);
|
||||
BOOST_CHECK(cb[2] == 5);
|
||||
BOOST_CHECK(cb[3] == 6);
|
||||
BOOST_TEST(*it1 == 1);
|
||||
BOOST_TEST(*it2 == 2);
|
||||
BOOST_TEST(*it3 == 5);
|
||||
BOOST_TEST(*it4 == 6);
|
||||
BOOST_TEST(cb[0] == 1);
|
||||
BOOST_TEST(cb[1] == 2);
|
||||
BOOST_TEST(cb[2] == 5);
|
||||
BOOST_TEST(cb[3] == 6);
|
||||
}
|
||||
|
||||
void validity_rerase_test() {
|
||||
@@ -498,14 +498,14 @@ void validity_rerase_test() {
|
||||
|
||||
// memory placement: { 4, 5, X, 1, 3 }
|
||||
// circular buffer: { 1, 3, 4, 5 }
|
||||
BOOST_CHECK(*it1 == 1);
|
||||
BOOST_CHECK(*it2 == 3);
|
||||
BOOST_CHECK(*it3 == 4);
|
||||
BOOST_CHECK(*it4 == 5);
|
||||
BOOST_CHECK(cb[0] == 1);
|
||||
BOOST_CHECK(cb[1] == 3);
|
||||
BOOST_CHECK(cb[2] == 4);
|
||||
BOOST_CHECK(cb[3] == 5);
|
||||
BOOST_TEST(*it1 == 1);
|
||||
BOOST_TEST(*it2 == 3);
|
||||
BOOST_TEST(*it3 == 4);
|
||||
BOOST_TEST(*it4 == 5);
|
||||
BOOST_TEST(cb[0] == 1);
|
||||
BOOST_TEST(cb[1] == 3);
|
||||
BOOST_TEST(cb[2] == 4);
|
||||
BOOST_TEST(cb[3] == 5);
|
||||
}
|
||||
|
||||
void validity_rerase_range_test() {
|
||||
@@ -533,14 +533,14 @@ void validity_rerase_range_test() {
|
||||
|
||||
// memory placement: { 2, 5, 6, X, X, 1 }
|
||||
// circular buffer: { 1, 2, 5, 6 }
|
||||
BOOST_CHECK(*it1 == 1);
|
||||
BOOST_CHECK(*it2 == 2);
|
||||
BOOST_CHECK(*it3 == 5);
|
||||
BOOST_CHECK(*it4 == 6);
|
||||
BOOST_CHECK(cb[0] == 1);
|
||||
BOOST_CHECK(cb[1] == 2);
|
||||
BOOST_CHECK(cb[2] == 5);
|
||||
BOOST_CHECK(cb[3] == 6);
|
||||
BOOST_TEST(*it1 == 1);
|
||||
BOOST_TEST(*it2 == 2);
|
||||
BOOST_TEST(*it3 == 5);
|
||||
BOOST_TEST(*it4 == 6);
|
||||
BOOST_TEST(cb[0] == 1);
|
||||
BOOST_TEST(cb[1] == 2);
|
||||
BOOST_TEST(cb[2] == 5);
|
||||
BOOST_TEST(cb[3] == 6);
|
||||
}
|
||||
|
||||
void validity_linearize_test() {
|
||||
@@ -562,12 +562,12 @@ void validity_linearize_test() {
|
||||
|
||||
// memory placement: { 1, 2, 3 }
|
||||
// circular buffer: { 1, 2, 3 }
|
||||
BOOST_CHECK(*it1 == 2);
|
||||
BOOST_CHECK(*it2 == 3);
|
||||
BOOST_CHECK(*it3 == 1);
|
||||
BOOST_CHECK(cb[0] == 1);
|
||||
BOOST_CHECK(cb[1] == 2);
|
||||
BOOST_CHECK(cb[2] == 3);
|
||||
BOOST_TEST(*it1 == 2);
|
||||
BOOST_TEST(*it2 == 3);
|
||||
BOOST_TEST(*it3 == 1);
|
||||
BOOST_TEST(cb[0] == 1);
|
||||
BOOST_TEST(cb[1] == 2);
|
||||
BOOST_TEST(cb[2] == 3);
|
||||
}
|
||||
|
||||
void validity_swap_test() {
|
||||
@@ -602,18 +602,18 @@ void validity_swap_test() {
|
||||
// Although iterators refer to the original elements,
|
||||
// their internal state is inconsistent and no other operation
|
||||
// (except dereferencing) can be invoked on them any more.
|
||||
BOOST_CHECK(*it11 == 1);
|
||||
BOOST_CHECK(*it12 == 2);
|
||||
BOOST_CHECK(*it13 == 3);
|
||||
BOOST_CHECK(*it21 == 4);
|
||||
BOOST_CHECK(*it22 == 5);
|
||||
BOOST_CHECK(*it23 == 6);
|
||||
BOOST_CHECK(cb1[0] == 4);
|
||||
BOOST_CHECK(cb1[1] == 5);
|
||||
BOOST_CHECK(cb1[2] == 6);
|
||||
BOOST_CHECK(cb2[0] == 1);
|
||||
BOOST_CHECK(cb2[1] == 2);
|
||||
BOOST_CHECK(cb2[2] == 3);
|
||||
BOOST_TEST(*it11 == 1);
|
||||
BOOST_TEST(*it12 == 2);
|
||||
BOOST_TEST(*it13 == 3);
|
||||
BOOST_TEST(*it21 == 4);
|
||||
BOOST_TEST(*it22 == 5);
|
||||
BOOST_TEST(*it23 == 6);
|
||||
BOOST_TEST(cb1[0] == 4);
|
||||
BOOST_TEST(cb1[1] == 5);
|
||||
BOOST_TEST(cb1[2] == 6);
|
||||
BOOST_TEST(cb2[0] == 1);
|
||||
BOOST_TEST(cb2[1] == 2);
|
||||
BOOST_TEST(cb2[2] == 3);
|
||||
}
|
||||
|
||||
void validity_push_back_test() {
|
||||
@@ -635,12 +635,12 @@ void validity_push_back_test() {
|
||||
|
||||
// memory placement: { 3, 4, 2 }
|
||||
// circular buffer: { 2, 3, 4 }
|
||||
BOOST_CHECK(*it1 == 4);
|
||||
BOOST_CHECK(*it2 == 2);
|
||||
BOOST_CHECK(*it3 == 3);
|
||||
BOOST_CHECK(cb[0] == 2);
|
||||
BOOST_CHECK(cb[1] == 3);
|
||||
BOOST_CHECK(cb[2] == 4);
|
||||
BOOST_TEST(*it1 == 4);
|
||||
BOOST_TEST(*it2 == 2);
|
||||
BOOST_TEST(*it3 == 3);
|
||||
BOOST_TEST(cb[0] == 2);
|
||||
BOOST_TEST(cb[1] == 3);
|
||||
BOOST_TEST(cb[2] == 4);
|
||||
}
|
||||
|
||||
void validity_push_front_test() {
|
||||
@@ -662,12 +662,12 @@ void validity_push_front_test() {
|
||||
|
||||
// memory placement: { 4, 1, 2 }
|
||||
// circular buffer: { 4, 1, 2 }
|
||||
BOOST_CHECK(*it1 == 1);
|
||||
BOOST_CHECK(*it2 == 2);
|
||||
BOOST_CHECK(*it3 == 4);
|
||||
BOOST_CHECK(cb[0] == 4);
|
||||
BOOST_CHECK(cb[1] == 1);
|
||||
BOOST_CHECK(cb[2] == 2);
|
||||
BOOST_TEST(*it1 == 1);
|
||||
BOOST_TEST(*it2 == 2);
|
||||
BOOST_TEST(*it3 == 4);
|
||||
BOOST_TEST(cb[0] == 4);
|
||||
BOOST_TEST(cb[1] == 1);
|
||||
BOOST_TEST(cb[2] == 2);
|
||||
}
|
||||
|
||||
void validity_pop_back_test() {
|
||||
@@ -688,10 +688,10 @@ void validity_pop_back_test() {
|
||||
|
||||
// memory placement: { X, 1, 2 }
|
||||
// circular buffer: { 1, 2 }
|
||||
BOOST_CHECK(*it1 == 1);
|
||||
BOOST_CHECK(*it2 == 2);
|
||||
BOOST_CHECK(cb[0] == 1);
|
||||
BOOST_CHECK(cb[1] == 2);
|
||||
BOOST_TEST(*it1 == 1);
|
||||
BOOST_TEST(*it2 == 2);
|
||||
BOOST_TEST(cb[0] == 1);
|
||||
BOOST_TEST(cb[1] == 2);
|
||||
}
|
||||
|
||||
void validity_pop_front_test() {
|
||||
@@ -712,34 +712,31 @@ void validity_pop_front_test() {
|
||||
|
||||
// memory placement: { 3, X, 2 }
|
||||
// circular buffer: { 2, 3 }
|
||||
BOOST_CHECK(*it1 == 2);
|
||||
BOOST_CHECK(*it2 == 3);
|
||||
BOOST_CHECK(cb[0] == 2);
|
||||
BOOST_CHECK(cb[1] == 3);
|
||||
BOOST_TEST(*it1 == 2);
|
||||
BOOST_TEST(*it2 == 3);
|
||||
BOOST_TEST(cb[0] == 2);
|
||||
BOOST_TEST(cb[1] == 3);
|
||||
}
|
||||
|
||||
// test main
|
||||
test_suite* init_unit_test_suite(int /*argc*/, char* /*argv*/[]) {
|
||||
|
||||
test_suite* tests = BOOST_TEST_SUITE("Unit tests for the iterator of the circular_buffer.");
|
||||
|
||||
tests->add(BOOST_TEST_CASE(&validity_example_test));
|
||||
tests->add(BOOST_TEST_CASE(&validity_insert_test));
|
||||
tests->add(BOOST_TEST_CASE(&validity_insert_n_test));
|
||||
tests->add(BOOST_TEST_CASE(&validity_insert_range_test));
|
||||
tests->add(BOOST_TEST_CASE(&validity_rinsert_test));
|
||||
tests->add(BOOST_TEST_CASE(&validity_rinsert_n_test));
|
||||
tests->add(BOOST_TEST_CASE(&validity_rinsert_range_test));
|
||||
tests->add(BOOST_TEST_CASE(&validity_erase_test));
|
||||
tests->add(BOOST_TEST_CASE(&validity_erase_range_test));
|
||||
tests->add(BOOST_TEST_CASE(&validity_rerase_test));
|
||||
tests->add(BOOST_TEST_CASE(&validity_rerase_range_test));
|
||||
tests->add(BOOST_TEST_CASE(&validity_linearize_test));
|
||||
tests->add(BOOST_TEST_CASE(&validity_swap_test));
|
||||
tests->add(BOOST_TEST_CASE(&validity_push_back_test));
|
||||
tests->add(BOOST_TEST_CASE(&validity_push_front_test));
|
||||
tests->add(BOOST_TEST_CASE(&validity_pop_back_test));
|
||||
tests->add(BOOST_TEST_CASE(&validity_pop_front_test));
|
||||
|
||||
return tests;
|
||||
int main()
|
||||
{
|
||||
validity_example_test();
|
||||
validity_insert_test();
|
||||
validity_insert_n_test();
|
||||
validity_insert_range_test();
|
||||
validity_rinsert_test();
|
||||
validity_rinsert_n_test();
|
||||
validity_rinsert_range_test();
|
||||
validity_erase_test();
|
||||
validity_erase_range_test();
|
||||
validity_rerase_test();
|
||||
validity_rerase_range_test();
|
||||
validity_linearize_test();
|
||||
validity_swap_test();
|
||||
validity_push_back_test();
|
||||
validity_push_front_test();
|
||||
validity_pop_back_test();
|
||||
validity_pop_front_test();
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
||||
@@ -29,33 +29,33 @@ void min_capacity_test() {
|
||||
cb_space_optimized cb2(capacity_ctrl(10, 5), 1);
|
||||
cb_space_optimized cb3(capacity_ctrl(20, 10), v.begin(), v.end());
|
||||
|
||||
BOOST_CHECK(cb1.size() == 0);
|
||||
BOOST_CHECK(cb1.capacity().capacity() == 10);
|
||||
BOOST_CHECK(cb1.capacity().min_capacity() == 10);
|
||||
BOOST_CHECK(cb2[0] == 1);
|
||||
BOOST_CHECK(cb2.size() == 10);
|
||||
BOOST_CHECK(cb2.capacity() == 10);
|
||||
BOOST_CHECK(cb2.capacity().min_capacity() == 5);
|
||||
BOOST_CHECK(cb3[0] == 1);
|
||||
BOOST_CHECK(cb3.size() == 5);
|
||||
BOOST_CHECK(cb3.capacity() == 20);
|
||||
BOOST_CHECK(cb3.capacity().min_capacity() == 10);
|
||||
BOOST_CHECK(cb1.capacity().min_capacity() <= cb1.internal_capacity());
|
||||
BOOST_CHECK(cb2.capacity().min_capacity() <= cb2.internal_capacity());
|
||||
BOOST_CHECK(cb3.capacity().min_capacity() <= cb3.internal_capacity());
|
||||
BOOST_TEST(cb1.size() == 0);
|
||||
BOOST_TEST(cb1.capacity().capacity() == 10);
|
||||
BOOST_TEST(cb1.capacity().min_capacity() == 10);
|
||||
BOOST_TEST(cb2[0] == 1);
|
||||
BOOST_TEST(cb2.size() == 10);
|
||||
BOOST_TEST(cb2.capacity() == 10);
|
||||
BOOST_TEST(cb2.capacity().min_capacity() == 5);
|
||||
BOOST_TEST(cb3[0] == 1);
|
||||
BOOST_TEST(cb3.size() == 5);
|
||||
BOOST_TEST(cb3.capacity() == 20);
|
||||
BOOST_TEST(cb3.capacity().min_capacity() == 10);
|
||||
BOOST_TEST(cb1.capacity().min_capacity() <= cb1.internal_capacity());
|
||||
BOOST_TEST(cb2.capacity().min_capacity() <= cb2.internal_capacity());
|
||||
BOOST_TEST(cb3.capacity().min_capacity() <= cb3.internal_capacity());
|
||||
|
||||
cb2.erase(cb2.begin() + 2, cb2.end());
|
||||
|
||||
BOOST_CHECK(cb2.size() == 2);
|
||||
BOOST_CHECK(cb2.capacity().min_capacity() <= cb2.internal_capacity());
|
||||
BOOST_TEST(cb2.size() == 2);
|
||||
BOOST_TEST(cb2.capacity().min_capacity() <= cb2.internal_capacity());
|
||||
|
||||
cb2.clear();
|
||||
cb3.clear();
|
||||
|
||||
BOOST_CHECK(cb2.empty());
|
||||
BOOST_CHECK(cb3.empty());
|
||||
BOOST_CHECK(cb2.capacity().min_capacity() <= cb2.internal_capacity());
|
||||
BOOST_CHECK(cb3.capacity().min_capacity() <= cb3.internal_capacity());
|
||||
BOOST_TEST(cb2.empty());
|
||||
BOOST_TEST(cb3.empty());
|
||||
BOOST_TEST(cb2.capacity().min_capacity() <= cb2.internal_capacity());
|
||||
BOOST_TEST(cb3.capacity().min_capacity() <= cb3.internal_capacity());
|
||||
}
|
||||
|
||||
void capacity_control_test() {
|
||||
@@ -65,33 +65,33 @@ void capacity_control_test() {
|
||||
circular_buffer_space_optimized<int>::capacity_type(20, 5);
|
||||
circular_buffer_space_optimized<int>::capacity_type c3 = c2;
|
||||
|
||||
BOOST_CHECK(c1.capacity() == 10);
|
||||
BOOST_CHECK(c1.min_capacity() == 0);
|
||||
BOOST_CHECK(c2.capacity() == 20);
|
||||
BOOST_CHECK(c2.min_capacity() == 5);
|
||||
BOOST_CHECK(c3.capacity() == 20);
|
||||
BOOST_CHECK(c3.min_capacity() == 5);
|
||||
BOOST_TEST(c1.capacity() == 10);
|
||||
BOOST_TEST(c1.min_capacity() == 0);
|
||||
BOOST_TEST(c2.capacity() == 20);
|
||||
BOOST_TEST(c2.min_capacity() == 5);
|
||||
BOOST_TEST(c3.capacity() == 20);
|
||||
BOOST_TEST(c3.min_capacity() == 5);
|
||||
|
||||
c1 = c2;
|
||||
|
||||
BOOST_CHECK(c1.capacity() == 20);
|
||||
BOOST_CHECK(c1.min_capacity() == 5);
|
||||
BOOST_TEST(c1.capacity() == 20);
|
||||
BOOST_TEST(c1.min_capacity() == 5);
|
||||
}
|
||||
|
||||
void specific_constructors_test() {
|
||||
|
||||
cb_space_optimized cb1;
|
||||
BOOST_CHECK(cb1.capacity() == 0);
|
||||
BOOST_CHECK(cb1.capacity().min_capacity() == 0);
|
||||
BOOST_CHECK(cb1.internal_capacity() == 0);
|
||||
BOOST_CHECK(cb1.size() == 0);
|
||||
BOOST_TEST(cb1.capacity() == 0);
|
||||
BOOST_TEST(cb1.capacity().min_capacity() == 0);
|
||||
BOOST_TEST(cb1.internal_capacity() == 0);
|
||||
BOOST_TEST(cb1.size() == 0);
|
||||
|
||||
cb1.push_back(1);
|
||||
cb1.push_back(2);
|
||||
cb1.push_back(3);
|
||||
|
||||
BOOST_CHECK(cb1.size() == 0);
|
||||
BOOST_CHECK(cb1.capacity() == 0);
|
||||
BOOST_TEST(cb1.size() == 0);
|
||||
BOOST_TEST(cb1.capacity() == 0);
|
||||
|
||||
vector<int> v;
|
||||
v.push_back(1);
|
||||
@@ -100,9 +100,9 @@ void specific_constructors_test() {
|
||||
|
||||
cb_space_optimized cb2(v.begin(), v.end());
|
||||
|
||||
BOOST_CHECK(cb2.capacity() == 3);
|
||||
BOOST_CHECK(cb2.capacity().min_capacity() == 0);
|
||||
BOOST_CHECK(cb2.size() == 3);
|
||||
BOOST_TEST(cb2.capacity() == 3);
|
||||
BOOST_TEST(cb2.capacity().min_capacity() == 0);
|
||||
BOOST_TEST(cb2.size() == 3);
|
||||
}
|
||||
|
||||
void shrink_to_fit_test() {
|
||||
@@ -112,15 +112,15 @@ void shrink_to_fit_test() {
|
||||
cb.push_back(2);
|
||||
cb.push_back(3);
|
||||
|
||||
BOOST_CHECK(cb.size() == 3);
|
||||
BOOST_CHECK(cb.capacity() == 1000);
|
||||
BOOST_TEST(cb.size() == 3);
|
||||
BOOST_TEST(cb.capacity() == 1000);
|
||||
|
||||
size_t internal_capacity = cb.internal_capacity();
|
||||
cb_space_optimized(cb).swap(cb);
|
||||
|
||||
BOOST_CHECK(cb.size() == 3);
|
||||
BOOST_CHECK(cb.capacity() == 1000);
|
||||
BOOST_CHECK(internal_capacity >= cb.internal_capacity());
|
||||
BOOST_TEST(cb.size() == 3);
|
||||
BOOST_TEST(cb.capacity() == 1000);
|
||||
BOOST_TEST(internal_capacity >= cb.internal_capacity());
|
||||
}
|
||||
|
||||
void iterator_invalidation_test() {
|
||||
@@ -136,33 +136,33 @@ void iterator_invalidation_test() {
|
||||
cb_space_optimized::iterator it3 = cb1.begin() + 6;
|
||||
|
||||
cb1.set_capacity(10);
|
||||
BOOST_CHECK(it1.is_valid(&cb1));
|
||||
BOOST_CHECK(!it2.is_valid(&cb1));
|
||||
BOOST_CHECK(!it3.is_valid(&cb1));
|
||||
BOOST_TEST(it1.is_valid(&cb1));
|
||||
BOOST_TEST(!it2.is_valid(&cb1));
|
||||
BOOST_TEST(!it3.is_valid(&cb1));
|
||||
|
||||
it1 = cb1.end();
|
||||
it2 = cb1.begin();
|
||||
it3 = cb1.begin() + 6;
|
||||
cb1.rset_capacity(10);
|
||||
BOOST_CHECK(it1.is_valid(&cb1));
|
||||
BOOST_CHECK(!it2.is_valid(&cb1));
|
||||
BOOST_CHECK(!it3.is_valid(&cb1));
|
||||
BOOST_TEST(it1.is_valid(&cb1));
|
||||
BOOST_TEST(!it2.is_valid(&cb1));
|
||||
BOOST_TEST(!it3.is_valid(&cb1));
|
||||
|
||||
it1 = cb1.end();
|
||||
it2 = cb1.begin();
|
||||
it3 = cb1.begin() + 6;
|
||||
cb1.resize(10);
|
||||
BOOST_CHECK(it1.is_valid(&cb1));
|
||||
BOOST_CHECK(!it2.is_valid(&cb1));
|
||||
BOOST_CHECK(!it3.is_valid(&cb1));
|
||||
BOOST_TEST(it1.is_valid(&cb1));
|
||||
BOOST_TEST(!it2.is_valid(&cb1));
|
||||
BOOST_TEST(!it3.is_valid(&cb1));
|
||||
|
||||
it1 = cb1.end();
|
||||
it2 = cb1.begin();
|
||||
it3 = cb1.begin() + 6;
|
||||
cb1.rresize(10);
|
||||
BOOST_CHECK(it1.is_valid(&cb1));
|
||||
BOOST_CHECK(!it2.is_valid(&cb1));
|
||||
BOOST_CHECK(!it3.is_valid(&cb1));
|
||||
BOOST_TEST(it1.is_valid(&cb1));
|
||||
BOOST_TEST(!it2.is_valid(&cb1));
|
||||
BOOST_TEST(!it3.is_valid(&cb1));
|
||||
|
||||
{
|
||||
cb_space_optimized cb2(10, 1);
|
||||
@@ -173,24 +173,21 @@ void iterator_invalidation_test() {
|
||||
it2 = cb2.begin();
|
||||
it3 = cb2.begin() + 6;
|
||||
}
|
||||
BOOST_CHECK(!it1.is_valid(&cb1));
|
||||
BOOST_CHECK(!it2.is_valid(&cb1));
|
||||
BOOST_CHECK(!it3.is_valid(&cb1));
|
||||
BOOST_TEST(!it1.is_valid(&cb1));
|
||||
BOOST_TEST(!it2.is_valid(&cb1));
|
||||
BOOST_TEST(!it3.is_valid(&cb1));
|
||||
|
||||
#endif // #if BOOST_CB_ENABLE_DEBUG
|
||||
}
|
||||
|
||||
// test main
|
||||
test_suite* init_unit_test_suite(int /*argc*/, char* /*argv*/[]) {
|
||||
|
||||
test_suite* tests = BOOST_TEST_SUITE("Unit tests for the circular_buffer_space_optimized.");
|
||||
add_common_tests(tests);
|
||||
|
||||
tests->add(BOOST_TEST_CASE(&min_capacity_test));
|
||||
tests->add(BOOST_TEST_CASE(&capacity_control_test));
|
||||
tests->add(BOOST_TEST_CASE(&specific_constructors_test));
|
||||
tests->add(BOOST_TEST_CASE(&shrink_to_fit_test));
|
||||
tests->add(BOOST_TEST_CASE(&iterator_invalidation_test));
|
||||
|
||||
return tests;
|
||||
int main()
|
||||
{
|
||||
run_common_tests();
|
||||
min_capacity_test();
|
||||
capacity_control_test();
|
||||
specific_constructors_test();
|
||||
shrink_to_fit_test();
|
||||
iterator_invalidation_test();
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
#define BOOST_CB_TEST
|
||||
|
||||
#include <boost/circular_buffer.hpp>
|
||||
#include <boost/test/included/unit_test.hpp>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
#include <iterator>
|
||||
#include <numeric>
|
||||
#include <vector>
|
||||
@@ -139,7 +139,6 @@ inline ptrdiff_t* distance_type(const MyInputIterator&) { return 0; }
|
||||
|
||||
#endif // #if defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) && !defined(BOOST_MSVC_STD_ITERATOR)
|
||||
|
||||
using boost::unit_test::test_suite;
|
||||
using namespace boost;
|
||||
using namespace std;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user