forked from boostorg/container
Support GCC's -Wconversion -Wfloat-conversion -Warith-conversion -Wsign-conversion warnings.
This commit is contained in:
@@ -114,6 +114,7 @@ class deque_iterator
|
||||
typedef std::random_access_iterator_tag iterator_category;
|
||||
typedef typename boost::intrusive::pointer_traits<Pointer>::element_type value_type;
|
||||
typedef typename boost::intrusive::pointer_traits<Pointer>::difference_type difference_type;
|
||||
typedef typename boost::intrusive::pointer_traits<Pointer>::size_type size_type;
|
||||
typedef typename if_c
|
||||
< IsConst
|
||||
, typename boost::intrusive::pointer_traits<Pointer>::template
|
||||
@@ -151,6 +152,10 @@ class deque_iterator
|
||||
: m_cur(x), m_first(*y), m_last(*y + block_size), m_node(y)
|
||||
{}
|
||||
|
||||
BOOST_CONTAINER_FORCEINLINE deque_iterator(val_alloc_ptr x, index_pointer y, size_type block_size) BOOST_NOEXCEPT_OR_NOTHROW
|
||||
: m_cur(x), m_first(*y), m_last(*y + difference_type(block_size)), m_node(y)
|
||||
{}
|
||||
|
||||
BOOST_CONTAINER_FORCEINLINE deque_iterator() BOOST_NOEXCEPT_OR_NOTHROW
|
||||
: m_cur(), m_first(), m_last(), m_node() //Value initialization to achieve "null iterators" (N3644)
|
||||
{}
|
||||
@@ -186,7 +191,7 @@ class deque_iterator
|
||||
if(!this->m_cur && !x.m_cur){
|
||||
return 0;
|
||||
}
|
||||
const difference_type block_size = this->m_last - this->m_first;
|
||||
const difference_type block_size = m_last - m_first;
|
||||
BOOST_ASSERT(block_size);
|
||||
return block_size * (this->m_node - x.m_node - 1) +
|
||||
(this->m_cur - this->m_first) + (x.m_last - x.m_cur);
|
||||
@@ -238,15 +243,15 @@ class deque_iterator
|
||||
return *this;
|
||||
BOOST_ASSERT(!!m_cur);
|
||||
difference_type offset = n + (this->m_cur - this->m_first);
|
||||
const difference_type block_size = this->m_last - this->m_first;
|
||||
const difference_type block_size = m_last - m_first;
|
||||
BOOST_ASSERT(block_size);
|
||||
if (offset >= 0 && offset < block_size)
|
||||
this->m_cur += n;
|
||||
this->m_cur += difference_type(n);
|
||||
else {
|
||||
difference_type node_offset =
|
||||
offset > 0 ? (offset / block_size)
|
||||
: (-difference_type((-offset - 1) / block_size) - 1);
|
||||
this->priv_set_node(this->m_node + node_offset, block_size);
|
||||
this->priv_set_node(this->m_node + node_offset, size_type(block_size));
|
||||
this->m_cur = this->m_first +
|
||||
(offset - node_offset * block_size);
|
||||
}
|
||||
@@ -269,6 +274,7 @@ class deque_iterator
|
||||
reference operator[](difference_type n) const BOOST_NOEXCEPT_OR_NOTHROW
|
||||
{ return *(*this + n); }
|
||||
|
||||
//Comparisons
|
||||
BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE
|
||||
friend bool operator==(const deque_iterator& l, const deque_iterator& r) BOOST_NOEXCEPT_OR_NOTHROW
|
||||
{ return l.m_cur == r.m_cur; }
|
||||
@@ -297,6 +303,9 @@ class deque_iterator
|
||||
friend deque_iterator operator+(difference_type n, deque_iterator x) BOOST_NOEXCEPT_OR_NOTHROW
|
||||
{ return x += n; }
|
||||
|
||||
BOOST_CONTAINER_FORCEINLINE void priv_set_node(index_pointer new_node, size_type block_size) BOOST_NOEXCEPT_OR_NOTHROW
|
||||
{ return this->priv_set_node(new_node, difference_type(block_size)); }
|
||||
|
||||
BOOST_CONTAINER_FORCEINLINE void priv_set_node(index_pointer new_node, difference_type block_size) BOOST_NOEXCEPT_OR_NOTHROW
|
||||
{
|
||||
this->m_node = new_node;
|
||||
@@ -346,6 +355,7 @@ class deque_base
|
||||
typedef Allocator allocator_type;
|
||||
typedef allocator_type stored_allocator_type;
|
||||
typedef val_alloc_size size_type;
|
||||
typedef val_alloc_diff difference_type;
|
||||
|
||||
private:
|
||||
typedef typename get_deque_opt<Options>::type options_type;
|
||||
@@ -357,6 +367,9 @@ class deque_base
|
||||
BOOST_CONSTEXPR BOOST_CONTAINER_FORCEINLINE static size_type get_block_size() BOOST_NOEXCEPT_OR_NOTHROW
|
||||
{ return deque_block_size<val_alloc_val, options_type::block_bytes, options_type::block_size>::value; }
|
||||
|
||||
BOOST_CONSTEXPR BOOST_CONTAINER_FORCEINLINE static val_alloc_diff get_block_ssize() BOOST_NOEXCEPT_OR_NOTHROW
|
||||
{ return val_alloc_diff((get_block_size)()); }
|
||||
|
||||
typedef deque_value_traits<val_alloc_val> traits_t;
|
||||
typedef ptr_alloc_t map_allocator_type;
|
||||
|
||||
@@ -418,8 +431,8 @@ class deque_base
|
||||
this->members_.m_map_size = dtl::max_value((size_type) InitialMapSize, num_nodes + 2);
|
||||
this->members_.m_map = this->priv_allocate_map(this->members_.m_map_size);
|
||||
|
||||
ptr_alloc_ptr nstart = this->members_.m_map + (this->members_.m_map_size - num_nodes) / 2;
|
||||
ptr_alloc_ptr nfinish = nstart + num_nodes;
|
||||
ptr_alloc_ptr nstart = this->members_.m_map + difference_type(this->members_.m_map_size - num_nodes) / 2;
|
||||
ptr_alloc_ptr nfinish = nstart + difference_type(num_nodes);
|
||||
|
||||
BOOST_TRY {
|
||||
this->priv_create_nodes(nstart, nfinish);
|
||||
@@ -435,8 +448,7 @@ class deque_base
|
||||
this->members_.m_start.priv_set_node(nstart, get_block_size());
|
||||
this->members_.m_finish.priv_set_node(nfinish - 1, get_block_size());
|
||||
this->members_.m_start.m_cur = this->members_.m_start.m_first;
|
||||
this->members_.m_finish.m_cur = this->members_.m_finish.m_first +
|
||||
num_elements % get_block_size();
|
||||
this->members_.m_finish.m_cur = this->members_.m_finish.m_first + difference_type(num_elements % get_block_size());
|
||||
// }
|
||||
}
|
||||
|
||||
@@ -538,6 +550,7 @@ class deque : protected deque_base<typename real_allocator<T, Allocator>::type,
|
||||
typedef deque_base<typename real_allocator<T, Allocator>::type, Options> Base;
|
||||
#endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
|
||||
typedef typename real_allocator<T, Allocator>::type ValAllocator;
|
||||
typedef constant_iterator<T> c_it;
|
||||
|
||||
public:
|
||||
|
||||
@@ -570,10 +583,12 @@ class deque : protected deque_base<typename real_allocator<T, Allocator>::type,
|
||||
|
||||
#endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
|
||||
|
||||
using Base::get_block_ssize;
|
||||
|
||||
public:
|
||||
|
||||
BOOST_CONSTEXPR BOOST_CONTAINER_FORCEINLINE static size_type get_block_size() BOOST_NOEXCEPT_OR_NOTHROW
|
||||
{ return Base::get_block_size(); }
|
||||
using Base::get_block_size;
|
||||
|
||||
|
||||
//////////////////////////////////////////////
|
||||
//
|
||||
@@ -903,7 +918,6 @@ class deque : protected deque_base<typename real_allocator<T, Allocator>::type,
|
||||
//! <b>Complexity</b>: Linear to n.
|
||||
BOOST_CONTAINER_FORCEINLINE void assign(size_type n, const T& val)
|
||||
{
|
||||
typedef constant_iterator<value_type, difference_type> c_it;
|
||||
this->assign(c_it(val, n), c_it());
|
||||
}
|
||||
|
||||
@@ -946,10 +960,10 @@ class deque : protected deque_base<typename real_allocator<T, Allocator>::type,
|
||||
>::type * = 0
|
||||
)
|
||||
{
|
||||
const size_type len = boost::container::iterator_distance(first, last);
|
||||
const size_type len = boost::container::iterator_udistance(first, last);
|
||||
if (len > size()) {
|
||||
FwdIt mid = first;
|
||||
boost::container::iterator_advance(mid, this->size());
|
||||
boost::container::iterator_uadvance(mid, this->size());
|
||||
boost::container::copy(first, mid, begin());
|
||||
this->insert(this->cend(), mid, last);
|
||||
}
|
||||
@@ -1143,7 +1157,7 @@ class deque : protected deque_base<typename real_allocator<T, Allocator>::type,
|
||||
//! <b>Complexity</b>: Constant.
|
||||
BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE
|
||||
size_type size() const BOOST_NOEXCEPT_OR_NOTHROW
|
||||
{ return this->members_.m_finish - this->members_.m_start; }
|
||||
{ return size_type(this->members_.m_finish - this->members_.m_start); }
|
||||
|
||||
//! <b>Effects</b>: Returns the largest possible size of the deque.
|
||||
//!
|
||||
@@ -1202,7 +1216,7 @@ class deque : protected deque_base<typename real_allocator<T, Allocator>::type,
|
||||
{
|
||||
const size_type len = size();
|
||||
if (new_size < len)
|
||||
this->erase(this->members_.m_start + new_size, this->members_.m_finish);
|
||||
this->erase(this->members_.m_start + difference_type(new_size), this->members_.m_finish);
|
||||
else
|
||||
this->insert(this->members_.m_finish, new_size - len, x);
|
||||
}
|
||||
@@ -1335,7 +1349,7 @@ class deque : protected deque_base<typename real_allocator<T, Allocator>::type,
|
||||
iterator nth(size_type n) BOOST_NOEXCEPT_OR_NOTHROW
|
||||
{
|
||||
BOOST_ASSERT(this->size() >= n);
|
||||
return iterator(this->begin()+n);
|
||||
return iterator(this->begin()+difference_type(n));
|
||||
}
|
||||
|
||||
//! <b>Requires</b>: size() >= n.
|
||||
@@ -1353,7 +1367,7 @@ class deque : protected deque_base<typename real_allocator<T, Allocator>::type,
|
||||
const_iterator nth(size_type n) const BOOST_NOEXCEPT_OR_NOTHROW
|
||||
{
|
||||
BOOST_ASSERT(this->size() >= n);
|
||||
return const_iterator(this->cbegin()+n);
|
||||
return const_iterator(this->cbegin()+difference_type(n));
|
||||
}
|
||||
|
||||
//! <b>Requires</b>: begin() <= p <= end().
|
||||
@@ -1649,7 +1663,6 @@ class deque : protected deque_base<typename real_allocator<T, Allocator>::type,
|
||||
BOOST_CONTAINER_FORCEINLINE iterator insert(const_iterator pos, size_type n, const value_type& x)
|
||||
{
|
||||
//Range check of p is done by insert()
|
||||
typedef constant_iterator<value_type, difference_type> c_it;
|
||||
return this->insert(pos, c_it(x, n), c_it());
|
||||
}
|
||||
|
||||
@@ -1681,7 +1694,7 @@ class deque : protected deque_base<typename real_allocator<T, Allocator>::type,
|
||||
it = this->emplace(it, *first);
|
||||
++it;
|
||||
}
|
||||
it -= n;
|
||||
it -= difference_type(n);
|
||||
return it;
|
||||
}
|
||||
|
||||
@@ -1717,7 +1730,7 @@ class deque : protected deque_base<typename real_allocator<T, Allocator>::type,
|
||||
{
|
||||
BOOST_ASSERT(this->priv_in_range_or_end(p));
|
||||
dtl::insert_range_proxy<ValAllocator, FwdIt, iterator> proxy(first);
|
||||
return priv_insert_aux_impl(p, boost::container::iterator_distance(first, last), proxy);
|
||||
return priv_insert_aux_impl(p, boost::container::iterator_udistance(first, last), proxy);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -1772,7 +1785,7 @@ class deque : protected deque_base<typename real_allocator<T, Allocator>::type,
|
||||
BOOST_ASSERT(this->priv_in_range(pos));
|
||||
iterator next = pos.unconst();
|
||||
++next;
|
||||
size_type index = pos - this->members_.m_start;
|
||||
size_type index = size_type(pos - this->members_.m_start);
|
||||
if (index < (this->size()/2)) {
|
||||
boost::container::move_backward(this->begin(), pos.unconst(), next);
|
||||
pop_front();
|
||||
@@ -1781,7 +1794,7 @@ class deque : protected deque_base<typename real_allocator<T, Allocator>::type,
|
||||
boost::container::move(next, this->end(), pos.unconst());
|
||||
pop_back();
|
||||
}
|
||||
return this->members_.m_start + index;
|
||||
return this->members_.m_start + difference_type(index);
|
||||
}
|
||||
|
||||
//! <b>Effects</b>: Erases the elements pointed by [first, last).
|
||||
@@ -1805,19 +1818,19 @@ class deque : protected deque_base<typename real_allocator<T, Allocator>::type,
|
||||
const size_type elems_before = static_cast<size_type>(first - this->members_.m_start);
|
||||
if (elems_before < (this->size() - n) - elems_before) {
|
||||
boost::container::move_backward(begin(), first.unconst(), last.unconst());
|
||||
iterator new_start = this->members_.m_start + n;
|
||||
iterator new_start = this->members_.m_start + difference_type(n);
|
||||
this->priv_destroy_range(this->members_.m_start, new_start);
|
||||
this->priv_destroy_nodes(this->members_.m_start.m_node, new_start.m_node);
|
||||
this->members_.m_start = new_start;
|
||||
}
|
||||
else {
|
||||
boost::container::move(last.unconst(), end(), first.unconst());
|
||||
iterator new_finish = this->members_.m_finish - n;
|
||||
iterator new_finish = this->members_.m_finish - difference_type(n);
|
||||
this->priv_destroy_range(new_finish, this->members_.m_finish);
|
||||
this->priv_destroy_nodes(new_finish.m_node + 1, this->members_.m_finish.m_node + 1);
|
||||
this->members_.m_finish = new_finish;
|
||||
}
|
||||
return this->members_.m_start + elems_before;
|
||||
return this->members_.m_start + difference_type(elems_before);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1848,7 +1861,7 @@ class deque : protected deque_base<typename real_allocator<T, Allocator>::type,
|
||||
for (index_pointer node = this->members_.m_start.m_node + 1;
|
||||
node < this->members_.m_finish.m_node;
|
||||
++node) {
|
||||
this->priv_destroy_range(*node, *node + get_block_size());
|
||||
this->priv_destroy_range(*node, *node + get_block_ssize());
|
||||
this->priv_deallocate_node(*node);
|
||||
}
|
||||
|
||||
@@ -1929,7 +1942,7 @@ class deque : protected deque_base<typename real_allocator<T, Allocator>::type,
|
||||
this->clear();
|
||||
}
|
||||
else {
|
||||
iterator new_finish = this->members_.m_finish - n;
|
||||
iterator new_finish = this->members_.m_finish - difference_type(n);
|
||||
this->priv_destroy_range(new_finish, this->members_.m_finish);
|
||||
this->priv_destroy_nodes(new_finish.m_node + 1, this->members_.m_finish.m_node + 1);
|
||||
this->members_.m_finish = new_finish;
|
||||
@@ -2051,7 +2064,7 @@ class deque : protected deque_base<typename real_allocator<T, Allocator>::type,
|
||||
iterator priv_insert_aux_impl(const_iterator p, size_type n, InsertProxy proxy)
|
||||
{
|
||||
iterator pos(p.unconst());
|
||||
const size_type pos_n = p - this->cbegin();
|
||||
const size_type pos_n = size_type(p - this->cbegin());
|
||||
if(!this->members_.m_map){
|
||||
this->priv_initialize_map(0);
|
||||
pos = this->begin();
|
||||
@@ -2067,18 +2080,18 @@ class deque : protected deque_base<typename real_allocator<T, Allocator>::type,
|
||||
this->members_.m_start = new_start;
|
||||
}
|
||||
else{
|
||||
pos = this->members_.m_start + elemsbefore;
|
||||
pos = this->members_.m_start + difference_type(elemsbefore);
|
||||
if (elemsbefore >= n) {
|
||||
const iterator start_n = this->members_.m_start + n;
|
||||
const iterator start_n = this->members_.m_start + difference_type(n);
|
||||
::boost::container::uninitialized_move_alloc
|
||||
(this->alloc(), this->members_.m_start, start_n, new_start);
|
||||
this->members_.m_start = new_start;
|
||||
boost::container::move(start_n, pos, old_start);
|
||||
proxy.copy_n_and_update(this->alloc(), pos - n, n);
|
||||
proxy.copy_n_and_update(this->alloc(), pos - difference_type(n), n);
|
||||
}
|
||||
else {
|
||||
const size_type mid_count = n - elemsbefore;
|
||||
const iterator mid_start = old_start - mid_count;
|
||||
const iterator mid_start = old_start - difference_type(mid_count);
|
||||
proxy.uninitialized_copy_n_and_update(this->alloc(), mid_start, mid_count);
|
||||
this->members_.m_start = mid_start;
|
||||
::boost::container::uninitialized_move_alloc
|
||||
@@ -2097,7 +2110,7 @@ class deque : protected deque_base<typename real_allocator<T, Allocator>::type,
|
||||
this->members_.m_finish = new_finish;
|
||||
}
|
||||
else{
|
||||
pos = old_finish - elemsafter;
|
||||
pos = old_finish - difference_type(elemsafter);
|
||||
if (elemsafter >= n) {
|
||||
iterator finish_n = old_finish - difference_type(n);
|
||||
::boost::container::uninitialized_move_alloc
|
||||
@@ -2109,13 +2122,13 @@ class deque : protected deque_base<typename real_allocator<T, Allocator>::type,
|
||||
else {
|
||||
const size_type raw_gap = n - elemsafter;
|
||||
::boost::container::uninitialized_move_alloc
|
||||
(this->alloc(), pos, old_finish, old_finish + raw_gap);
|
||||
(this->alloc(), pos, old_finish, old_finish + difference_type(raw_gap));
|
||||
BOOST_TRY{
|
||||
proxy.copy_n_and_update(this->alloc(), pos, elemsafter);
|
||||
proxy.uninitialized_copy_n_and_update(this->alloc(), old_finish, raw_gap);
|
||||
}
|
||||
BOOST_CATCH(...){
|
||||
this->priv_destroy_range(old_finish, old_finish + elemsafter);
|
||||
this->priv_destroy_range(old_finish, old_finish + difference_type(elemsafter));
|
||||
BOOST_RETHROW
|
||||
}
|
||||
BOOST_CATCH_END
|
||||
@@ -2123,7 +2136,7 @@ class deque : protected deque_base<typename real_allocator<T, Allocator>::type,
|
||||
}
|
||||
}
|
||||
}
|
||||
return this->begin() + pos_n;
|
||||
return this->begin() + difference_type(pos_n);
|
||||
}
|
||||
|
||||
template <class InsertProxy>
|
||||
@@ -2137,7 +2150,7 @@ class deque : protected deque_base<typename real_allocator<T, Allocator>::type,
|
||||
iterator old_finish = this->members_.m_finish;
|
||||
proxy.uninitialized_copy_n_and_update(this->alloc(), old_finish, n);
|
||||
this->members_.m_finish = new_finish;
|
||||
return iterator(this->members_.m_finish - n);
|
||||
return iterator(this->members_.m_finish - difference_type(n));
|
||||
}
|
||||
|
||||
template <class InsertProxy>
|
||||
@@ -2155,7 +2168,6 @@ class deque : protected deque_base<typename real_allocator<T, Allocator>::type,
|
||||
|
||||
BOOST_CONTAINER_FORCEINLINE iterator priv_fill_insert(const_iterator pos, size_type n, const value_type& x)
|
||||
{
|
||||
typedef constant_iterator<value_type, difference_type> c_it;
|
||||
return this->insert(pos, c_it(x, n), c_it());
|
||||
}
|
||||
|
||||
@@ -2167,7 +2179,7 @@ class deque : protected deque_base<typename real_allocator<T, Allocator>::type,
|
||||
BOOST_TRY {
|
||||
for ( ; cur < this->members_.m_finish.m_node; ++cur){
|
||||
boost::container::uninitialized_fill_alloc
|
||||
(this->alloc(), *cur, *cur + get_block_size(), value);
|
||||
(this->alloc(), *cur, *cur + get_block_ssize(), value);
|
||||
}
|
||||
boost::container::uninitialized_fill_alloc
|
||||
(this->alloc(), this->members_.m_finish.m_first, this->members_.m_finish.m_cur, value);
|
||||
@@ -2198,14 +2210,14 @@ class deque : protected deque_base<typename real_allocator<T, Allocator>::type,
|
||||
void priv_range_initialize(FwdIt first, FwdIt last, typename iterator_disable_if_tag<FwdIt, std::input_iterator_tag>::type* =0)
|
||||
{
|
||||
size_type n = 0;
|
||||
n = boost::container::iterator_distance(first, last);
|
||||
n = boost::container::iterator_udistance(first, last);
|
||||
this->priv_initialize_map(n);
|
||||
|
||||
index_pointer cur_node = this->members_.m_start.m_node;
|
||||
BOOST_TRY {
|
||||
for (; cur_node < this->members_.m_finish.m_node; ++cur_node) {
|
||||
FwdIt mid = first;
|
||||
boost::container::iterator_advance(mid, get_block_size());
|
||||
boost::container::iterator_uadvance(mid, get_block_size());
|
||||
::boost::container::uninitialized_copy_alloc(this->alloc(), first, mid, *cur_node);
|
||||
first = mid;
|
||||
}
|
||||
@@ -2247,11 +2259,10 @@ class deque : protected deque_base<typename real_allocator<T, Allocator>::type,
|
||||
|
||||
iterator priv_reserve_elements_at_front(size_type n)
|
||||
{
|
||||
size_type vacancies = this->members_.m_start.m_cur - this->members_.m_start.m_first;
|
||||
size_type vacancies = size_type(this->members_.m_start.m_cur - this->members_.m_start.m_first);
|
||||
if (n > vacancies){
|
||||
size_type new_elems = n-vacancies;
|
||||
size_type new_nodes = (new_elems + get_block_size() - 1) /
|
||||
get_block_size();
|
||||
size_type new_nodes = (new_elems + get_block_size() - 1u) / get_block_size();
|
||||
size_type s = (size_type)(this->members_.m_start.m_node - this->members_.m_map);
|
||||
if (new_nodes > s){
|
||||
this->priv_reallocate_map(new_nodes, true);
|
||||
@@ -2259,11 +2270,11 @@ class deque : protected deque_base<typename real_allocator<T, Allocator>::type,
|
||||
size_type i = 1;
|
||||
BOOST_TRY {
|
||||
for (; i <= new_nodes; ++i)
|
||||
*(this->members_.m_start.m_node - i) = this->priv_allocate_node();
|
||||
*(this->members_.m_start.m_node - difference_type(i)) = this->priv_allocate_node();
|
||||
}
|
||||
BOOST_CATCH(...) {
|
||||
for (size_type j = 1; j < i; ++j)
|
||||
this->priv_deallocate_node(*(this->members_.m_start.m_node - j));
|
||||
this->priv_deallocate_node(*(this->members_.m_start.m_node - difference_type(j)));
|
||||
BOOST_RETHROW
|
||||
}
|
||||
BOOST_CATCH_END
|
||||
@@ -2273,22 +2284,22 @@ class deque : protected deque_base<typename real_allocator<T, Allocator>::type,
|
||||
|
||||
iterator priv_reserve_elements_at_back(size_type n)
|
||||
{
|
||||
size_type vacancies = (this->members_.m_finish.m_last - this->members_.m_finish.m_cur) - 1;
|
||||
size_type vacancies = size_type(this->members_.m_finish.m_last - this->members_.m_finish.m_cur - 1);
|
||||
if (n > vacancies){
|
||||
size_type new_elems = n - vacancies;
|
||||
size_type new_nodes = (new_elems + get_block_size() - 1)/get_block_size();
|
||||
size_type s = (size_type)(this->members_.m_map_size - (this->members_.m_finish.m_node - this->members_.m_map));
|
||||
size_type new_elems = size_type(n - vacancies);
|
||||
size_type new_nodes = size_type(new_elems + get_block_size() - 1u)/get_block_size();
|
||||
size_type s = (size_type)(this->members_.m_map_size - size_type(this->members_.m_finish.m_node - this->members_.m_map));
|
||||
if (new_nodes + 1 > s){
|
||||
this->priv_reallocate_map(new_nodes, false);
|
||||
}
|
||||
size_type i = 1;
|
||||
BOOST_TRY {
|
||||
for (; i <= new_nodes; ++i)
|
||||
*(this->members_.m_finish.m_node + i) = this->priv_allocate_node();
|
||||
*(this->members_.m_finish.m_node + difference_type(i)) = this->priv_allocate_node();
|
||||
}
|
||||
BOOST_CATCH(...) {
|
||||
for (size_type j = 1; j < i; ++j)
|
||||
this->priv_deallocate_node(*(this->members_.m_finish.m_node + j));
|
||||
this->priv_deallocate_node(*(this->members_.m_finish.m_node + difference_type(j)));
|
||||
BOOST_RETHROW
|
||||
}
|
||||
BOOST_CATCH_END
|
||||
@@ -2298,26 +2309,26 @@ class deque : protected deque_base<typename real_allocator<T, Allocator>::type,
|
||||
|
||||
void priv_reallocate_map(size_type nodes_to_add, bool add_at_front)
|
||||
{
|
||||
size_type old_num_nodes = this->members_.m_finish.m_node - this->members_.m_start.m_node + 1;
|
||||
size_type old_num_nodes = size_type(this->members_.m_finish.m_node - this->members_.m_start.m_node + 1);
|
||||
size_type new_num_nodes = old_num_nodes + nodes_to_add;
|
||||
|
||||
index_pointer new_nstart;
|
||||
if (this->members_.m_map_size > 2 * new_num_nodes) {
|
||||
new_nstart = this->members_.m_map + (this->members_.m_map_size - new_num_nodes) / 2
|
||||
+ (add_at_front ? nodes_to_add : 0);
|
||||
new_nstart = this->members_.m_map + difference_type(this->members_.m_map_size - new_num_nodes) / 2
|
||||
+ difference_type(add_at_front ? nodes_to_add : 0u);
|
||||
if (new_nstart < this->members_.m_start.m_node)
|
||||
boost::container::move(this->members_.m_start.m_node, this->members_.m_finish.m_node + 1, new_nstart);
|
||||
else
|
||||
boost::container::move_backward
|
||||
(this->members_.m_start.m_node, this->members_.m_finish.m_node + 1, new_nstart + old_num_nodes);
|
||||
(this->members_.m_start.m_node, this->members_.m_finish.m_node + 1, new_nstart + difference_type(old_num_nodes));
|
||||
}
|
||||
else {
|
||||
size_type new_map_size =
|
||||
this->members_.m_map_size + dtl::max_value(this->members_.m_map_size, nodes_to_add) + 2;
|
||||
|
||||
index_pointer new_map = this->priv_allocate_map(new_map_size);
|
||||
new_nstart = new_map + (new_map_size - new_num_nodes) / 2
|
||||
+ (add_at_front ? nodes_to_add : 0);
|
||||
new_nstart = new_map + difference_type(new_map_size - new_num_nodes) / 2
|
||||
+ difference_type(add_at_front ? nodes_to_add : 0u);
|
||||
boost::container::move(this->members_.m_start.m_node, this->members_.m_finish.m_node + 1, new_nstart);
|
||||
this->priv_deallocate_map(this->members_.m_map, this->members_.m_map_size);
|
||||
|
||||
@@ -2326,7 +2337,7 @@ class deque : protected deque_base<typename real_allocator<T, Allocator>::type,
|
||||
}
|
||||
|
||||
this->members_.m_start.priv_set_node(new_nstart, get_block_size());
|
||||
this->members_.m_finish.priv_set_node(new_nstart + old_num_nodes - 1, get_block_size());
|
||||
this->members_.m_finish.priv_set_node(new_nstart + difference_type(old_num_nodes - 1u), get_block_size());
|
||||
}
|
||||
#endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user