mirror of
https://github.com/boostorg/circular_buffer.git
synced 2026-02-03 21:12:21 +00:00
Compare commits
4 Commits
20131209-d
...
boost-1.55
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
aca434d344 | ||
|
|
90711fb1fe | ||
|
|
6eb5fd4a3d | ||
|
|
6998f28fda |
@@ -11,13 +11,12 @@
|
||||
#if !defined(BOOST_CIRCULAR_BUFFER_HPP)
|
||||
#define BOOST_CIRCULAR_BUFFER_HPP
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#if defined(_MSC_VER) && _MSC_VER >= 1200
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include <boost/circular_buffer_fwd.hpp>
|
||||
#include <boost/detail/workaround.hpp>
|
||||
#include <boost/static_assert.hpp>
|
||||
|
||||
// BOOST_CB_ENABLE_DEBUG: Debug support control.
|
||||
#if defined(NDEBUG) || defined(BOOST_CB_DISABLE_DEBUG)
|
||||
@@ -34,20 +33,29 @@
|
||||
#define BOOST_CB_ASSERT(Expr) ((void)0)
|
||||
#endif
|
||||
|
||||
// BOOST_CB_STATIC_ASSERT: Compile time assertion.
|
||||
#if BOOST_WORKAROUND(BOOST_MSVC, < 1300)
|
||||
#define BOOST_CB_STATIC_ASSERT(Expr) ((void)0)
|
||||
#else
|
||||
#include <boost/static_assert.hpp>
|
||||
#define BOOST_CB_STATIC_ASSERT(Expr) BOOST_STATIC_ASSERT(Expr)
|
||||
#endif
|
||||
|
||||
// BOOST_CB_IS_CONVERTIBLE: Check if Iterator::value_type is convertible to Type.
|
||||
#if BOOST_WORKAROUND(__BORLANDC__, <= 0x0550) || BOOST_WORKAROUND(__MWERKS__, <= 0x2407)
|
||||
#if BOOST_WORKAROUND(__BORLANDC__, <= 0x0550) || BOOST_WORKAROUND(__MWERKS__, <= 0x2407) || \
|
||||
BOOST_WORKAROUND(BOOST_MSVC, < 1300)
|
||||
#define BOOST_CB_IS_CONVERTIBLE(Iterator, Type) ((void)0)
|
||||
#else
|
||||
#include <boost/detail/iterator.hpp>
|
||||
#include <boost/type_traits/is_convertible.hpp>
|
||||
#define BOOST_CB_IS_CONVERTIBLE(Iterator, Type) \
|
||||
BOOST_STATIC_ASSERT((is_convertible<typename detail::iterator_traits<Iterator>::value_type, Type>::value))
|
||||
BOOST_CB_STATIC_ASSERT((is_convertible<typename detail::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.
|
||||
#if defined(BOOST_NO_TEMPLATED_ITERATOR_CONSTRUCTORS)
|
||||
#define BOOST_CB_ASSERT_TEMPLATED_ITERATOR_CONSTRUCTORS BOOST_STATIC_ASSERT(false);
|
||||
#define BOOST_CB_ASSERT_TEMPLATED_ITERATOR_CONSTRUCTORS BOOST_CB_STATIC_ASSERT(false);
|
||||
#else
|
||||
#define BOOST_CB_ASSERT_TEMPLATED_ITERATOR_CONSTRUCTORS ((void)0);
|
||||
#endif
|
||||
@@ -59,6 +67,7 @@
|
||||
|
||||
#undef BOOST_CB_ASSERT_TEMPLATED_ITERATOR_CONSTRUCTORS
|
||||
#undef BOOST_CB_IS_CONVERTIBLE
|
||||
#undef BOOST_CB_STATIC_ASSERT
|
||||
#undef BOOST_CB_ASSERT
|
||||
#undef BOOST_CB_ENABLE_DEBUG
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
#if !defined(BOOST_CIRCULAR_BUFFER_BASE_HPP)
|
||||
#define BOOST_CIRCULAR_BUFFER_BASE_HPP
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#if defined(_MSC_VER) && _MSC_VER >= 1200
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
@@ -34,10 +34,21 @@
|
||||
#include <utility>
|
||||
#include <deque>
|
||||
#include <stdexcept>
|
||||
#if BOOST_CB_ENABLE_DEBUG
|
||||
#include <cstring>
|
||||
#endif
|
||||
#if BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3205))
|
||||
#include <stddef.h>
|
||||
#endif
|
||||
|
||||
#if defined(BOOST_NO_STDC_NAMESPACE)
|
||||
namespace std {
|
||||
using ::memset;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
namespace boost {
|
||||
|
||||
/*!
|
||||
@@ -679,7 +690,7 @@ public:
|
||||
break;
|
||||
}
|
||||
if (is_uninitialized(dest)) {
|
||||
cb_details::do_construct<value_type>(dest, this_type::move_if_noexcept(*src), m_alloc);
|
||||
::new (dest) value_type(this_type::move_if_noexcept(*src));
|
||||
++constructed;
|
||||
} else {
|
||||
value_type tmp = this_type::move_if_noexcept(*src);
|
||||
@@ -891,7 +902,7 @@ public:
|
||||
iterator b = begin();
|
||||
BOOST_TRY {
|
||||
reset(buff,
|
||||
cb_details::uninitialized_move_if_noexcept(b, b + (std::min)(new_capacity, size()), buff, m_alloc),
|
||||
cb_details::uninitialized_move_if_noexcept<value_type>(b, b + (std::min)(new_capacity, size()), buff),
|
||||
new_capacity);
|
||||
} BOOST_CATCH(...) {
|
||||
deallocate(buff, new_capacity);
|
||||
@@ -966,8 +977,8 @@ public:
|
||||
pointer buff = allocate(new_capacity);
|
||||
iterator e = end();
|
||||
BOOST_TRY {
|
||||
reset(buff, cb_details::uninitialized_move_if_noexcept(e - (std::min)(new_capacity, size()),
|
||||
e, buff, m_alloc), new_capacity);
|
||||
reset(buff, cb_details::uninitialized_move_if_noexcept<value_type>(e - (std::min)(new_capacity, size()),
|
||||
e, buff), new_capacity);
|
||||
} BOOST_CATCH(...) {
|
||||
deallocate(buff, new_capacity);
|
||||
BOOST_RETHROW
|
||||
@@ -1114,7 +1125,7 @@ public:
|
||||
initialize_buffer(cb.capacity());
|
||||
m_first = m_buff;
|
||||
BOOST_TRY {
|
||||
m_last = cb_details::uninitialized_copy(cb.begin(), cb.end(), m_buff, m_alloc);
|
||||
m_last = cb_details::uninitialized_copy<value_type>(cb.begin(), cb.end(), m_buff);
|
||||
} BOOST_CATCH(...) {
|
||||
deallocate(m_buff, cb.capacity());
|
||||
BOOST_RETHROW
|
||||
@@ -1139,6 +1150,25 @@ public:
|
||||
}
|
||||
#endif // BOOST_NO_CXX11_RVALUE_REFERENCES
|
||||
|
||||
|
||||
#if BOOST_WORKAROUND(BOOST_MSVC, < 1300)
|
||||
|
||||
/*! \cond */
|
||||
template <class InputIterator>
|
||||
circular_buffer(InputIterator first, InputIterator last)
|
||||
: m_alloc(allocator_type()) {
|
||||
initialize(first, last, is_integral<InputIterator>());
|
||||
}
|
||||
|
||||
template <class InputIterator>
|
||||
circular_buffer(capacity_type capacity, InputIterator first, InputIterator last)
|
||||
: m_alloc(allocator_type()) {
|
||||
initialize(capacity, first, last, is_integral<InputIterator>());
|
||||
}
|
||||
/*! \endcond */
|
||||
|
||||
#else
|
||||
|
||||
//! Create a full <code>circular_buffer</code> filled with a copy of the range.
|
||||
/*!
|
||||
\pre Valid range <code>[first, last)</code>.<br>
|
||||
@@ -1191,6 +1221,8 @@ public:
|
||||
initialize(buffer_capacity, first, last, is_integral<InputIterator>());
|
||||
}
|
||||
|
||||
#endif // #if BOOST_WORKAROUND(BOOST_MSVC, < 1300)
|
||||
|
||||
//! The destructor.
|
||||
/*!
|
||||
Destroys the <code>circular_buffer</code>.
|
||||
@@ -1238,7 +1270,7 @@ public:
|
||||
return *this;
|
||||
pointer buff = allocate(cb.capacity());
|
||||
BOOST_TRY {
|
||||
reset(buff, cb_details::uninitialized_copy(cb.begin(), cb.end(), buff, m_alloc), cb.capacity());
|
||||
reset(buff, cb_details::uninitialized_copy<value_type>(cb.begin(), cb.end(), buff), cb.capacity());
|
||||
} BOOST_CATCH(...) {
|
||||
deallocate(buff, cb.capacity());
|
||||
BOOST_RETHROW
|
||||
@@ -1435,7 +1467,7 @@ private:
|
||||
increment(m_last);
|
||||
m_first = m_last;
|
||||
} else {
|
||||
cb_details::do_construct<value_type>(m_last, static_cast<ValT>(item), m_alloc);
|
||||
::new (m_last) value_type(static_cast<ValT>(item));
|
||||
increment(m_last);
|
||||
++m_size;
|
||||
}
|
||||
@@ -1452,7 +1484,7 @@ private:
|
||||
m_last = m_first;
|
||||
} else {
|
||||
decrement(m_first);
|
||||
cb_details::do_construct<value_type>(m_first, static_cast<ValT>(item), m_alloc);
|
||||
::new (m_first) value_type(static_cast<ValT>(item));
|
||||
++m_size;
|
||||
}
|
||||
} BOOST_CATCH(...) {
|
||||
@@ -2386,7 +2418,7 @@ private:
|
||||
throw_exception(std::length_error("circular_buffer"));
|
||||
#if BOOST_CB_ENABLE_DEBUG
|
||||
pointer p = (n == 0) ? 0 : m_alloc.allocate(n, 0);
|
||||
cb_details::do_fill_uninitialized_memory(p, sizeof(value_type) * n);
|
||||
std::memset(p, cb_details::UNINITIALIZED, sizeof(value_type) * n);
|
||||
return p;
|
||||
#else
|
||||
return (n == 0) ? 0 : m_alloc.allocate(n, 0);
|
||||
@@ -2427,7 +2459,7 @@ private:
|
||||
*/
|
||||
void construct_or_replace(bool construct, pointer pos, param_value_type item) {
|
||||
if (construct)
|
||||
cb_details::do_construct<value_type>(pos, item, m_alloc);
|
||||
::new (pos) value_type(item);
|
||||
else
|
||||
replace(pos, item);
|
||||
}
|
||||
@@ -2439,7 +2471,7 @@ private:
|
||||
*/
|
||||
void construct_or_replace(bool construct, pointer pos, rvalue_type item) {
|
||||
if (construct)
|
||||
cb_details::do_construct<value_type>(pos, boost::move(item), m_alloc);
|
||||
::new (pos) value_type(boost::move(item));
|
||||
else
|
||||
replace(pos, boost::move(item));
|
||||
}
|
||||
@@ -2449,7 +2481,7 @@ private:
|
||||
m_alloc.destroy(p);
|
||||
#if BOOST_CB_ENABLE_DEBUG
|
||||
invalidate_iterators(iterator(this, p));
|
||||
cb_details::do_fill_uninitialized_memory(p, sizeof(value_type));
|
||||
std::memset(p, cb_details::UNINITIALIZED, sizeof(value_type));
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -2522,9 +2554,9 @@ private:
|
||||
void initialize(Iterator first, Iterator last, const false_type&) {
|
||||
BOOST_CB_IS_CONVERTIBLE(Iterator, value_type); // check for invalid iterator type
|
||||
#if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x581))
|
||||
initialize(first, last, iterator_category<Iterator>::type());
|
||||
initialize(first, last, BOOST_ITERATOR_CATEGORY<Iterator>::type());
|
||||
#else
|
||||
initialize(first, last, BOOST_DEDUCED_TYPENAME iterator_category<Iterator>::type());
|
||||
initialize(first, last, BOOST_DEDUCED_TYPENAME BOOST_ITERATOR_CATEGORY<Iterator>::type());
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -2561,9 +2593,9 @@ private:
|
||||
void initialize(capacity_type buffer_capacity, Iterator first, Iterator last, const false_type&) {
|
||||
BOOST_CB_IS_CONVERTIBLE(Iterator, value_type); // check for invalid iterator type
|
||||
#if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x581))
|
||||
initialize(buffer_capacity, first, last, iterator_category<Iterator>::type());
|
||||
initialize(buffer_capacity, first, last, BOOST_ITERATOR_CATEGORY<Iterator>::type());
|
||||
#else
|
||||
initialize(buffer_capacity, first, last, BOOST_DEDUCED_TYPENAME iterator_category<Iterator>::type());
|
||||
initialize(buffer_capacity, first, last, BOOST_DEDUCED_TYPENAME BOOST_ITERATOR_CATEGORY<Iterator>::type());
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -2579,7 +2611,7 @@ private:
|
||||
if (buffer_capacity == 0)
|
||||
return;
|
||||
while (first != last && !full()) {
|
||||
cb_details::do_construct<value_type>(m_last, *first++, m_alloc);
|
||||
::new (m_last) value_type(*first++);
|
||||
increment(m_last);
|
||||
++m_size;
|
||||
}
|
||||
@@ -2615,7 +2647,7 @@ private:
|
||||
m_size = distance;
|
||||
}
|
||||
BOOST_TRY {
|
||||
m_last = cb_details::uninitialized_copy(first, last, m_buff, m_alloc);
|
||||
m_last = cb_details::uninitialized_copy<value_type>(first, last, m_buff);
|
||||
} BOOST_CATCH(...) {
|
||||
deallocate(m_buff, buffer_capacity);
|
||||
BOOST_RETHROW
|
||||
@@ -2655,9 +2687,9 @@ private:
|
||||
void assign(Iterator first, Iterator last, const false_type&) {
|
||||
BOOST_CB_IS_CONVERTIBLE(Iterator, value_type); // check for invalid iterator type
|
||||
#if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x581))
|
||||
assign(first, last, iterator_category<Iterator>::type());
|
||||
assign(first, last, BOOST_ITERATOR_CATEGORY<Iterator>::type());
|
||||
#else
|
||||
assign(first, last, BOOST_DEDUCED_TYPENAME iterator_category<Iterator>::type());
|
||||
assign(first, last, BOOST_DEDUCED_TYPENAME BOOST_ITERATOR_CATEGORY<Iterator>::type());
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -2669,8 +2701,8 @@ private:
|
||||
std::deque<value_type, allocator_type> tmp(first, last, m_alloc);
|
||||
size_type distance = tmp.size();
|
||||
assign_n(distance, distance,
|
||||
cb_details::make_assign_range
|
||||
(boost::make_move_iterator(tmp.begin()), boost::make_move_iterator(tmp.end()), m_alloc));
|
||||
cb_details::make_assign_range<value_type>
|
||||
(boost::make_move_iterator(tmp.begin()), boost::make_move_iterator(tmp.end())));
|
||||
}
|
||||
|
||||
//! Specialized assign method.
|
||||
@@ -2678,7 +2710,7 @@ private:
|
||||
void assign(ForwardIterator first, ForwardIterator last, const std::forward_iterator_tag&) {
|
||||
BOOST_CB_ASSERT(std::distance(first, last) >= 0); // check for wrong range
|
||||
size_type distance = std::distance(first, last);
|
||||
assign_n(distance, distance, cb_details::make_assign_range(first, last, m_alloc));
|
||||
assign_n(distance, distance, cb_details::make_assign_range<value_type>(first, last));
|
||||
}
|
||||
|
||||
//! Specialized assign method.
|
||||
@@ -2692,9 +2724,9 @@ private:
|
||||
void assign(capacity_type new_capacity, Iterator first, Iterator last, const false_type&) {
|
||||
BOOST_CB_IS_CONVERTIBLE(Iterator, value_type); // check for invalid iterator type
|
||||
#if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x581))
|
||||
assign(new_capacity, first, last, iterator_category<Iterator>::type());
|
||||
assign(new_capacity, first, last, BOOST_ITERATOR_CATEGORY<Iterator>::type());
|
||||
#else
|
||||
assign(new_capacity, first, last, BOOST_DEDUCED_TYPENAME iterator_category<Iterator>::type());
|
||||
assign(new_capacity, first, last, BOOST_DEDUCED_TYPENAME BOOST_ITERATOR_CATEGORY<Iterator>::type());
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -2705,7 +2737,12 @@ private:
|
||||
clear();
|
||||
insert(begin(), first, last);
|
||||
} else {
|
||||
#if BOOST_WORKAROUND(BOOST_MSVC, < 1300)
|
||||
circular_buffer<value_type, allocator_type> tmp(new_capacity, m_alloc);
|
||||
tmp.insert(begin(), first, last);
|
||||
#else
|
||||
circular_buffer<value_type, allocator_type> tmp(new_capacity, first, last, m_alloc);
|
||||
#endif
|
||||
tmp.swap(*this);
|
||||
}
|
||||
}
|
||||
@@ -2721,7 +2758,7 @@ private:
|
||||
distance = new_capacity;
|
||||
}
|
||||
assign_n(new_capacity, distance,
|
||||
cb_details::make_assign_range(first, last, m_alloc));
|
||||
cb_details::make_assign_range<value_type>(first, last));
|
||||
}
|
||||
|
||||
//! Helper assign method.
|
||||
@@ -2801,9 +2838,9 @@ private:
|
||||
void insert(const iterator& pos, Iterator first, Iterator last, const false_type&) {
|
||||
BOOST_CB_IS_CONVERTIBLE(Iterator, value_type); // check for invalid iterator type
|
||||
#if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x581))
|
||||
insert(pos, first, last, iterator_category<Iterator>::type());
|
||||
insert(pos, first, last, BOOST_ITERATOR_CATEGORY<Iterator>::type());
|
||||
#else
|
||||
insert(pos, first, last, BOOST_DEDUCED_TYPENAME iterator_category<Iterator>::type());
|
||||
insert(pos, first, last, BOOST_DEDUCED_TYPENAME BOOST_ITERATOR_CATEGORY<Iterator>::type());
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -2844,7 +2881,7 @@ private:
|
||||
pointer p = m_last;
|
||||
BOOST_TRY {
|
||||
for (; ii < construct; ++ii, increment(p))
|
||||
cb_details::do_construct<value_type>(p, *wrapper(), m_alloc);
|
||||
::new (p) value_type(*wrapper());
|
||||
for (;ii < n; ++ii, increment(p))
|
||||
replace(p, *wrapper());
|
||||
} BOOST_CATCH(...) {
|
||||
@@ -2892,9 +2929,9 @@ private:
|
||||
void rinsert(const iterator& pos, Iterator first, Iterator last, const false_type&) {
|
||||
BOOST_CB_IS_CONVERTIBLE(Iterator, value_type); // check for invalid iterator type
|
||||
#if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x581))
|
||||
rinsert(pos, first, last, iterator_category<Iterator>::type());
|
||||
rinsert(pos, first, last, BOOST_ITERATOR_CATEGORY<Iterator>::type());
|
||||
#else
|
||||
rinsert(pos, first, last, BOOST_DEDUCED_TYPENAME iterator_category<Iterator>::type());
|
||||
rinsert(pos, first, last, BOOST_DEDUCED_TYPENAME BOOST_ITERATOR_CATEGORY<Iterator>::type());
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -2938,7 +2975,7 @@ private:
|
||||
for (;ii > construct; --ii, increment(p))
|
||||
replace(p, *wrapper());
|
||||
for (; ii > 0; --ii, increment(p))
|
||||
cb_details::do_construct<value_type>(p, *wrapper(), m_alloc);
|
||||
::new (p) value_type(*wrapper());
|
||||
} BOOST_CATCH(...) {
|
||||
size_type constructed = ii < construct ? construct - ii : 0;
|
||||
m_last = add(m_last, constructed);
|
||||
|
||||
@@ -9,20 +9,10 @@
|
||||
#if !defined(BOOST_CIRCULAR_BUFFER_DEBUG_HPP)
|
||||
#define BOOST_CIRCULAR_BUFFER_DEBUG_HPP
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#if defined(_MSC_VER) && _MSC_VER >= 1200
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#if BOOST_CB_ENABLE_DEBUG
|
||||
#include <cstring>
|
||||
|
||||
#if defined(BOOST_NO_STDC_NAMESPACE)
|
||||
namespace std {
|
||||
using ::memset;
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // BOOST_CB_ENABLE_DEBUG
|
||||
namespace boost {
|
||||
|
||||
namespace cb_details {
|
||||
@@ -32,17 +22,6 @@ namespace cb_details {
|
||||
// The value the uninitialized memory is filled with.
|
||||
const int UNINITIALIZED = 0xcc;
|
||||
|
||||
template <class T>
|
||||
inline void do_fill_uninitialized_memory(T* data, std::size_t size_in_bytes) BOOST_NOEXCEPT {
|
||||
std::memset(static_cast<void*>(data), UNINITIALIZED, size_in_bytes);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline void do_fill_uninitialized_memory(T& /*data*/, std::size_t /*size_in_bytes*/) BOOST_NOEXCEPT {
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
|
||||
class debug_iterator_registry;
|
||||
|
||||
/*!
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
#if !defined(BOOST_CIRCULAR_BUFFER_DETAILS_HPP)
|
||||
#define BOOST_CIRCULAR_BUFFER_DETAILS_HPP
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#if defined(_MSC_VER) && _MSC_VER >= 1200
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
@@ -38,42 +38,11 @@ template<class ForwardIterator, class Diff, class T, class Alloc>
|
||||
void uninitialized_fill_n_with_alloc(
|
||||
ForwardIterator first, Diff n, const T& item, Alloc& alloc);
|
||||
|
||||
template<class InputIterator, class ForwardIterator, class Alloc>
|
||||
ForwardIterator uninitialized_copy(InputIterator first, InputIterator last, ForwardIterator dest, Alloc& a);
|
||||
template<class ValueType, class InputIterator, class ForwardIterator>
|
||||
ForwardIterator uninitialized_copy(InputIterator first, InputIterator last, ForwardIterator dest);
|
||||
|
||||
template<class InputIterator, class ForwardIterator, class Alloc>
|
||||
ForwardIterator uninitialized_move_if_noexcept(InputIterator first, InputIterator last, ForwardIterator dest, Alloc& a);
|
||||
|
||||
|
||||
//! Those `do_construct` methods are required because in C++03 default allocators
|
||||
//! have `construct` method that accepts second parameter in as a const reference;
|
||||
//! while move-only types emulated by Boost.Move require constructor that accepts
|
||||
//! a non-const reference.
|
||||
//!
|
||||
//! So when we need to call `construct` and pointer to value_type is provided, we
|
||||
//! assume that it is safe to call placement new instead of Alloc::construct.
|
||||
//! Otherwise we are asume that user has made his own allocator or uses allocator
|
||||
//! from other libraries. In that case it's users ability to provide Alloc::construct
|
||||
//! with non-const reference parameter or just do not use move-only types.
|
||||
template <class ValueType, class Alloc>
|
||||
inline void do_construct(ValueType* p, BOOST_RV_REF(ValueType) item, Alloc&) {
|
||||
::new (p) ValueType(boost::move(item));
|
||||
}
|
||||
|
||||
template <class ValueType, class Alloc>
|
||||
inline void do_construct(ValueType* p, const ValueType& item, Alloc&) {
|
||||
::new (p) ValueType(item);
|
||||
}
|
||||
|
||||
template <class ValueType, class Alloc, class PointerT>
|
||||
inline void do_construct(PointerT& p, BOOST_RV_REF(ValueType) item, Alloc& a) {
|
||||
a.construct(p, boost::move(item));
|
||||
}
|
||||
|
||||
template <class ValueType, class Alloc, class PointerT>
|
||||
inline void do_construct(PointerT& p, const ValueType& item, Alloc& a) {
|
||||
a.construct(p, item);
|
||||
}
|
||||
template<class ValueType, class InputIterator, class ForwardIterator>
|
||||
ForwardIterator uninitialized_move_if_noexcept(InputIterator first, InputIterator last, ForwardIterator dest);
|
||||
|
||||
/*!
|
||||
\struct const_traits
|
||||
@@ -158,24 +127,23 @@ private:
|
||||
\struct assign_range
|
||||
\brief Helper functor for assigning range of items.
|
||||
*/
|
||||
template <class Iterator, class Alloc>
|
||||
template <class ValueType, class Iterator>
|
||||
struct assign_range {
|
||||
Iterator m_first;
|
||||
Iterator m_last;
|
||||
Alloc& m_alloc;
|
||||
|
||||
assign_range(const Iterator& first, const Iterator& last, Alloc& alloc)
|
||||
: m_first(first), m_last(last), m_alloc(alloc) {}
|
||||
assign_range(const Iterator& first, const Iterator& last) BOOST_NOEXCEPT
|
||||
: m_first(first), m_last(last) {}
|
||||
|
||||
template <class Pointer>
|
||||
void operator () (Pointer p) const {
|
||||
boost::cb_details::uninitialized_copy(m_first, m_last, p, m_alloc);
|
||||
boost::cb_details::uninitialized_copy<ValueType>(m_first, m_last, p);
|
||||
}
|
||||
};
|
||||
|
||||
template <class Iterator, class Alloc>
|
||||
inline assign_range<Iterator, Alloc> make_assign_range(const Iterator& first, const Iterator& last, Alloc& a) {
|
||||
return assign_range<Iterator, Alloc>(first, last, a);
|
||||
template <class ValueType, class Iterator>
|
||||
inline assign_range<ValueType, Iterator> make_assign_range(const Iterator& first, const Iterator& last) {
|
||||
return assign_range<ValueType, Iterator>(first, last);
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -455,47 +423,70 @@ operator + (typename Traits::difference_type n, const iterator<Buff, Traits>& it
|
||||
return it + n;
|
||||
}
|
||||
|
||||
#if defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) && !defined(BOOST_MSVC_STD_ITERATOR)
|
||||
|
||||
//! Iterator category.
|
||||
template <class Buff, class Traits>
|
||||
inline std::random_access_iterator_tag iterator_category(const iterator<Buff, Traits>&) {
|
||||
return std::random_access_iterator_tag();
|
||||
}
|
||||
|
||||
//! The type of the elements stored in the circular buffer.
|
||||
template <class Buff, class Traits>
|
||||
inline typename Traits::value_type* value_type(const iterator<Buff, Traits>&) { return 0; }
|
||||
|
||||
//! Distance type.
|
||||
template <class Buff, class Traits>
|
||||
inline typename Traits::difference_type* distance_type(const iterator<Buff, Traits>&) { return 0; }
|
||||
|
||||
#endif // #if defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) && !defined(BOOST_MSVC_STD_ITERATOR)
|
||||
|
||||
/*!
|
||||
\fn ForwardIterator uninitialized_copy(InputIterator first, InputIterator last, ForwardIterator dest)
|
||||
\brief Equivalent of <code>std::uninitialized_copy</code> but with explicit specification of value type.
|
||||
*/
|
||||
template<class InputIterator, class ForwardIterator, class Alloc>
|
||||
inline ForwardIterator uninitialized_copy(InputIterator first, InputIterator last, ForwardIterator dest, Alloc& a) {
|
||||
template<class ValueType, class InputIterator, class ForwardIterator>
|
||||
inline ForwardIterator uninitialized_copy(InputIterator first, InputIterator last, ForwardIterator dest) {
|
||||
typedef ValueType value_type;
|
||||
|
||||
// We do not use allocator.construct and allocator.destroy
|
||||
// because C++03 requires to take parameter by const reference but
|
||||
// Boost.move requires nonconst reference
|
||||
ForwardIterator next = dest;
|
||||
BOOST_TRY {
|
||||
for (; first != last; ++first, ++dest)
|
||||
do_construct<typename Alloc::value_type>(dest, *first, a);
|
||||
::new (dest) value_type(*first);
|
||||
} BOOST_CATCH(...) {
|
||||
for (; next != dest; ++next)
|
||||
a.destroy(next);
|
||||
next->~value_type();
|
||||
BOOST_RETHROW
|
||||
}
|
||||
BOOST_CATCH_END
|
||||
return dest;
|
||||
}
|
||||
|
||||
template<class InputIterator, class ForwardIterator, class Alloc>
|
||||
ForwardIterator uninitialized_move_if_noexcept_impl(InputIterator first, InputIterator last, ForwardIterator dest, Alloc& a,
|
||||
template<class ValueType, class InputIterator, class ForwardIterator>
|
||||
ForwardIterator uninitialized_move_if_noexcept_impl(InputIterator first, InputIterator last, ForwardIterator dest,
|
||||
true_type) {
|
||||
for (; first != last; ++first, ++dest)
|
||||
do_construct<typename Alloc::value_type>(dest, boost::move(*first), a);
|
||||
::new (dest) ValueType(boost::move(*first));
|
||||
return dest;
|
||||
}
|
||||
|
||||
template<class InputIterator, class ForwardIterator, class Alloc>
|
||||
ForwardIterator uninitialized_move_if_noexcept_impl(InputIterator first, InputIterator last, ForwardIterator dest, Alloc& a,
|
||||
template<class ValueType, class InputIterator, class ForwardIterator>
|
||||
ForwardIterator uninitialized_move_if_noexcept_impl(InputIterator first, InputIterator last, ForwardIterator dest,
|
||||
false_type) {
|
||||
return uninitialized_copy(first, last, dest, a);
|
||||
return uninitialized_copy<ValueType>(first, last, dest);
|
||||
}
|
||||
|
||||
/*!
|
||||
\fn ForwardIterator uninitialized_move_if_noexcept(InputIterator first, InputIterator last, ForwardIterator dest)
|
||||
\brief Equivalent of <code>std::uninitialized_copy</code> but with explicit specification of value type and moves elements if they have noexcept move constructors.
|
||||
*/
|
||||
template<class InputIterator, class ForwardIterator, class Alloc>
|
||||
ForwardIterator uninitialized_move_if_noexcept(InputIterator first, InputIterator last, ForwardIterator dest, Alloc& a) {
|
||||
typedef typename boost::is_nothrow_move_constructible<typename Alloc::value_type>::type tag_t;
|
||||
return uninitialized_move_if_noexcept_impl(first, last, dest, a, tag_t());
|
||||
template<class ValueType, class InputIterator, class ForwardIterator>
|
||||
ForwardIterator uninitialized_move_if_noexcept(InputIterator first, InputIterator last, ForwardIterator dest) {
|
||||
typedef typename boost::is_nothrow_move_constructible<ValueType>::type tag_t;
|
||||
return uninitialized_move_if_noexcept_impl<ValueType>(first, last, dest, tag_t());
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -507,7 +498,7 @@ inline void uninitialized_fill_n_with_alloc(ForwardIterator first, Diff n, const
|
||||
ForwardIterator next = first;
|
||||
BOOST_TRY {
|
||||
for (; n > 0; ++first, --n)
|
||||
do_construct<typename Alloc::value_type>(first, item, alloc);
|
||||
alloc.construct(first, item);
|
||||
} BOOST_CATCH(...) {
|
||||
for (; next != first; ++next)
|
||||
alloc.destroy(next);
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
#if !defined(BOOST_CIRCULAR_BUFFER_SPACE_OPTIMIZED_HPP)
|
||||
#define BOOST_CIRCULAR_BUFFER_SPACE_OPTIMIZED_HPP
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#if defined(_MSC_VER) && _MSC_VER >= 1200
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
@@ -416,6 +416,31 @@ public:
|
||||
: circular_buffer<T, Alloc>(init_capacity(capacity_ctrl, n), n, item, alloc)
|
||||
, m_capacity_ctrl(capacity_ctrl) {}
|
||||
|
||||
#if BOOST_WORKAROUND(BOOST_MSVC, < 1300)
|
||||
|
||||
/*! \cond */
|
||||
circular_buffer_space_optimized(const circular_buffer_space_optimized<T, Alloc>& cb)
|
||||
: circular_buffer<T, Alloc>(cb.begin(), cb.end())
|
||||
, m_capacity_ctrl(cb.m_capacity_ctrl) {}
|
||||
|
||||
template <class InputIterator>
|
||||
circular_buffer_space_optimized(InputIterator first, InputIterator last)
|
||||
: circular_buffer<T, Alloc>(first, last)
|
||||
, m_capacity_ctrl(circular_buffer<T, Alloc>::capacity()) {}
|
||||
|
||||
template <class InputIterator>
|
||||
circular_buffer_space_optimized(capacity_type capacity_ctrl, InputIterator first, InputIterator last)
|
||||
: circular_buffer<T, Alloc>(
|
||||
init_capacity(capacity_ctrl, first, last, is_integral<InputIterator>()),
|
||||
first, last)
|
||||
, m_capacity_ctrl(capacity_ctrl) {
|
||||
reduce_capacity(
|
||||
is_same< BOOST_DEDUCED_TYPENAME BOOST_ITERATOR_CATEGORY<InputIterator>::type, std::input_iterator_tag >());
|
||||
}
|
||||
/*! \endcond */
|
||||
|
||||
#else
|
||||
|
||||
//! The copy constructor.
|
||||
/*!
|
||||
Creates a copy of the specified <code>circular_buffer_space_optimized</code>.
|
||||
@@ -509,9 +534,11 @@ public:
|
||||
first, last, alloc)
|
||||
, m_capacity_ctrl(capacity_ctrl) {
|
||||
reduce_capacity(
|
||||
is_same< BOOST_DEDUCED_TYPENAME iterator_category<InputIterator>::type, std::input_iterator_tag >());
|
||||
is_same< BOOST_DEDUCED_TYPENAME BOOST_ITERATOR_CATEGORY<InputIterator>::type, std::input_iterator_tag >());
|
||||
}
|
||||
|
||||
#endif // #if BOOST_WORKAROUND(BOOST_MSVC, < 1300)
|
||||
|
||||
#if defined(BOOST_CB_NEVER_DEFINED)
|
||||
// This section will never be compiled - the default destructor will be generated instead.
|
||||
// Declared only for documentation purpose.
|
||||
@@ -1605,10 +1632,10 @@ private:
|
||||
const false_type&) {
|
||||
BOOST_CB_IS_CONVERTIBLE(Iterator, value_type); // check for invalid iterator type
|
||||
#if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x581))
|
||||
return init_capacity(capacity_ctrl, first, last, iterator_category<Iterator>::type());
|
||||
return init_capacity(capacity_ctrl, first, last, BOOST_ITERATOR_CATEGORY<Iterator>::type());
|
||||
#else
|
||||
return init_capacity(
|
||||
capacity_ctrl, first, last, BOOST_DEDUCED_TYPENAME iterator_category<Iterator>::type());
|
||||
capacity_ctrl, first, last, BOOST_DEDUCED_TYPENAME BOOST_ITERATOR_CATEGORY<Iterator>::type());
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
#if !defined(BOOST_CIRCULAR_BUFFER_FWD_HPP)
|
||||
#define BOOST_CIRCULAR_BUFFER_FWD_HPP
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#if defined(_MSC_VER) && _MSC_VER >= 1200
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
|
||||
@@ -11,8 +11,7 @@
|
||||
#include <boost/type_traits/is_nothrow_move_assignable.hpp>
|
||||
#include <boost/type_traits/has_nothrow_constructor.hpp>
|
||||
|
||||
template <class Alloc>
|
||||
void generic_test(CB_CONTAINER<MyInteger, Alloc>& cb) {
|
||||
void generic_test(CB_CONTAINER<MyInteger>& cb) {
|
||||
|
||||
vector<int> v;
|
||||
v.push_back(11);
|
||||
@@ -150,88 +149,6 @@ void size_test() {
|
||||
generic_test(cb2);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
class my_allocator {
|
||||
typedef std::allocator<T> base_t;
|
||||
base_t base_;
|
||||
public:
|
||||
typedef T value_type;
|
||||
|
||||
|
||||
typedef value_type& reference;
|
||||
typedef const value_type& const_reference;
|
||||
typedef typename base_t::size_type size_type;
|
||||
typedef typename base_t::difference_type difference_type;
|
||||
|
||||
struct const_pointer;
|
||||
struct pointer {
|
||||
pointer(){}
|
||||
pointer(void* p) : hidden_ptr_((T*)p) {}
|
||||
difference_type operator-(const const_pointer& rhs) const { return hidden_ptr_ - rhs.hidden_ptr_; }
|
||||
difference_type operator-(pointer rhs) const { return hidden_ptr_ - rhs.hidden_ptr_; }
|
||||
pointer operator-(size_type rhs) const { return hidden_ptr_ - rhs; }
|
||||
bool operator == (pointer rhs) const { return hidden_ptr_ == rhs.hidden_ptr_; }
|
||||
bool operator != (pointer rhs) const { return hidden_ptr_ != rhs.hidden_ptr_; }
|
||||
bool operator < (pointer rhs) const { return hidden_ptr_ < rhs.hidden_ptr_; }
|
||||
bool operator >= (pointer rhs) const { return hidden_ptr_ >= rhs.hidden_ptr_; }
|
||||
pointer& operator++() { ++hidden_ptr_; return *this; }
|
||||
pointer& operator--() { --hidden_ptr_; return *this; }
|
||||
pointer& operator+=(size_type s) { hidden_ptr_ += s; return *this; }
|
||||
pointer operator+(size_type s) const { return hidden_ptr_ + s; }
|
||||
pointer operator++(int) { pointer p = *this; ++hidden_ptr_; return p; }
|
||||
pointer operator--(int) { pointer p = *this; --hidden_ptr_; return p; }
|
||||
T& operator*() const { return *hidden_ptr_; }
|
||||
|
||||
T* hidden_ptr_;
|
||||
};
|
||||
|
||||
struct const_pointer {
|
||||
const_pointer(){}
|
||||
const_pointer(pointer p) : hidden_ptr_(p.hidden_ptr_) {}
|
||||
const_pointer(const void* p) : hidden_ptr_((const T*)p) {}
|
||||
difference_type operator-(pointer rhs) const { return hidden_ptr_ - rhs.hidden_ptr_; }
|
||||
difference_type operator-(const_pointer rhs) const { return hidden_ptr_ - rhs.hidden_ptr_; }
|
||||
const_pointer operator-(size_type rhs) const { return hidden_ptr_ - rhs; }
|
||||
bool operator == (const_pointer rhs) const { return hidden_ptr_ == rhs.hidden_ptr_; }
|
||||
bool operator != (const_pointer rhs) const { return hidden_ptr_ != rhs.hidden_ptr_; }
|
||||
bool operator < (const_pointer rhs) const { return hidden_ptr_ < rhs.hidden_ptr_; }
|
||||
bool operator >= (const_pointer rhs) const { return hidden_ptr_ >= rhs.hidden_ptr_; }
|
||||
const_pointer& operator++() { ++hidden_ptr_; return *this; }
|
||||
const_pointer& operator--() { --hidden_ptr_; return *this; }
|
||||
const_pointer& operator+=(size_type s) { hidden_ptr_ += s; return hidden_ptr_; }
|
||||
const_pointer operator+(size_type s) const { return hidden_ptr_ + s; }
|
||||
const_pointer operator++(int) { const_pointer p = *this; ++hidden_ptr_; return p; }
|
||||
const_pointer operator--(int) { const_pointer p = *this; --hidden_ptr_; return p; }
|
||||
const T& operator*() const { return *hidden_ptr_; }
|
||||
|
||||
const T* hidden_ptr_;
|
||||
};
|
||||
|
||||
template<class T2>
|
||||
struct rebind
|
||||
{
|
||||
typedef my_allocator<T2> other;
|
||||
};
|
||||
|
||||
size_type max_size() const
|
||||
{ return base_.max_size(); }
|
||||
|
||||
pointer allocate(size_type count, const void* hint = 0) {
|
||||
return pointer(base_.allocate(count, hint));
|
||||
}
|
||||
|
||||
void deallocate(const pointer &ptr, size_type s)
|
||||
{ base_.deallocate(ptr.hidden_ptr_, s); }
|
||||
|
||||
template<class P>
|
||||
void construct(const pointer &ptr, BOOST_FWD_REF(P) p)
|
||||
{ ::new(ptr.hidden_ptr_) value_type(::boost::forward<P>(p)); }
|
||||
|
||||
void destroy(const pointer &ptr)
|
||||
{ (*ptr.hidden_ptr_).~value_type(); }
|
||||
|
||||
};
|
||||
|
||||
void allocator_test() {
|
||||
|
||||
CB_CONTAINER<MyInteger> cb1(10, 0);
|
||||
@@ -242,10 +159,6 @@ void allocator_test() {
|
||||
alloc.max_size();
|
||||
|
||||
generic_test(cb1);
|
||||
|
||||
|
||||
CB_CONTAINER<MyInteger, my_allocator<MyInteger> > cb_a(10, 0);
|
||||
generic_test(cb_a);
|
||||
}
|
||||
|
||||
void begin_and_end_test() {
|
||||
|
||||
Reference in New Issue
Block a user