|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r80404 - in trunk: boost/container boost/container/detail libs/container/test
From: igaztanaga_at_[hidden]
Date: 2012-09-05 05:28:26
Author: igaztanaga
Date: 2012-09-05 05:28:24 EDT (Wed, 05 Sep 2012)
New Revision: 80404
URL: http://svn.boost.org/trac/boost/changeset/80404
Log:
Improved type safety and strict aliasing
Text files modified:
trunk/boost/container/detail/multiallocation_chain.hpp | 23 +
trunk/boost/container/stable_vector.hpp | 494 ++++++++++++++++++++-------------------
trunk/boost/container/string.hpp | 364 ++++++++++++++++-------------
trunk/libs/container/test/check_equal_containers.hpp | 5
4 files changed, 465 insertions(+), 421 deletions(-)
Modified: trunk/boost/container/detail/multiallocation_chain.hpp
==============================================================================
--- trunk/boost/container/detail/multiallocation_chain.hpp (original)
+++ trunk/boost/container/detail/multiallocation_chain.hpp 2012-09-05 05:28:24 EDT (Wed, 05 Sep 2012)
@@ -157,18 +157,20 @@
MultiallocationChain holder_;
typedef typename MultiallocationChain::void_pointer void_pointer;
typedef typename boost::intrusive::pointer_traits
- <void_pointer>::template rebind_pointer<T>::type pointer;
+ <void_pointer> void_pointer_traits;
+ typedef typename void_pointer_traits::template
+ rebind_pointer<T>::type pointer;
+ typedef typename boost::intrusive::pointer_traits
+ <pointer> pointer_traits;
- static pointer cast(void_pointer p)
- {
- return pointer(static_cast<T*>(container_detail::to_raw_pointer(p)));
- }
+ static pointer cast(const void_pointer &p)
+ { return pointer_traits::static_cast_from(p); }
public:
typedef transform_iterator
< typename MultiallocationChain::iterator
- , container_detail::cast_functor <T> > iterator;
- typedef typename MultiallocationChain::size_type size_type;
+ , container_detail::cast_functor <T> > iterator;
+ typedef typename MultiallocationChain::size_type size_type;
transform_multiallocation_chain()
: holder_()
@@ -234,8 +236,11 @@
static iterator iterator_to(pointer p)
{ return iterator(MultiallocationChain::iterator_to(p)); }
- std::pair<void_pointer, void_pointer> extract_data()
- { return holder_.extract_data(); }
+ std::pair<pointer, pointer> extract_data()
+ {
+ std::pair<void_pointer, void_pointer> data(holder_.extract_data());
+ return std::pair<pointer, pointer>(cast(data.first), cast(data.second));
+ }
MultiallocationChain extract_multiallocation_chain()
{
Modified: trunk/boost/container/stable_vector.hpp
==============================================================================
--- trunk/boost/container/stable_vector.hpp (original)
+++ trunk/boost/container/stable_vector.hpp 2012-09-05 05:28:24 EDT (Wed, 05 Sep 2012)
@@ -36,10 +36,11 @@
#include <boost/container/detail/algorithms.hpp>
#include <boost/container/allocator_traits.hpp>
#include <boost/intrusive/pointer_traits.hpp>
-
-#include <algorithm>
+#include <boost/aligned_storage.hpp>
+#include <algorithm> //max
#include <stdexcept>
#include <memory>
+#include <new> //placement new
///@cond
@@ -104,23 +105,44 @@
bool do_clear_;
};
-template<class VoidPtr>
-struct node_type_base
+template<typename VoidPointer, typename T>
+struct node;
+
+template<class NodePtr>
+struct node_base
{
- node_type_base()
+ private:
+ typedef NodePtr node_ptr;
+ typedef typename boost::intrusive::
+ pointer_traits<node_ptr> node_ptr_traits;
+ typedef typename node_ptr_traits::
+ template rebind_pointer
+ <node_base>::type node_base_ptr;
+ typedef typename node_ptr_traits::
+ template rebind_pointer
+ <node_ptr>::type node_ptr_ptr;
+
+ public:
+ node_base(const node_ptr_ptr &n)
+ : up(n)
+ {}
+
+ node_base()
+ : up()
{}
- void set_pointer(const VoidPtr &p)
- { up = p; }
- VoidPtr up;
+ node_ptr_ptr up;
};
template<typename VoidPointer, typename T>
-struct node_type
- : public node_type_base<VoidPointer>
+struct node
+ : public node_base
+ <typename boost::intrusive::
+ pointer_traits<VoidPointer>::template
+ rebind_pointer< node<VoidPointer, T> >::type>
{
private:
- node_type();
+ node();
public:
T value;
@@ -135,90 +157,67 @@
, Pointer
, Reference>
{
- typedef typename boost::intrusive::
- pointer_traits<Pointer>::template
- rebind_pointer<void>::type void_ptr;
- typedef typename boost::intrusive::
- pointer_traits<Pointer>::template
- rebind_pointer<const void>::type const_void_ptr;
- typedef node_type<void_ptr, T> node_type_t;
- typedef typename boost::intrusive::
- pointer_traits<Pointer>::template
- rebind_pointer<node_type_t>::type node_type_ptr_t;
- typedef typename boost::intrusive::
- pointer_traits<Pointer>::template
- rebind_pointer<const node_type_t>::type const_node_type_ptr_t;
- typedef typename boost::intrusive::
- pointer_traits<Pointer>::template
- rebind_pointer<void_ptr>::type void_ptr_ptr;
+ typedef boost::intrusive::
+ pointer_traits<Pointer> ptr_traits;
+ typedef typename ptr_traits::template
+ rebind_pointer<void>::type void_ptr;
+ typedef node<void_ptr, T> node_type;
+ typedef typename ptr_traits::template
+ rebind_pointer<node_type>::type node_ptr;
+ typedef typename ptr_traits::template
+ rebind_pointer<node_ptr>::type node_ptr_ptr;
+ typedef typename ptr_traits::template
+ rebind_pointer<T>::type friend_iterator_pointer;
- friend class iterator<T, const T, typename boost::intrusive::pointer_traits<Pointer>::template rebind_pointer<T>::type>;
+ friend class iterator<T, const T, friend_iterator_pointer>;
public:
typedef std::random_access_iterator_tag iterator_category;
typedef T value_type;
- typedef typename boost::intrusive::
- pointer_traits<Pointer>::difference_type difference_type;
+ typedef typename ptr_traits::difference_type difference_type;
typedef Pointer pointer;
typedef Reference reference;
iterator()
{}
- explicit iterator(node_type_ptr_t pn)
- : pn(pn)
+ explicit iterator(node_ptr p)
+ : pn(p)
{}
- iterator(const iterator<T, T&, typename boost::intrusive::pointer_traits<Pointer>::template rebind_pointer<T>::type>& x)
+ iterator(const iterator<T, T&, friend_iterator_pointer>& x)
: pn(x.pn)
{}
- node_type_ptr_t node() const
- { return pn; }
-
- private:
- static node_type_ptr_t node_ptr_cast(const void_ptr &p)
- {
- return node_type_ptr_t(static_cast<node_type_t*>(container_detail::to_raw_pointer(p)));
- }
-
- static const_node_type_ptr_t node_ptr_cast(const const_void_ptr &p)
- {
- return const_node_type_ptr_t(static_cast<const node_type_t*>(container_detail::to_raw_pointer(p)));
- }
-
- static void_ptr_ptr void_ptr_ptr_cast(const void_ptr &p)
- {
- return void_ptr_ptr(static_cast<void_ptr*>(container_detail::to_raw_pointer(p)));
- }
-
- reference dereference() const
- { return pn->value; }
- bool equal(const iterator& x) const
- { return pn==x.pn; }
- void increment()
- { pn = node_ptr_cast(*(void_ptr_ptr_cast(pn->up)+1)); }
- void decrement()
- { pn = node_ptr_cast(*(void_ptr_ptr_cast(pn->up)-1)); }
- void advance(difference_type n)
- { pn = node_ptr_cast(*(void_ptr_ptr_cast(pn->up)+n)); }
- difference_type distance_to(const iterator& x)const
- { return void_ptr_ptr_cast(x.pn->up) - void_ptr_ptr_cast(pn->up); }
-
public:
//Pointer like operators
- reference operator*() const { return this->dereference(); }
- pointer operator->() const { return pointer(&this->dereference()); }
+ reference operator*() const
+ { return pn->value; }
+
+ pointer operator->() const
+ { return ptr_traits::pointer_to(*this); }
//Increment / Decrement
iterator& operator++()
- { this->increment(); return *this; }
+ {
+ if(node_ptr_ptr p = this->pn->up){
+ ++p;
+ this->pn = *p;
+ }
+ return *this;
+ }
iterator operator++(int)
{ iterator tmp(*this); ++*this; return iterator(tmp); }
iterator& operator--()
- { this->decrement(); return *this; }
+ {
+ if(node_ptr_ptr p = this->pn->up){
+ --p;
+ this->pn = *p;
+ }
+ return *this;
+ }
iterator operator--(int)
{ iterator tmp(*this); --*this; return iterator(tmp); }
@@ -232,7 +231,10 @@
iterator& operator+=(difference_type off)
{
- pn = node_ptr_cast(*(void_ptr_ptr_cast(pn->up)+off));
+ if(node_ptr_ptr p = this->pn->up){
+ p += off;
+ this->pn = *p;
+ }
return *this;
}
@@ -262,7 +264,7 @@
friend difference_type operator-(const iterator& left, const iterator& right)
{
- return void_ptr_ptr_cast(left.pn->up) - void_ptr_ptr_cast(right.pn->up);
+ return left.pn->up - right.pn->up;
}
//Comparison operators
@@ -273,18 +275,18 @@
{ return l.pn != r.pn; }
friend bool operator< (const iterator& l, const iterator& r)
- { return void_ptr_ptr_cast(l.pn->up) < void_ptr_ptr_cast(r.pn->up); }
+ { return l.pn->up < r.pn->up; }
friend bool operator<= (const iterator& l, const iterator& r)
- { return void_ptr_ptr_cast(l.pn->up) <= void_ptr_ptr_cast(r.pn->up); }
+ { return l.pn->up <= r.pn->up; }
friend bool operator> (const iterator& l, const iterator& r)
- { return void_ptr_ptr_cast(l.pn->up) > void_ptr_ptr_cast(r.pn->up); }
+ { return l.pn->up > r.pn->up; }
friend bool operator>= (const iterator& l, const iterator& r)
- { return void_ptr_ptr_cast(l.pn->up) >= void_ptr_ptr_cast(r.pn->up); }
+ { return l.pn->up >= r.pn->up; }
- node_type_ptr_t pn;
+ node_ptr pn;
};
template<class A, unsigned int Version>
@@ -368,34 +370,32 @@
typedef allocator_traits<A> allocator_traits_type;
typedef typename container_detail::
move_const_ref_type<T>::type insert_const_ref_type;
+ typedef boost::intrusive::
+ pointer_traits
+ <typename allocator_traits_type::pointer> ptr_traits;
typedef typename boost::intrusive::pointer_traits
<typename allocator_traits_type::pointer>::
template rebind_pointer<void>::type void_ptr;
- typedef typename boost::intrusive::pointer_traits
- <void_ptr>::template
- rebind_pointer<const void>::type const_void_ptr;
- typedef typename boost::intrusive::pointer_traits
- <void_ptr>::template
- rebind_pointer<void_ptr>::type void_ptr_ptr;
- typedef typename boost::intrusive::pointer_traits
- <void_ptr>::template
- rebind_pointer<const void_ptr>::type const_void_ptr_ptr;
- typedef stable_vector_detail::node_type
- <void_ptr, T> node_type_t;
- typedef typename boost::intrusive::pointer_traits
- <void_ptr>::template
- rebind_pointer<node_type_t>::type node_type_ptr_t;
- typedef stable_vector_detail::node_type_base
- <void_ptr> node_type_base_t;
- typedef typename boost::intrusive::pointer_traits
- <void_ptr>::template
- rebind_pointer<node_type_base_t>::type node_type_base_ptr_t;
- typedef ::boost::container::vector<void_ptr,
+ typedef stable_vector_detail::node<void_ptr, T> node_type;
+ typedef typename ptr_traits::template
+ rebind_pointer<node_type>::type node_ptr;
+ typedef typename ptr_traits::template
+ rebind_pointer<node_ptr>::type node_ptr_ptr;
+ typedef stable_vector_detail::
+ node_base<node_ptr> node_base_type;
+ typedef typename ptr_traits::template
+ rebind_pointer<node_base_type>::type node_base_ptr;
+ typedef boost::intrusive::
+ pointer_traits<node_base_ptr> node_base_ptr_traits;
+ typedef boost::intrusive::
+ pointer_traits<node_ptr> node_ptr_traits;
+ typedef boost::intrusive::
+ pointer_traits<node_ptr_ptr> node_ptr_ptr_traits;
+ typedef ::boost::container::vector<node_ptr,
typename allocator_traits_type::
template portable_rebind_alloc
- <void_ptr>::type> impl_type;
+ <node_ptr>::type> impl_type;
typedef typename impl_type::iterator impl_iterator;
- typedef typename impl_type::const_iterator const_impl_iterator;
typedef ::boost::container::container_detail::
integral_constant<unsigned, 1> allocator_v1;
@@ -406,37 +406,37 @@
version<A>::value> alloc_version;
typedef typename allocator_traits_type::
template portable_rebind_alloc
- <node_type_t>::type node_allocator_type;
+ <node_type>::type node_allocator_type;
- node_type_ptr_t allocate_one()
+ node_ptr allocate_one()
{ return this->allocate_one(alloc_version()); }
template<class AllocatorVersion>
- node_type_ptr_t allocate_one(AllocatorVersion,
+ node_ptr allocate_one(AllocatorVersion,
typename boost::container::container_detail::enable_if_c
<boost::container::container_detail::is_same<AllocatorVersion, allocator_v1>
::value>::type * = 0)
{ return this->priv_node_alloc().allocate(1); }
template<class AllocatorVersion>
- node_type_ptr_t allocate_one(AllocatorVersion,
+ node_ptr allocate_one(AllocatorVersion,
typename boost::container::container_detail::enable_if_c
<!boost::container::container_detail::is_same<AllocatorVersion, allocator_v1>
::value>::type * = 0)
{ return this->priv_node_alloc().allocate_one(); }
- void deallocate_one(node_type_ptr_t p)
+ void deallocate_one(node_ptr p)
{ return this->deallocate_one(p, alloc_version()); }
template<class AllocatorVersion>
- void deallocate_one(node_type_ptr_t p, AllocatorVersion,
+ void deallocate_one(node_ptr p, AllocatorVersion,
typename boost::container::container_detail::enable_if_c
<boost::container::container_detail::is_same<AllocatorVersion, allocator_v1>
::value>::type * = 0)
{ this->priv_node_alloc().deallocate(p, 1); }
template<class AllocatorVersion>
- void deallocate_one(node_type_ptr_t p, AllocatorVersion,
+ void deallocate_one(node_ptr p, AllocatorVersion,
typename boost::container::container_detail::enable_if_c
<!boost::container::container_detail::is_same<AllocatorVersion, allocator_v1>
::value>::type * = 0)
@@ -469,11 +469,11 @@
private:
BOOST_COPYABLE_AND_MOVABLE(stable_vector)
static const size_type ExtraPointers = 3;
- //This container stores metadata at the end of the void_ptr vector with additional 3 pointers:
- // back() is impl.back() - ExtraPointers;
- // end node index is impl.end()[-3]
- // Node cache first is impl.end()[-2];
- // Node cache last is *impl.back();
+ //This container stores metadata at the end of the node_ptr vector with additional 3 pointers:
+ // back() is this->impl.back() - ExtraPointers;
+ // end node index is *(this->impl.end() -3)
+ // Node cache first is *(this->impl.end() - 2);
+ // Node cache last is this->impl.back();
typedef typename stable_vector_detail::
select_multiallocation_chain
@@ -681,7 +681,6 @@
}
//If unequal allocators, then do a one by one move
else{
- typedef typename std::iterator_traits<iterator>::iterator_category ItCat;
this->assign( boost::make_move_iterator(x.begin())
, boost::make_move_iterator(x.end()));
}
@@ -757,14 +756,13 @@
stored_allocator_type &get_stored_allocator() BOOST_CONTAINER_NOEXCEPT
{ return this->priv_node_alloc(); }
-
//! <b>Effects</b>: Returns an iterator to the first element contained in the stable_vector.
//!
//! <b>Throws</b>: Nothing.
//!
//! <b>Complexity</b>: Constant.
iterator begin()
- { return (impl.empty()) ? end(): iterator(node_ptr_cast(impl.front())) ; }
+ { return (this->impl.empty()) ? this->end(): iterator(this->impl.front()) ; }
//! <b>Effects</b>: Returns a const_iterator to the first element contained in the stable_vector.
//!
@@ -772,21 +770,21 @@
//!
//! <b>Complexity</b>: Constant.
const_iterator begin()const
- { return (impl.empty()) ? cend() : const_iterator(node_ptr_cast(impl.front())) ; }
+ { return (this->impl.empty()) ? this->cend() : const_iterator(this->impl.front()) ; }
//! <b>Effects</b>: Returns an iterator to the end of the stable_vector.
//!
//! <b>Throws</b>: Nothing.
//!
//! <b>Complexity</b>: Constant.
- iterator end() {return iterator(get_end_node());}
+ iterator end() {return iterator(this->get_end_node());}
//! <b>Effects</b>: Returns a const_iterator to the end of the stable_vector.
//!
//! <b>Throws</b>: Nothing.
//!
//! <b>Complexity</b>: Constant.
- const_iterator end()const {return const_iterator(get_end_node());}
+ const_iterator end()const {return const_iterator(this->get_end_node());}
//! <b>Effects</b>: Returns a reverse_iterator pointing to the beginning
//! of the reversed stable_vector.
@@ -856,7 +854,7 @@
//!
//! <b>Complexity</b>: Constant.
size_type size() const
- { return impl.empty() ? 0 : (impl.size() - ExtraPointers); }
+ { return this->impl.empty() ? 0 : (this->impl.size() - ExtraPointers); }
//! <b>Effects</b>: Returns the largest possible size of the stable_vector.
//!
@@ -864,7 +862,7 @@
//!
//! <b>Complexity</b>: Constant.
size_type max_size() const
- { return impl.max_size() - ExtraPointers; }
+ { return this->impl.max_size() - ExtraPointers; }
//! <b>Effects</b>: Number of elements for which memory has been allocated.
//! capacity() is always greater than or equal to size().
@@ -874,7 +872,7 @@
//! <b>Complexity</b>: Constant.
size_type capacity() const
{
- if(!impl.capacity()){
+ if(!this->impl.capacity()){
return 0;
}
else{
@@ -890,7 +888,7 @@
//!
//! <b>Complexity</b>: Constant.
bool empty() const
- { return impl.empty() || impl.size() == ExtraPointers; }
+ { return this->impl.empty() || this->impl.size() == ExtraPointers; }
//! <b>Effects</b>: Inserts or erases elements at the end such that
//! the size becomes n. New elements are copy constructed from x.
@@ -901,7 +899,7 @@
void resize(size_type n, const T& t)
{
STABLE_VECTOR_CHECK_INVARIANT;
- if(n > size())
+ if(n > this->size())
this->insert(this->cend(), n - this->size(), t);
else if(n < this->size())
this->erase(this->cbegin() + n, this->cend());
@@ -917,7 +915,7 @@
{
typedef default_construct_iterator<value_type, difference_type> default_iterator;
STABLE_VECTOR_CHECK_INVARIANT;
- if(n > size())
+ if(n > this->size())
this->insert(this->cend(), default_iterator(n - this->size()), default_iterator());
else if(n < this->size())
this->erase(this->cbegin() + n, this->cend());
@@ -940,11 +938,11 @@
if(n > old_capacity){
this->initialize_end_node(n);
const void * old_ptr = &impl[0];
- impl.reserve(n + ExtraPointers);
+ this->impl.reserve(n + ExtraPointers);
bool realloced = &impl[0] != old_ptr;
//Fix the pointers for the newly allocated buffer
if(realloced){
- this->align_nodes(impl.begin(), impl.begin()+size+1);
+ this->align_nodes(this->impl.begin(), this->impl.begin()+size+1);
}
//Now fill pool if data is not enough
if((n - size) > this->internal_data.pool_size){
@@ -961,7 +959,8 @@
//! <b>Throws</b>: Nothing.
//!
//! <b>Complexity</b>: Constant.
- reference operator[](size_type n){return value(impl[n]);}
+ reference operator[](size_type n)
+ { return this->impl[n]->value; }
//! <b>Requires</b>: size() > n.
//!
@@ -971,7 +970,8 @@
//! <b>Throws</b>: Nothing.
//!
//! <b>Complexity</b>: Constant.
- const_reference operator[](size_type n)const{return value(impl[n]);}
+ const_reference operator[](size_type n)const
+ { return this->impl[n]->value; }
//! <b>Requires</b>: size() > n.
//!
@@ -983,7 +983,7 @@
//! <b>Complexity</b>: Constant.
reference at(size_type n)
{
- if(n>=size())
+ if(n>=this->size())
throw std::out_of_range("invalid subscript at stable_vector::at");
return operator[](n);
}
@@ -998,7 +998,7 @@
//! <b>Complexity</b>: Constant.
const_reference at(size_type n)const
{
- if(n>=size())
+ if(n>=this->size())
throw std::out_of_range("invalid subscript at stable_vector::at");
return operator[](n);
}
@@ -1012,7 +1012,7 @@
//!
//! <b>Complexity</b>: Constant.
reference front()
- { return value(impl.front()); }
+ { return this->impl.front()->value; }
//! <b>Requires</b>: !empty()
//!
@@ -1023,7 +1023,7 @@
//!
//! <b>Complexity</b>: Constant.
const_reference front()const
- { return value(impl.front()); }
+ { return this->impl.front()->value; }
//! <b>Requires</b>: !empty()
//!
@@ -1034,7 +1034,7 @@
//!
//! <b>Complexity</b>: Constant.
reference back()
- { return value(*(&impl.back() - ExtraPointers)); }
+ { return (*(&this->impl.back() - ExtraPointers))->value; }
//! <b>Requires</b>: !empty()
//!
@@ -1045,7 +1045,7 @@
//!
//! <b>Complexity</b>: Constant.
const_reference back()const
- { return value(*(&impl.back() - ExtraPointers)); }
+ { return (*(&this->impl.back() - ExtraPointers))->value; }
//! <b>Effects</b>: Inserts a copy of x at the end of the stable_vector.
//!
@@ -1183,10 +1183,10 @@
difference_type d = position - this->cbegin();
if(n){
this->insert_iter_prolog(n, d);
- const impl_iterator it(impl.begin() + d);
+ const impl_iterator it(this->impl.begin() + d);
this->priv_insert_iter_fwd(it, first, last, n);
//Fix the pointers for the newly allocated buffer
- this->align_nodes(it + n, get_last_align());
+ this->align_nodes(it + n, this->get_end_align());
}
return this->begin() + d;
}
@@ -1277,10 +1277,10 @@
{
STABLE_VECTOR_CHECK_INVARIANT;
difference_type d = position - this->cbegin();
- impl_iterator it = impl.begin() + d;
+ impl_iterator it = this->impl.begin() + d;
this->delete_node(*it);
- it = impl.erase(it);
- this->align_nodes(it, get_last_align());
+ it = this->impl.erase(it);
+ this->align_nodes(it, this->get_end_align());
return this->begin()+d;
}
@@ -1295,11 +1295,11 @@
STABLE_VECTOR_CHECK_INVARIANT;
difference_type d1 = first - this->cbegin(), d2 = last - this->cbegin();
if(d1 != d2){
- impl_iterator it1(impl.begin() + d1), it2(impl.begin() + d2);
+ impl_iterator it1(this->impl.begin() + d1), it2(this->impl.begin() + d2);
for(impl_iterator it = it1; it != it2; ++it)
this->delete_node(*it);
- impl_iterator e = impl.erase(it1, it2);
- this->align_nodes(e, get_last_align());
+ impl_iterator e = this->impl.erase(it1, it2);
+ this->align_nodes(e, this->get_end_align());
}
return iterator(this->begin() + d1);
}
@@ -1342,7 +1342,7 @@
if(this->empty()){
this->impl.clear();
this->impl.shrink_to_fit();
- this->internal_data.set_end_pointer_to_default_constructed();
+ this->internal_data.end_node.up = node_ptr_ptr();
}
//Otherwise, try to shrink-to-fit the index and readjust pointers if necessary
else{
@@ -1352,7 +1352,7 @@
bool realloced = &impl[0] != old_ptr;
//Fix the pointers for the newly allocated buffer
if(realloced){
- this->align_nodes(impl.begin(), impl.begin()+size+1);
+ this->align_nodes(this->impl.begin(), this->impl.begin()+size+1);
}
}
}
@@ -1375,14 +1375,14 @@
<boost::container::container_detail::is_same<AllocatorVersion, allocator_v1>
::value>::type * = 0)
{
- if(!impl.empty() && impl.back()){
- void_ptr &pool_first_ref = impl.end()[-2];
- void_ptr &pool_last_ref = impl.back();
+ if(!this->impl.empty() && this->impl.back()){
+ node_ptr &pool_first_ref = *(this->impl.end() - 2);
+ node_ptr &pool_last_ref = this->impl.back();
multiallocation_chain holder;
holder.incorporate_after(holder.before_begin(), pool_first_ref, pool_last_ref, this->internal_data.pool_size);
while(!holder.empty()){
- node_type_ptr_t n = holder.front();
+ node_ptr n = holder.front();
holder.pop_front();
this->deallocate_one(n);
}
@@ -1397,9 +1397,9 @@
<!boost::container::container_detail::is_same<AllocatorVersion, allocator_v1>
::value>::type * = 0)
{
- if(!impl.empty() && impl.back()){
- void_ptr &pool_first_ref = impl.end()[-2];
- void_ptr &pool_last_ref = impl.back();
+ if(!this->impl.empty() && this->impl.back()){
+ node_ptr &pool_first_ref = *(this->impl.end() - 2);
+ node_ptr &pool_last_ref = this->impl.back();
multiallocation_chain holder;
holder.incorporate_after(holder.before_begin(), pool_first_ref, pool_last_ref, internal_data.pool_size);
this->priv_node_alloc().deallocate_individual(boost::move(holder));
@@ -1436,50 +1436,50 @@
<!boost::container::container_detail::is_same<AllocatorVersion, allocator_v1>
::value>::type * = 0)
{
- void_ptr &pool_first_ref = impl.end()[-2];
- void_ptr &pool_last_ref = impl.back();
+ node_ptr &pool_first_ref = *(this->impl.end() - 2);
+ node_ptr &pool_last_ref = this->impl.back();
multiallocation_chain holder;
holder.incorporate_after(holder.before_begin(), pool_first_ref, pool_last_ref, internal_data.pool_size);
//BOOST_STATIC_ASSERT((::boost::has_move_emulation_enabled<multiallocation_chain>::value == true));
multiallocation_chain m (this->priv_node_alloc().allocate_individual(n));
holder.splice_after(holder.before_begin(), m, m.before_begin(), m.last(), n);
this->internal_data.pool_size += n;
- std::pair<void_ptr, void_ptr> data(holder.extract_data());
+ std::pair<node_ptr, node_ptr> data(holder.extract_data());
pool_first_ref = data.first;
pool_last_ref = data.second;
}
- void put_in_pool(node_type_ptr_t p)
+ void put_in_pool(node_ptr p)
{
- void_ptr &pool_first_ref = impl.end()[-2];
- void_ptr &pool_last_ref = impl.back();
+ node_ptr &pool_first_ref = *(this->impl.end()-2);
+ node_ptr &pool_last_ref = this->impl.back();
multiallocation_chain holder;
holder.incorporate_after(holder.before_begin(), pool_first_ref, pool_last_ref, internal_data.pool_size);
holder.push_front(p);
++this->internal_data.pool_size;
- std::pair<void_ptr, void_ptr> ret(holder.extract_data());
+ std::pair<node_ptr, node_ptr> ret(holder.extract_data());
pool_first_ref = ret.first;
pool_last_ref = ret.second;
}
- node_type_ptr_t priv_get_from_pool()
+ node_ptr priv_get_from_pool()
{
- if(!impl.back()){
- return node_type_ptr_t(0);
+ if(!this->impl.back()){
+ return node_ptr(0);
}
else{
- void_ptr &pool_first_ref = impl.end()[-2];
- void_ptr &pool_last_ref = impl.back();
+ node_ptr &pool_first_ref = *(this->impl.end() - 2);
+ node_ptr &pool_last_ref = this->impl.back();
multiallocation_chain holder;
holder.incorporate_after(holder.before_begin(), pool_first_ref, pool_last_ref, internal_data.pool_size);
- node_type_ptr_t ret = holder.front();
+ node_ptr ret = holder.front();
holder.pop_front();
--this->internal_data.pool_size;
if(!internal_data.pool_size){
- pool_first_ref = pool_last_ref = void_ptr(0);
+ pool_first_ref = pool_last_ref = node_ptr();
}
else{
- std::pair<void_ptr, void_ptr> data(holder.extract_data());
+ std::pair<node_ptr, node_ptr> data(holder.extract_data());
pool_first_ref = data.first;
pool_last_ref = data.second;
}
@@ -1491,79 +1491,62 @@
{
initialize_end_node(n);
const void* old_ptr = &impl[0];
- //size_type old_capacity = capacity();
- //size_type old_size = size();
- impl.insert(impl.begin()+d, n, 0);
+ //size_type old_capacity = this->capacity();
+ //size_type old_size = this->size();
+ this->impl.insert(this->impl.begin()+d, n, 0);
bool realloced = &impl[0] != old_ptr;
//Fix the pointers for the newly allocated buffer
if(realloced){
- align_nodes(impl.begin(), impl.begin()+d);
+ align_nodes(this->impl.begin(), this->impl.begin()+d);
}
}
- impl_iterator get_last_align()
+ impl_iterator get_end_align()
{
- return impl.end() - (ExtraPointers - 1);
+ return this->impl.end() - (ExtraPointers - 1);
}
- const_impl_iterator get_last_align() const
- {
- return impl.cend() - (ExtraPointers - 1);
- }
-
- static node_type_ptr_t node_ptr_cast(const void_ptr &p)
- {
- return node_type_ptr_t(static_cast<node_type_t*>(container_detail::to_raw_pointer(p)));
- }
-
- static node_type_base_ptr_t node_base_ptr_cast(const void_ptr &p)
- {
- return node_type_base_ptr_t(static_cast<node_type_base_t*>(container_detail::to_raw_pointer(p)));
- }
-
- static value_type& value(const void_ptr &p)
- {
- return node_ptr_cast(p)->value;
- }
+ static node_ptr_ptr ptr_to_node_ptr(node_ptr &n)
+ { return node_ptr_ptr_traits::pointer_to(n); }
- void initialize_end_node(size_type impl_capacity = 0)
+ void initialize_end_node(const size_type impl_capacity = 0)
{
- if(impl.empty()){
- impl.reserve(impl_capacity + ExtraPointers);
- impl.resize (ExtraPointers, void_ptr(0));
- impl[0] = &this->internal_data.end_node;
- this->internal_data.end_node.up = &impl[0];
+ if(this->impl.empty()){
+ this->impl.reserve(impl_capacity + ExtraPointers);
+ this->impl.resize(ExtraPointers);
+ node_ptr &end_node_ref = impl[0];
+ end_node_ref = this->get_end_node();
+ this->internal_data.end_node.up = stable_vector::ptr_to_node_ptr(end_node_ref);
}
}
void readjust_end_node()
{
if(!this->impl.empty()){
- void_ptr &end_node_ref = *(this->get_last_align()-1);
+ node_ptr &end_node_ref = *(this->get_end_align()-1);
end_node_ref = this->get_end_node();
- this->internal_data.end_node.up = &end_node_ref;
+ this->internal_data.end_node.up = node_ptr_ptr_traits::pointer_to(end_node_ref);
}
else{
- this->internal_data.end_node.up = void_ptr(&this->internal_data.end_node.up);
+ this->internal_data.end_node.up = node_ptr_ptr();
}
}
- node_type_ptr_t get_end_node() const
+ node_ptr get_end_node() const
{
- const node_type_base_t* cp = &this->internal_data.end_node;
- node_type_base_t* p = const_cast<node_type_base_t*>(cp);
- return node_ptr_cast(p);
+ return node_ptr_traits::static_cast_from
+ (node_base_ptr_traits::pointer_to(const_cast<node_base_type&>(this->internal_data.end_node)));
}
template<class Iter>
- void_ptr new_node(const void_ptr &up, Iter it)
+ node_ptr new_node(const node_ptr_ptr &up, Iter it)
{
- node_type_ptr_t p = this->allocate_one();
+ node_ptr p = this->allocate_one();
try{
boost::container::construct_in_place(this->priv_node_alloc(), container_detail::addressof(p->value), it);
//This does not throw
- ::new(static_cast<node_type_base_t*>(container_detail::to_raw_pointer(p))) node_type_base_t;
- p->set_pointer(up);
+ ::new(static_cast<node_base_type*>(container_detail::to_raw_pointer(p))) node_base_type;
+ p->up = up;
}
catch(...){
this->deallocate_one(p);
@@ -1572,18 +1555,18 @@
return p;
}
- void delete_node(const void_ptr &p)
+ void delete_node(const node_ptr &n)
{
- node_type_ptr_t n(node_ptr_cast(p));
allocator_traits<node_allocator_type>::
destroy(this->priv_node_alloc(), container_detail::to_raw_pointer(n));
+ static_cast<node_base_type*>(container_detail::to_raw_pointer(n))->~node_base_type();
this->put_in_pool(n);
}
static void align_nodes(impl_iterator first, impl_iterator last)
{
while(first!=last){
- node_ptr_cast(*first)->up = void_ptr(&*first);
+ (*first)->up = stable_vector::ptr_to_node_ptr(*first);
++first;
}
}
@@ -1594,14 +1577,14 @@
size_type i=0;
try{
while(first!=last){
- it[i] = this->new_node(void_ptr_ptr(&it[i]), first);
+ it[i] = this->new_node(stable_vector::ptr_to_node_ptr(it[i]), first);
++first;
++i;
}
}
catch(...){
- impl_iterator e = impl.erase(it + i, it + n);
- this->align_nodes(e, get_last_align());
+ impl_iterator e = this->impl.erase(it + i, it + n);
+ this->align_nodes(e, this->get_end_align());
throw;
}
}
@@ -1612,7 +1595,7 @@
multiallocation_chain mem(this->priv_node_alloc().allocate_individual(n));
size_type i = 0;
- node_type_ptr_t p = 0;
+ node_ptr p = 0;
try{
while(first != last){
p = mem.front();
@@ -1620,8 +1603,8 @@
//This can throw
boost::container::construct_in_place(this->priv_node_alloc(), container_detail::addressof(p->value), first);
//This does not throw
- ::new(static_cast<node_type_base_t*>(container_detail::to_raw_pointer(p))) node_type_base_t;
- p->set_pointer(void_ptr_ptr(&it[i]));
+ ::new(static_cast<node_base_type*>(container_detail::to_raw_pointer(p))) node_base_type;
+ p->up = stable_vector::ptr_to_node_ptr(it[i]);
++first;
it[i] = p;
++i;
@@ -1630,8 +1613,8 @@
catch(...){
this->priv_node_alloc().deallocate_one(p);
this->priv_node_alloc().deallocate_many(boost::move(mem));
- impl_iterator e = impl.erase(it+i, it+n);
- this->align_nodes(e, get_last_align());
+ impl_iterator e = this->impl.erase(it+i, it+n);
+ this->align_nodes(e, this->get_end_align());
throw;
}
}
@@ -1640,7 +1623,7 @@
void priv_insert_iter_fwd(const impl_iterator it, FwdIterator first, FwdIterator last, difference_type n)
{
size_type i = 0;
- node_type_ptr_t p = 0;
+ node_ptr p = 0;
try{
while(first != last){
p = this->priv_get_from_pool();
@@ -1651,8 +1634,8 @@
//This can throw
boost::container::construct_in_place(this->priv_node_alloc(), container_detail::addressof(p->value), first);
//This does not throw
- ::new(static_cast<node_type_base_t*>(container_detail::to_raw_pointer(p))) node_type_base_t;
- p->set_pointer(void_ptr_ptr(&it[i]));
+ ::new(static_cast<node_base_type*>(container_detail::to_raw_pointer(p))) node_base_type;
+ p->up = stable_vector::ptr_to_node_ptr(it[i]);
++first;
it[i]=p;
++i;
@@ -1660,8 +1643,8 @@
}
catch(...){
put_in_pool(p);
- impl_iterator e = impl.erase(it+i, it+n);
- this->align_nodes(e, get_last_align());
+ impl_iterator e = this->impl.erase(it+i, it+n);
+ this->align_nodes(e, this->get_end_align());
throw;
}
}
@@ -1676,23 +1659,32 @@
#if defined(STABLE_VECTOR_ENABLE_INVARIANT_CHECKING)
bool priv_invariant()const
{
- if(impl.empty())
- return !capacity() && !size();
- if(get_end_node() != *(impl.end() - ExtraPointers)){
+ impl_type & impl_ref = const_cast<impl_type&>(this->impl);
+
+ if(impl_ref.empty())
+ return !this->capacity() && !this->size();
+ if(this->get_end_node() != *(impl_ref.end() - ExtraPointers)){
return false;
}
- for(const_impl_iterator it = impl.begin(), it_end = get_last_align(); it != it_end; ++it){
- if(const_void_ptr(node_ptr_cast(*it)->up) !=
- const_void_ptr(const_void_ptr_ptr(&*it)))
+ for( impl_iterator it = impl_ref.begin()
+ , it_end = const_cast<stable_vector&>(*this).get_end_align()
+ ; it != it_end
+ ; ++it){
+ if((*it)->up != stable_vector::ptr_to_node_ptr(*it)){
return false;
+ }
}
- size_type n = capacity()-size();
- const void_ptr &pool_head = impl.back();
+
+ size_type n = this->capacity() - this->size();
+ node_ptr &pool_first_ref = *(impl_ref.end() - 2);
+ node_ptr &pool_last_ref = impl_ref.back();
+ multiallocation_chain holder;
+ holder.incorporate_after(holder.before_begin(), pool_first_ref, pool_last_ref, internal_data.pool_size);
+ multiallocation_chain::iterator beg(holder.begin()), end(holder.end());
size_type num_pool = 0;
- node_type_ptr_t p = node_ptr_cast(pool_head);
- while(p){
+ while(beg != end){
++num_pool;
- p = node_ptr_cast(p->up);
+ ++beg;
}
return n >= num_pool;
}
@@ -1722,25 +1714,16 @@
: node_allocator_type(boost::forward<AllocatorRLValue>(a))
, pool_size(0)
, end_node()
- {
- this->set_end_pointer_to_default_constructed();
- }
+ {}
ebo_holder()
: node_allocator_type()
, pool_size(0)
, end_node()
- {
- this->set_end_pointer_to_default_constructed();
- }
-
- void set_end_pointer_to_default_constructed()
- {
- end_node.set_pointer(void_ptr(&end_node.up));
- }
+ {}
size_type pool_size;
- node_type_base_t end_node;
+ node_base_type end_node;
} internal_data;
node_allocator_type &priv_node_alloc() { return internal_data; }
@@ -1805,3 +1788,24 @@
#include <boost/container/detail/config_end.hpp>
#endif //BOOST_CONTAINER_STABLE_VECTOR_HPP
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Modified: trunk/boost/container/string.hpp
==============================================================================
--- trunk/boost/container/string.hpp (original)
+++ trunk/boost/container/string.hpp 2012-09-05 05:28:24 EDT (Wed, 05 Sep 2012)
@@ -48,6 +48,7 @@
#include <boost/move/move.hpp>
#include <boost/static_assert.hpp>
#include <boost/functional/hash.hpp>
+#include <boost/intrusive/pointer_traits.hpp>
#include <functional>
#include <string>
@@ -92,10 +93,11 @@
public:
typedef A allocator_type;
//! The stored allocator type
- typedef allocator_type stored_allocator_type;
+ typedef allocator_type stored_allocator_type;
typedef typename allocator_traits_type::pointer pointer;
typedef typename allocator_traits_type::value_type value_type;
typedef typename allocator_traits_type::size_type size_type;
+ typedef ::boost::intrusive::pointer_traits<pointer> pointer_traits;
basic_string_base()
: members_()
@@ -123,10 +125,7 @@
{
if(!this->is_short()){
this->deallocate_block();
- allocator_traits_type::destroy
- ( this->alloc()
- , static_cast<long_t*>(static_cast<void*>(&this->members_.m_repr.r))
- );
+ this->is_short(true);
}
}
@@ -198,11 +197,17 @@
long_raw_t r;
short_t s;
- short_t &short_repr() const
- { return *const_cast<short_t *>(&s); }
+ const short_t &short_repr() const
+ { return s; }
+
+ const long_t &long_repr() const
+ { return *static_cast<const long_t*>(static_cast<const void*>(&r)); }
- long_t &long_repr() const
- { return *const_cast<long_t*>(reinterpret_cast<const long_t*>(&r)); }
+ short_t &short_repr()
+ { return s; }
+
+ long_t &long_repr()
+ { return *static_cast<long_t*>(static_cast<void*>(&r)); }
};
struct members_holder
@@ -237,20 +242,22 @@
{ return static_cast<bool>(this->members_.m_repr.s.h.is_short != 0); }
void is_short(bool yes)
- {
- if(yes && !this->is_short()){
+ {
+ const bool was_short = this->is_short();
+ if(yes && !was_short){
allocator_traits_type::destroy
( this->alloc()
, static_cast<long_t*>(static_cast<void*>(&this->members_.m_repr.r))
);
+ this->members_.m_repr.s.h.is_short = true;
}
- else{
+ else if(!yes && was_short){
allocator_traits_type::construct
( this->alloc()
, static_cast<long_t*>(static_cast<void*>(&this->members_.m_repr.r))
);
+ this->members_.m_repr.s.h.is_short = false;
}
- this->members_.m_repr.s.h.is_short = yes;
}
private:
@@ -274,7 +281,7 @@
size_type &received_size, pointer reuse = 0)
{
if(this->is_short() && (command & (expand_fwd | expand_bwd)) ){
- reuse = pointer(0);
+ reuse = pointer();
command &= ~(expand_fwd | expand_bwd);
}
return this->allocation_command
@@ -292,7 +299,7 @@
(void)limit_size;
(void)reuse;
if(!(command & allocate_new))
- return std::pair<pointer, bool>(pointer(0), false);
+ return std::pair<pointer, bool>(pointer(), false);
received_size = preferred_size;
return std::make_pair(this->alloc().allocate(received_size), false);
}
@@ -353,7 +360,7 @@
pointer p = this->allocation_command(allocate_new, n, new_cap, new_cap).first;
this->is_short(false);
this->priv_long_addr(p);
- this->priv_size(0);
+ this->priv_long_size(0);
this->priv_storage(new_cap);
}
}
@@ -379,13 +386,26 @@
{ return this->priv_storage() - 1; }
pointer priv_short_addr() const
- { return pointer(&this->members_.m_repr.short_repr().data[0]); }
+ { return pointer_traits::pointer_to(const_cast<value_type&>(this->members_.m_repr.short_repr().data[0])); }
pointer priv_long_addr() const
{ return this->members_.m_repr.long_repr().start; }
pointer priv_addr() const
- { return this->is_short() ? pointer(&this->members_.m_repr.short_repr().data[0]) : this->members_.m_repr.long_repr().start; }
+ {
+ return this->is_short()
+ ? priv_short_addr()
+ : priv_long_addr()
+ ;
+ }
+
+ pointer priv_end_addr() const
+ {
+ return this->is_short()
+ ? this->priv_short_addr() + this->priv_short_size()
+ : this->priv_long_addr() + this->priv_long_size()
+ ;
+ }
void priv_long_addr(pointer addr)
{ this->members_.m_repr.long_repr().start = addr; }
@@ -411,7 +431,7 @@
}
size_type priv_size() const
- { return this->is_short() ? priv_short_size() : priv_long_size(); }
+ { return this->is_short() ? this->priv_short_size() : this->priv_long_size(); }
size_type priv_short_size() const
{ return this->members_.m_repr.short_repr().h.length; }
@@ -434,7 +454,7 @@
void priv_long_size(size_type sz)
{
- this->members_.m_repr.long_repr().length = static_cast<typename allocator_traits_type::size_type>(sz);
+ this->members_.m_repr.long_repr().length = sz;
}
void swap_data(basic_string_base& other)
@@ -444,16 +464,22 @@
container_detail::do_swap(this->members_.m_repr, other.members_.m_repr);
}
else{
- repr_t copied(this->members_.m_repr);
- this->members_.m_repr.long_repr() = other.members_.m_repr.long_repr();
- other.members_.m_repr = copied;
+ short_t short_backup(this->members_.m_repr.short_repr());
+ long_t long_backup (other.members_.m_repr.long_repr());
+ other.members_.m_repr.long_repr().~long_t();
+ ::new(&this->members_.m_repr.long_repr()) long_t;
+ this->members_.m_repr.long_repr() = long_backup;
+ other.members_.m_repr.short_repr() = short_backup;
}
}
else{
if(other.is_short()){
- repr_t copied(other.members_.m_repr);
- other.members_.m_repr.long_repr() = this->members_.m_repr.long_repr();
- this->members_.m_repr = copied;
+ short_t short_backup(other.members_.m_repr.short_repr());
+ long_t long_backup (this->members_.m_repr.long_repr());
+ this->members_.m_repr.long_repr().~long_t();
+ ::new(&other.members_.m_repr.long_repr()) long_t;
+ other.members_.m_repr.long_repr() = long_backup;
+ this->members_.m_repr.short_repr() = short_backup;
}
else{
container_detail::do_swap(this->members_.m_repr.long_repr(), other.members_.m_repr.long_repr());
@@ -581,6 +607,7 @@
typedef typename base_t::allocator_v1 allocator_v1;
typedef typename base_t::allocator_v2 allocator_v2;
typedef typename base_t::alloc_version alloc_version;
+ typedef ::boost::intrusive::pointer_traits<pointer> pointer_traits;
/// @endcond
public: // Constructor, destructor, assignment.
@@ -742,8 +769,8 @@
if(!this->is_short()){
this->deallocate_block();
this->is_short(true);
- Traits::assign(*this->priv_addr(), this->priv_null());
- this->priv_size(0);
+ Traits::assign(*this->priv_addr(), CharT(0));
+ this->priv_short_size(0);
}
}
container_detail::assign_alloc(this->alloc(), x.alloc(), flag);
@@ -818,7 +845,7 @@
//!
//! <b>Complexity</b>: Constant.
iterator end()
- { return this->priv_addr() + this->priv_size(); }
+ { return this->priv_end_addr(); }
//! <b>Effects</b>: Returns a const_iterator to the end of the vector.
//!
@@ -826,7 +853,7 @@
//!
//! <b>Complexity</b>: Constant.
const_iterator end() const
- { return this->priv_addr() + this->priv_size(); }
+ { return this->priv_end_addr(); }
//! <b>Effects</b>: Returns a const_iterator to the end of the vector.
//!
@@ -834,7 +861,7 @@
//!
//! <b>Complexity</b>: Constant.
const_iterator cend() const
- { return this->priv_addr() + this->priv_size(); }
+ { return this->priv_end_addr(); }
//! <b>Effects</b>: Returns a reverse_iterator pointing to the beginning
//! of the reversed vector.
@@ -843,7 +870,7 @@
//!
//! <b>Complexity</b>: Constant.
reverse_iterator rbegin()
- { return reverse_iterator(this->priv_addr() + this->priv_size()); }
+ { return reverse_iterator(this->priv_end_addr()); }
//! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning
//! of the reversed vector.
@@ -861,7 +888,7 @@
//!
//! <b>Complexity</b>: Constant.
const_reverse_iterator crbegin() const
- { return const_reverse_iterator(this->priv_addr() + this->priv_size()); }
+ { return const_reverse_iterator(this->priv_end_addr()); }
//! <b>Effects</b>: Returns a reverse_iterator pointing to the end
//! of the reversed vector.
@@ -950,7 +977,7 @@
//! <b>Complexity</b>: Linear to the difference between size() and new_size.
void resize(size_type n, CharT c)
{
- if (n <= size())
+ if (n <= this->size())
this->erase(this->begin() + n, this->end());
else
this->append(n - this->size(), c);
@@ -963,7 +990,7 @@
//!
//! <b>Complexity</b>: Linear to the difference between size() and new_size.
void resize(size_type n)
- { resize(n, this->priv_null()); }
+ { resize(n, CharT(0)); }
//! <b>Effects</b>: If n is less than or equal to capacity(), this call has no
//! effect. Otherwise, it is a request for allocation of additional memory.
@@ -973,8 +1000,9 @@
//! <b>Throws</b>: If memory allocation allocation throws
void reserve(size_type res_arg)
{
- if (res_arg > this->max_size())
+ if (res_arg > this->max_size()){
this->throw_length_error();
+ }
if (this->capacity() < res_arg){
size_type n = container_detail::max_value(res_arg, this->size()) + 1;
@@ -983,13 +1011,14 @@
(allocate_new, n, new_cap, new_cap).first;
size_type new_length = 0;
+ const pointer addr = this->priv_addr();
new_length += priv_uninitialized_copy
- (this->priv_addr(), this->priv_addr() + this->priv_size(), new_start);
+ (addr, addr + this->priv_size(), new_start);
this->priv_construct_null(new_start + new_length);
this->deallocate_block();
this->is_short(false);
this->priv_long_addr(new_start);
- this->priv_size(new_length);
+ this->priv_long_size(new_length);
this->priv_storage(new_cap);
}
}
@@ -1010,8 +1039,8 @@
//! <b>Complexity</b>: Linear to the number of elements in the vector.
void clear()
{
- if (!empty()) {
- Traits::assign(*this->priv_addr(), this->priv_null());
+ if (!this->empty()) {
+ Traits::assign(*this->priv_addr(), CharT(0));
this->priv_size(0);
}
}
@@ -1028,7 +1057,7 @@
if(this->priv_storage() > InternalBufferChars){
//Check if we should pass from dynamically allocated buffer
//to the internal storage
- if(this->priv_size() < (InternalBufferChars)){
+ if(this->priv_size() < InternalBufferChars){
//Dynamically allocated buffer attributes
pointer long_addr = this->priv_long_addr();
size_type long_storage = this->priv_long_storage();
@@ -1085,9 +1114,10 @@
//! <b>Throws</b>: std::range_error if n >= size()
//!
//! <b>Complexity</b>: Constant.
- reference at(size_type n) {
- if (n >= size())
- this->throw_out_of_range();
+ reference at(size_type n)
+ {
+ if (n >= this->size())
+ this->throw_out_of_range();
return *(this->priv_addr() + n);
}
@@ -1100,7 +1130,7 @@
//!
//! <b>Complexity</b>: Constant.
const_reference at(size_type n) const {
- if (n >= size())
+ if (n >= this->size())
this->throw_out_of_range();
return *(this->priv_addr() + n);
}
@@ -1186,13 +1216,14 @@
{
const size_type old_size = this->priv_size();
if (old_size < this->capacity()){
- this->priv_construct_null(this->priv_addr() + old_size + 1);
- Traits::assign(this->priv_addr()[old_size], c);
+ const pointer addr = this->priv_addr();
+ this->priv_construct_null(addr + old_size + 1);
+ Traits::assign(addr[old_size], c);
this->priv_size(old_size+1);
}
else{
//No enough memory, insert a new object at the end
- this->append((size_type)1, c);
+ this->append(size_type(1), c);
}
}
@@ -1266,7 +1297,8 @@
)
{
size_type cur = 0;
- CharT *ptr = container_detail::to_raw_pointer(this->priv_addr());
+ const pointer addr = this->priv_addr();
+ CharT *ptr = container_detail::to_raw_pointer(addr);
const size_type old_size = this->priv_size();
while (first != last && cur != old_size) {
Traits::assign(*ptr, *first);
@@ -1275,7 +1307,7 @@
++ptr;
}
if (first == last)
- this->erase(this->priv_addr() + cur, this->priv_addr() + old_size);
+ this->erase(addr + cur, addr + old_size);
else
this->append(first, last);
return *this;
@@ -1290,9 +1322,10 @@
//! <b>Returns</b>: *this
basic_string& insert(size_type pos, const basic_string& s)
{
- if (pos > size())
+ const size_type size = this->size();
+ if (pos > size)
this->throw_out_of_range();
- if (this->size() > this->max_size() - s.size())
+ if (size > this->max_size() - s.size())
this->throw_length_error();
this->insert(this->priv_addr() + pos, s.begin(), s.end());
return *this;
@@ -1308,10 +1341,12 @@
//! <b>Returns</b>: *this
basic_string& insert(size_type pos1, const basic_string& s, size_type pos2, size_type n)
{
- if (pos1 > this->size() || pos2 > s.size())
+ const size_type size = this->size();
+ const size_type str_size = s.size();
+ if (pos1 > size || pos2 > str_size)
this->throw_out_of_range();
- size_type len = container_detail::min_value(n, s.size() - pos2);
- if (this->size() > this->max_size() - len)
+ size_type len = container_detail::min_value(n, str_size - pos2);
+ if (size > this->max_size() - len)
this->throw_length_error();
const CharT *beg_ptr = container_detail::to_raw_pointer(s.begin()) + pos2;
const CharT *end_ptr = beg_ptr + len;
@@ -1350,7 +1385,7 @@
//! <b>Returns</b>: *this
basic_string& insert(size_type pos, const CharT* s)
{
- if (pos > size())
+ if (pos > this->size())
this->throw_out_of_range();
size_type len = Traits::length(s);
if (this->size() > this->max_size() - len)
@@ -1457,11 +1492,11 @@
//Reuse same buffer
if(enough_capacity){
- const size_type elems_after = old_size - (p - this->priv_addr());
+ const size_type elems_after = old_size - (p - old_start);
const size_type old_length = old_size;
if (elems_after >= n) {
- const pointer pointer_past_last = this->priv_addr() + old_size + 1;
- priv_uninitialized_copy(this->priv_addr() + (old_size - n + 1),
+ const pointer pointer_past_last = old_start + old_size + 1;
+ priv_uninitialized_copy(old_start + (old_size - n + 1),
pointer_past_last, pointer_past_last);
this->priv_size(old_size+n);
@@ -1474,12 +1509,13 @@
ForwardIter mid = first;
std::advance(mid, elems_after + 1);
- priv_uninitialized_copy(mid, last, this->priv_addr() + old_size + 1);
- this->priv_size(old_size + (n - elems_after));
+ priv_uninitialized_copy(mid, last, old_start + old_size + 1);
+ const size_type newer_size = old_size + (n - elems_after);
+ this->priv_size(newer_size);
priv_uninitialized_copy
- (p, const_iterator(this->priv_addr() + old_length + 1),
- this->priv_addr() + this->priv_size());
- this->priv_size(this->priv_size() + elems_after);
+ (p, const_iterator(old_start + old_length + 1),
+ old_start + newer_size);
+ this->priv_size(newer_size + elems_after);
this->priv_copy(first, mid, const_cast<CharT*>(container_detail::to_raw_pointer(p)));
}
}
@@ -1490,11 +1526,11 @@
size_type new_length = 0;
//This can't throw, since characters are POD
new_length += priv_uninitialized_copy
- (const_iterator(this->priv_addr()), p, new_start);
+ (const_iterator(old_start), p, new_start);
new_length += priv_uninitialized_copy
(first, last, new_start + new_length);
new_length += priv_uninitialized_copy
- (p, const_iterator(this->priv_addr() + old_size),
+ (p, const_iterator(old_start + old_size),
new_start + new_length);
this->priv_construct_null(new_start + new_length);
@@ -1542,9 +1578,10 @@
//! <b>Returns</b>: *this
basic_string& erase(size_type pos = 0, size_type n = npos)
{
- if (pos > size())
+ if (pos > this->size())
this->throw_out_of_range();
- erase(this->priv_addr() + pos, this->priv_addr() + pos + container_detail::min_value(n, size() - pos));
+ const pointer addr = this->priv_addr();
+ erase(addr + pos, addr + pos + container_detail::min_value(n, this->size() - pos));
return *this;
}
@@ -1597,7 +1634,7 @@
void pop_back()
{
const size_type old_size = this->priv_size();
- Traits::assign(this->priv_addr()[old_size-1], this->priv_null());
+ Traits::assign(this->priv_addr()[old_size-1], CharT(0));
this->priv_size(old_size-1);;
}
@@ -1610,13 +1647,14 @@
//! <b>Returns</b>: *this
basic_string& replace(size_type pos1, size_type n1, const basic_string& str)
{
- if (pos1 > size())
+ if (pos1 > this->size())
this->throw_out_of_range();
- const size_type len = container_detail::min_value(n1, size() - pos1);
+ const size_type len = container_detail::min_value(n1, this->size() - pos1);
if (this->size() - len >= this->max_size() - str.size())
this->throw_length_error();
- return this->replace( const_iterator(this->priv_addr() + pos1)
- , const_iterator(this->priv_addr() + pos1 + len)
+ const pointer addr = this->priv_addr();
+ return this->replace( const_iterator(addr + pos1)
+ , const_iterator(addr + pos1 + len)
, str.begin(), str.end());
}
@@ -1632,14 +1670,16 @@
basic_string& replace(size_type pos1, size_type n1,
const basic_string& str, size_type pos2, size_type n2)
{
- if (pos1 > size() || pos2 > str.size())
+ if (pos1 > this->size() || pos2 > str.size())
this->throw_out_of_range();
- const size_type len1 = container_detail::min_value(n1, size() - pos1);
+ const size_type len1 = container_detail::min_value(n1, this->size() - pos1);
const size_type len2 = container_detail::min_value(n2, str.size() - pos2);
if (this->size() - len1 >= this->max_size() - len2)
this->throw_length_error();
- return this->replace(this->priv_addr() + pos1, this->priv_addr() + pos1 + len1,
- str.priv_addr() + pos2, str.priv_addr() + pos2 + len2);
+ const pointer addr = this->priv_addr();
+ const pointer straddr = str.priv_addr();
+ return this->replace(addr + pos1, addr + pos1 + len1,
+ straddr + pos2, straddr + pos2 + len2);
}
//! <b>Requires</b>: pos1 <= size() and s points to an array of at least n2 elements of CharT.
@@ -1658,12 +1698,13 @@
//! <b>Returns</b>: *this
basic_string& replace(size_type pos1, size_type n1, const CharT* s, size_type n2)
{
- if (pos1 > size())
+ if (pos1 > this->size())
this->throw_out_of_range();
- const size_type len = container_detail::min_value(n1, size() - pos1);
+ const size_type len = container_detail::min_value(n1, this->size() - pos1);
if (n2 > this->max_size() || size() - len >= this->max_size() - n2)
this->throw_length_error();
- return this->replace(this->priv_addr() + pos1, this->priv_addr() + pos1 + len, s, s + n2);
+ const pointer addr = this->priv_addr();
+ return this->replace(addr + pos1, addr + pos1 + len, s, s + n2);
}
//! <b>Requires</b>: pos1 <= size() and s points to an array of at least n2 elements of CharT.
@@ -1682,13 +1723,14 @@
//! <b>Returns</b>: *this
basic_string& replace(size_type pos, size_type n1, const CharT* s)
{
- if (pos > size())
+ if (pos > this->size())
this->throw_out_of_range();
- const size_type len = container_detail::min_value(n1, size() - pos);
+ const size_type len = container_detail::min_value(n1, this->size() - pos);
const size_type n2 = Traits::length(s);
- if (n2 > this->max_size() || size() - len >= this->max_size() - n2)
+ if (n2 > this->max_size() || this->size() - len >= this->max_size() - n2)
this->throw_length_error();
- return this->replace(this->priv_addr() + pos, this->priv_addr() + pos + len,
+ const pointer addr = this->priv_addr();
+ return this->replace(addr + pos, addr + pos + len,
s, s + Traits::length(s));
}
@@ -1702,12 +1744,13 @@
//! <b>Returns</b>: *this
basic_string& replace(size_type pos1, size_type n1, size_type n2, CharT c)
{
- if (pos1 > size())
+ if (pos1 > this->size())
this->throw_out_of_range();
- const size_type len = container_detail::min_value(n1, size() - pos1);
- if (n2 > this->max_size() || size() - len >= this->max_size() - n2)
+ const size_type len = container_detail::min_value(n1, this->size() - pos1);
+ if (n2 > this->max_size() || this->size() - len >= this->max_size() - n2)
this->throw_length_error();
- return this->replace(this->priv_addr() + pos1, this->priv_addr() + pos1 + len, n2, c);
+ const pointer addr = this->priv_addr();
+ return this->replace(addr + pos1, addr + pos1 + len, n2, c);
}
//! <b>Requires</b>: [begin(),i1) and [i1,i2) are valid ranges.
@@ -1829,9 +1872,9 @@
//! <b>Returns</b>: rlen
size_type copy(CharT* s, size_type n, size_type pos = 0) const
{
- if (pos > size())
+ if (pos > this->size())
this->throw_out_of_range();
- const size_type len = container_detail::min_value(n, size() - pos);
+ const size_type len = container_detail::min_value(n, this->size() - pos);
Traits::copy(s, container_detail::to_raw_pointer(this->priv_addr() + pos), len);
return len;
}
@@ -1880,12 +1923,13 @@
//! <b>Returns</b>: find(basic_string<CharT,traits,Allocator>(s,n),pos).
size_type find(const CharT* s, size_type pos, size_type n) const
{
- if (pos + n > size())
+ if (pos + n > this->size())
return npos;
else {
- pointer finish = this->priv_addr() + this->priv_size();
+ const pointer addr = this->priv_addr();
+ pointer finish = addr + this->priv_size();
const const_iterator result =
- std::search(container_detail::to_raw_pointer(this->priv_addr() + pos),
+ std::search(container_detail::to_raw_pointer(addr + pos),
container_detail::to_raw_pointer(finish),
s, s + n, Eq_traits<Traits>());
return result != finish ? result - begin() : npos;
@@ -1898,19 +1942,21 @@
//!
//! <b>Returns</b>: find(basic_string(s), pos).
size_type find(const CharT* s, size_type pos = 0) const
- { return find(s, pos, Traits::length(s)); }
+ { return this->find(s, pos, Traits::length(s)); }
//! <b>Throws</b>: Nothing
//!
//! <b>Returns</b>: find(basic_string<CharT,traits,Allocator>(1,c), pos).
size_type find(CharT c, size_type pos = 0) const
{
- if (pos >= size())
+ const size_type size = this->size();
+ if (pos >= size)
return npos;
else {
- pointer finish = this->priv_addr() + this->priv_size();
+ const pointer addr = this->priv_addr();
+ pointer finish = addr + size;
const const_iterator result =
- std::find_if(this->priv_addr() + pos, finish,
+ std::find_if(addr + pos, finish,
std::bind2nd(Eq_traits<Traits>(), c));
return result != finish ? result - begin() : npos;
}
@@ -1934,7 +1980,7 @@
//! <b>Returns</b>: rfind(basic_string(s, n), pos).
size_type rfind(const CharT* s, size_type pos, size_type n) const
{
- const size_type len = size();
+ const size_type len = this->size();
if (n > len)
return npos;
@@ -1963,7 +2009,7 @@
//! <b>Returns</b>: rfind(basic_string<CharT,traits,Allocator>(1,c),pos).
size_type rfind(CharT c, size_type pos = npos) const
{
- const size_type len = size();
+ const size_type len = this->size();
if (len < 1)
return npos;
@@ -1993,14 +2039,15 @@
//! <b>Returns</b>: find_first_of(basic_string(s, n), pos).
size_type find_first_of(const CharT* s, size_type pos, size_type n) const
{
- if (pos >= size())
+ const size_type size = this->size();
+ if (pos >= size)
return npos;
else {
- pointer finish = this->priv_addr() + this->priv_size();
- const_iterator result = std::find_first_of(this->priv_addr() + pos, finish,
- s, s + n,
- Eq_traits<Traits>());
- return result != finish ? result - begin() : npos;
+ const pointer addr = this->priv_addr();
+ pointer finish = addr + size;
+ const_iterator result = std::find_first_of
+ (addr + pos, finish, s, s + n, Eq_traits<Traits>());
+ return result != finish ? result - this->begin() : npos;
}
}
@@ -2037,17 +2084,17 @@
//! <b>Returns</b>: find_last_of(basic_string(s, n), pos).
size_type find_last_of(const CharT* s, size_type pos, size_type n) const
{
- const size_type len = size();
+ const size_type len = this->size();
if (len < 1)
return npos;
else {
- const const_iterator last = this->priv_addr() + container_detail::min_value(len - 1, pos) + 1;
+ const pointer addr = this->priv_addr();
+ const const_iterator last = addr + container_detail::min_value(len - 1, pos) + 1;
const const_reverse_iterator rresult =
std::find_first_of(const_reverse_iterator(last), rend(),
- s, s + n,
- Eq_traits<Traits>());
- return rresult != rend() ? (rresult.base() - 1) - this->priv_addr() : npos;
+ s, s + n, Eq_traits<Traits>());
+ return rresult != rend() ? (rresult.base() - 1) - addr : npos;
}
}
@@ -2083,13 +2130,14 @@
//! <b>Returns</b>: find_first_not_of(basic_string(s, n), pos).
size_type find_first_not_of(const CharT* s, size_type pos, size_type n) const
{
- if (pos > size())
+ if (pos > this->size())
return npos;
else {
- const pointer finish = this->priv_addr() + this->priv_size();
- const const_iterator result = std::find_if(this->priv_addr() + pos, finish,
- Not_within_traits<Traits>(s, s + n));
- return result != finish ? result - this->priv_addr() : npos;
+ const pointer addr = this->priv_addr();
+ const pointer finish = addr + this->priv_size();
+ const const_iterator result = std::find_if
+ (addr + pos, finish, Not_within_traits<Traits>(s, s + n));
+ return result != finish ? result - addr : npos;
}
}
@@ -2106,12 +2154,13 @@
//! <b>Returns</b>: find_first_not_of(basic_string(1, c), pos).
size_type find_first_not_of(CharT c, size_type pos = 0) const
{
- if (pos > size())
+ if (pos > this->size())
return npos;
else {
- const pointer finish = this->priv_addr() + this->priv_size();
+ const pointer addr = this->priv_addr();
+ const pointer finish = addr + this->priv_size();
const const_iterator result
- = std::find_if(this->priv_addr() + pos, finish,
+ = std::find_if(addr + pos, finish,
std::not1(std::bind2nd(Eq_traits<Traits>(), c)));
return result != finish ? result - begin() : npos;
}
@@ -2134,7 +2183,7 @@
//! <b>Returns</b>: find_last_not_of(basic_string(s, n), pos).
size_type find_last_not_of(const CharT* s, size_type pos, size_type n) const
{
- const size_type len = size();
+ const size_type len = this->size();
if (len < 1)
return npos;
@@ -2160,7 +2209,7 @@
//! <b>Returns</b>: find_last_not_of(basic_string(1, c), pos).
size_type find_last_not_of(CharT c, size_type pos = npos) const
{
- const size_type len = size();
+ const size_type len = this->size();
if (len < 1)
return npos;
@@ -2183,10 +2232,11 @@
//! <b>Returns</b>: basic_string<CharT,traits,Allocator>(data()+pos,rlen).
basic_string substr(size_type pos = 0, size_type n = npos) const
{
- if (pos > size())
+ if (pos > this->size())
this->throw_out_of_range();
- return basic_string(this->priv_addr() + pos,
- this->priv_addr() + pos + container_detail::min_value(n, size() - pos), this->alloc());
+ const pointer addr = this->priv_addr();
+ return basic_string(addr + pos,
+ addr + pos + container_detail::min_value(n, size() - pos), this->alloc());
}
//! <b>Effects</b>: Determines the effective length rlen of the string to copy as
@@ -2199,7 +2249,11 @@
//! Otherwise, returns a value < 0 if size() < str.size(), a 0 value if size() == str.size(),
//! and value > 0 if size() > str.size()
int compare(const basic_string& str) const
- { return s_compare(this->priv_addr(), this->priv_addr() + this->priv_size(), str.priv_addr(), str.priv_addr() + str.priv_size()); }
+ {
+ const pointer addr = this->priv_addr();
+ const pointer str_addr = str.priv_addr();
+ return s_compare(addr, addr + this->priv_size(), str_addr, str_addr + str.priv_size());
+ }
//! <b>Requires</b>: pos1 <= size()
//!
@@ -2211,11 +2265,13 @@
//! <b>Returns</b>:basic_string(*this,pos1,n1).compare(str).
int compare(size_type pos1, size_type n1, const basic_string& str) const
{
- if (pos1 > size())
+ if (pos1 > this->size())
this->throw_out_of_range();
- return s_compare(this->priv_addr() + pos1,
- this->priv_addr() + pos1 + container_detail::min_value(n1, size() - pos1),
- str.priv_addr(), str.priv_addr() + str.priv_size());
+ const pointer addr = this->priv_addr();
+ const pointer str_addr = str.priv_addr();
+ return s_compare(addr + pos1,
+ addr + pos1 + container_detail::min_value(n1, this->size() - pos1),
+ str_addr, str_addr + str.priv_size());
}
//! <b>Requires</b>: pos1 <= size() and pos2 <= str.size()
@@ -2228,19 +2284,24 @@
//! <b>Returns</b>: basic_string(*this, pos1, n1).compare(basic_string(str, pos2, n2)).
int compare(size_type pos1, size_type n1,
const basic_string& str, size_type pos2, size_type n2) const {
- if (pos1 > size() || pos2 > str.size())
+ if (pos1 > this->size() || pos2 > str.size())
this->throw_out_of_range();
- return s_compare(this->priv_addr() + pos1,
- this->priv_addr() + pos1 + container_detail::min_value(n1, size() - pos1),
- str.priv_addr() + pos2,
- str.priv_addr() + pos2 + container_detail::min_value(n2, size() - pos2));
+ const pointer addr = this->priv_addr();
+ const pointer str_addr = str.priv_addr();
+ return s_compare(addr + pos1,
+ addr + pos1 + container_detail::min_value(n1, this->size() - pos1),
+ str_addr + pos2,
+ str_addr + pos2 + container_detail::min_value(n2, str.size() - pos2));
}
//! <b>Throws</b>: Nothing
//!
//! <b>Returns</b>: compare(basic_string(s)).
int compare(const CharT* s) const
- { return s_compare(this->priv_addr(), this->priv_addr() + this->priv_size(), s, s + Traits::length(s)); }
+ {
+ const pointer addr = this->priv_addr();
+ return s_compare(addr, addr + this->priv_size(), s, s + Traits::length(s));
+ }
//! <b>Requires</b>: pos1 > size() and s points to an array of at least n2 elements of CharT.
@@ -2251,10 +2312,11 @@
int compare(size_type pos1, size_type n1,
const CharT* s, size_type n2) const
{
- if (pos1 > size())
+ if (pos1 > this->size())
this->throw_out_of_range();
- return s_compare(this->priv_addr() + pos1,
- this->priv_addr() + pos1 + container_detail::min_value(n1, size() - pos1),
+ const pointer addr = this->priv_addr();
+ return s_compare( addr + pos1,
+ addr + pos1 + container_detail::min_value(n1, this->size() - pos1),
s, s + n2);
}
@@ -2322,15 +2384,12 @@
}
void priv_construct_null(pointer p)
- { this->construct(p, 0); }
-
- static CharT priv_null()
- { return (CharT) 0; }
+ { this->construct(p, CharT(0)); }
// Helper functions used by constructors. It is a severe error for
// any of them to be called anywhere except from within constructors.
void priv_terminate_string()
- { this->priv_construct_null(this->priv_addr() + this->priv_size()); }
+ { this->priv_construct_null(this->priv_end_addr()); }
template<class FwdIt, class Count> inline
void priv_uninitialized_fill_n(FwdIt first, Count count, const CharT val)
@@ -2377,26 +2436,7 @@
BOOST_CATCH_END
return (constructed);
}
-/*
- template <class InputIter>
- basic_string& priv_assign_dispatch(InputIter f, InputIter l, container_detail::false_)
- {
- size_type cur = 0;
- CharT *ptr = container_detail::to_raw_pointer(this->priv_addr());
- const size_type old_size = this->priv_size();
- while (f != l && cur != old_size) {
- Traits::assign(*ptr, *f);
- ++f;
- ++cur;
- ++ptr;
- }
- if (f == l)
- this->erase(this->priv_addr() + cur, this->priv_addr() + old_size);
- else
- this->append(f, l);
- return *this;
- }
-*/
+
template <class InputIterator, class OutIterator>
void priv_copy(InputIterator first, InputIterator last, OutIterator result)
{
Modified: trunk/libs/container/test/check_equal_containers.hpp
==============================================================================
--- trunk/libs/container/test/check_equal_containers.hpp (original)
+++ trunk/libs/container/test/check_equal_containers.hpp 2012-09-05 05:28:24 EDT (Wed, 05 Sep 2012)
@@ -58,13 +58,8 @@
}
std::size_t i = 0;
for(; itboost != itboostend; ++itboost, ++itstd, ++i){
-
if(!CheckEqual(*itstd, *itboost))
return false;
-/* value_type val(*itstd);
- const value_type &v = *itboost;
- if(v != val)
- return false;*/
}
return true;
}
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk