90 typedef std::size_t size_type;
91 typedef std::ptrdiff_t difference_type;
92 typedef std::reverse_iterator<iterator> reverse_iterator;
93 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
158 if(data_ !=
rhs.data_)
180 if(data_ !=
rhs.data_)
203 "ArrayVectorView::subarray(): Limits out of range.");
267 return (reverse_iterator(
end()));
272 inline const_reverse_iterator
rbegin()
const
274 return (const_reverse_iterator(
end()));
281 return (reverse_iterator(
begin()));
286 inline const_reverse_iterator
rend()
const
288 return (const_reverse_iterator(
begin()));
295 return (const_reverse_iterator(
end()));
300 inline const_reverse_iterator
crend()
const
302 return (const_reverse_iterator(
begin()));
323 return data_[size_-1];
330 return data_[size_-1];
337 VIGRA_ASSERT_INSIDE(
i);
345 VIGRA_ASSERT_INSIDE(
i);
382 return p >= 0 && p < size_;
407 else if(data_ !=
rhs.data_)
418 for(size_type
k=0;
k<
size(); ++
k)
419 if(data_[
k] !=
rhs[
k])
428 vigra_precondition (size() ==
rhs.
size(),
429 "ArrayVectorView::copy(): shape mismatch.");
433 if(data_ <=
rhs.data())
439 std::copy_backward(rhs.begin(), rhs.end(), end());
446ArrayVectorView <T>::copyImpl(
const ArrayVectorView <U>& rhs)
448 vigra_precondition (size() == rhs.size(),
449 "ArrayVectorView::copy(): shape mismatch.");
450 std::copy(rhs.begin(), rhs.end(), begin());
456ArrayVectorView <T>::swapDataImpl(
const ArrayVectorView <U>& rhs)
458 vigra_precondition (size () == rhs.size() (),
459 "ArrayVectorView::swapData(): size mismatch.");
462 if(data_ + size_ <= rhs.data_ || rhs.data_ + size_ <= data_)
464 for(size_type k=0; k<size_; ++k)
465 std::swap(data_[k], rhs.data_[k]);
469 ArrayVector<T> t(*
this);
511template <
class T,
class Alloc >
516 enum { minimumCapacity = 2, resizeFactor = 2 };
521 typedef typename view_type::reference reference;
523 typedef typename view_type::pointer pointer;
525 typedef typename view_type::iterator iterator;
527 typedef typename view_type::size_type size_type;
528 typedef typename view_type::difference_type difference_type;
529 typedef typename view_type::reverse_iterator reverse_iterator;
530 typedef typename view_type::const_reverse_iterator const_reverse_iterator;
536 capacity_(minimumCapacity),
539 this->data_ = reserve_raw(capacity_);
544 capacity_(minimumCapacity),
547 this->data_ = reserve_raw(capacity_);
554 initImpl(
size, value_type(), VigraTrueType());
580 template <
class InputIterator>
583 initImpl(
i,
end,
typename NumericTraits<InputIterator>::isIntegral());
586 template <
class InputIterator>
590 initImpl(
i,
end,
typename NumericTraits<InputIterator>::isIntegral());
597 if(this->size_ ==
rhs.size_)
612 deallocate(this->data_, this->size_, this->capacity_);
617 void push_back( value_type
const & t );
619 iterator insert(iterator p, value_type
const & v);
621 iterator insert(iterator p, size_type n, value_type
const & v);
623 template <
class InputIterator>
626 iterator erase(iterator p);
628 iterator erase(iterator p, iterator
q);
634 pointer reserveImpl(
bool dealloc);
653 size_type capacity()
const
662 void deallocate(pointer
data, size_type
size, size_type capacity);
664 pointer reserve_raw(size_type capacity);
666 void initImpl( size_type
size, value_type
const &
initial, VigraTrueType );
668 template <
class Iter>
669 void initImpl( Iter
i, Iter
end, VigraFalseType );
671 template <
class Iter>
672 void initImpl( Iter
i, Iter
end, Error_NumericTraits_not_specialized_for_this_case)
674 initImpl(
i,
end, VigraFalseType());
681template <
class T,
class Alloc>
695template <
class T,
class Alloc>
696inline void ArrayVector<T, Alloc>::pop_back()
699 alloc_.destroy(this->data_ + this->size_);
702template <
class T,
class Alloc>
703inline void ArrayVector<T, Alloc>::push_back( value_type
const & t )
706 pointer
old_data = reserveImpl(
false);
707 alloc_.construct(this->data_ + this->size_, t);
714template <
class T,
class Alloc>
715inline void ArrayVector<T, Alloc>::clear()
717 detail::destroy_n(this->data_, this->size_);
721template <
class T,
class Alloc>
722typename ArrayVector<T, Alloc>::iterator
723ArrayVector<T, Alloc>::insert(iterator p, value_type
const & v)
725 difference_type pos = p - this->
begin();
729 p = this->
begin() + pos;
735 p = this->
begin() + pos;
736 std::copy_backward(p, this->
end() - 2, this->
end() - 1);
742template <
class T,
class Alloc>
743typename ArrayVector<T, Alloc>::iterator
744ArrayVector<T, Alloc>::insert(iterator p, size_type n, value_type
const & v)
746 difference_type pos = p - this->
begin();
756 std::uninitialized_copy(p, this->
end(), new_data + pos + n);
763 deallocate(this->data_, this->size_, this->capacity_);
767 else if(pos + n > this->size_)
769 size_type diff = pos + n - this->size_;
770 std::uninitialized_copy(p, this->
end(), this->
end() + diff);
771 std::uninitialized_fill(this->
end(), this->
end() + diff, v);
772 std::fill(p, this->
end(), v);
776 size_type diff = this->size_ - (pos + n);
777 std::uninitialized_copy(this->
end() - n, this->
end(), this->
end());
778 std::copy_backward(p, p + diff, this->
end());
779 std::fill(p, p + n, v);
782 return this->
begin() + pos;
785template <
class T,
class Alloc>
786template <
class InputIterator>
787typename ArrayVector<T, Alloc>::iterator
788ArrayVector<T, Alloc>::insert(iterator p, InputIterator i, InputIterator iend)
790 size_type n = std::distance(
i,
iend);
791 size_type pos = p - this->
begin();
801 std::uninitialized_copy(p, this->
end(), new_data + pos + n);
808 deallocate(this->data_, this->size_, this->capacity_);
812 else if(pos + n > this->size_)
814 size_type diff = pos + n - this->size_;
815 std::uninitialized_copy(p, this->
end(), this->
end() + diff);
817 std::advance(split, n - diff);
818 std::uninitialized_copy(split,
iend, this->
end());
819 std::copy(
i, split, p);
823 size_type diff = this->size_ - (pos + n);
824 std::uninitialized_copy(this->
end() - n, this->
end(), this->
end());
825 std::copy_backward(p, p + diff, this->
end());
826 std::copy(
i,
iend, p);
829 return this->
begin() + pos;
832template <
class T,
class Alloc>
833typename ArrayVector<T, Alloc>::iterator
834ArrayVector<T, Alloc>::erase(iterator p)
836 std::copy(p+1, this->
end(), p);
841template <
class T,
class Alloc>
842typename ArrayVector<T, Alloc>::iterator
843ArrayVector<T, Alloc>::erase(iterator p, iterator q)
845 std::copy(
q, this->
end(), p);
852template <
class T,
class Alloc>
853typename ArrayVector<T, Alloc>::pointer
854ArrayVector<T, Alloc>::reserveImpl(
bool dealloc, size_type new_capacity)
868 deallocate(
old_data, this->size_, this->capacity_);
873template <
class T,
class Alloc>
874inline typename ArrayVector<T, Alloc>::pointer
875ArrayVector<T, Alloc>::reserveImpl(
bool dealloc)
878 return reserveImpl(
dealloc, minimumCapacity);
879 else if(this->size_ == capacity_)
880 return reserveImpl(
dealloc, resizeFactor*capacity_);
885template <
class T,
class Alloc>
887ArrayVector<T, Alloc>::resize( size_type new_size, value_type
const & initial)
890 erase(this->
begin() + new_size, this->
end());
893 insert(this->
end(), new_size - this->
size(), initial);
897template <
class T,
class Alloc>
899ArrayVector<T, Alloc>::initImpl( size_type size, value_type
const & initial, VigraTrueType )
903 this->data_ = reserve_raw(capacity_);
905 std::uninitialized_fill(this->data_, this->data_+this->size_,
initial);
908template <
class T,
class Alloc>
911ArrayVector<T, Alloc>::initImpl( Iter i, Iter end, VigraFalseType )
913 this->size_ = std::distance(
i,
end);
914 capacity_ = this->size_;
915 this->data_ = reserve_raw(capacity_);
917 detail::uninitializedCopy(
i,
end, this->data_);
920template <
class T,
class Alloc>
922ArrayVector<T, Alloc>::swap(this_type & rhs)
924 std::swap(this->size_,
rhs.size_);
925 std::swap(capacity_,
rhs.capacity_);
926 std::swap(this->data_,
rhs.data_);
929template <
class T,
class Alloc>
931ArrayVector<T, Alloc>::deallocate(pointer data, size_type size, size_type capacity)
935 detail::destroy_n(data,
size);
936 alloc_.deallocate(data, capacity);
940template <
class T,
class Alloc>
941inline typename ArrayVector<T, Alloc>::pointer
942ArrayVector<T, Alloc>::reserve_raw(size_type capacity)
947 data = alloc_.allocate(capacity);
959 for(std::ptrdiff_t k=0; k<(std::ptrdiff_t)a.
size()-1; ++k)
968#undef VIGRA_ASSERT_INSIDE