1 /* $XConsortium: Vector.C /main/3 1996/08/17 08:15:28 mgreess $ */
2 // Copyright (c) 1994, 1996 James Clark
3 // See the file COPYING for copying permission.
5 #ifndef Vector_DEF_INCLUDED
6 #define Vector_DEF_INCLUDED 1
11 #ifdef SP_QUAL_TEMPLATE_DTOR_BROKEN
18 namespace SP_NAMESPACE {
25 erase(ptr_, ptr_ + size_);
26 ::operator delete((void *)ptr_);
31 Vector<T>::Vector(const Vector<T> &v)
32 : ptr_(0), size_(0), alloc_(0)
34 insert(ptr_ + size_, v.ptr_, v.ptr_ + v.size_);
38 Vector<T>::Vector(size_t n, const T &t)
39 : ptr_(0), size_(0), alloc_(0)
41 insert(ptr_ + size_, n, t);
45 Vector<T> &Vector<T>::operator=(const Vector<T> &v)
51 insert(ptr_ + size_, v.ptr_ + size_, v.ptr_ + v.size_);
54 erase(ptr_ + n, ptr_ + size_);
62 void Vector<T>::assign(size_t n, const T &t)
67 insert(ptr_ + size_, n - size_, t);
70 erase(ptr_ + n, ptr_ + size_);
76 void Vector<T>::insert(const T *p, size_t n, const T &t)
81 memmove(ptr_ + i + n, ptr_ + i, (size_ - i)*sizeof(T));
83 for (T *pp = ptr_ + i; n-- > 0; pp++)
88 void Vector<T>::insert(const T *p, const T *q1, const T *q2)
94 memmove(ptr_ + i + n, ptr_ + i, (size_ - i)*sizeof(T));
96 for (T *pp = ptr_ + i; q1 != q2; q1++, pp++)
97 (void)new (pp) T(*q1);
101 void Vector<T>::swap(Vector<T> &v)
121 void Vector<T>::append(size_t n)
125 (void)new (ptr_ + size_++) T;
129 T *Vector<T>::erase(const T *p1, const T *p2)
131 #if !defined(SP_TEMPLATE_DESTRUCTOR_COMPILER_BUG)
132 for (const T *p = p1; p != p2; p++)
135 if (p2 != ptr_ + size_)
136 memmove((T *)p1, p2, ((const T *)(ptr_ + size_) - p2)*sizeof(T));
142 void Vector<T>::reserve1(size_t size)
147 void *p = ::operator new(alloc_*sizeof(T));
149 memcpy(p, ptr_, size_*sizeof(T));
150 ::operator delete((void *)ptr_);
159 #endif /* not Vector_DEF_INCLUDED */