1 /* $XConsortium: NCVector.h /main/1 1996/07/29 16:58:13 cde-hp $ */
2 // Copyright (c) 1994, 1996 James Clark
3 // See the file COPYING for copying permission.
5 #ifndef NCVector_INCLUDED
6 #define NCVector_INCLUDED 1
11 // This offers a subset of the interface offered by the standard C++
12 // vector class as defined in the Jan 96 WP.
13 // Code in SP currently assumes that size_type is size_t.
16 namespace SP_NAMESPACE {
22 typedef size_t size_type;
24 typedef const T *const_iterator;
25 NCVector() : ptr_(0), size_(0), alloc_(0) { }
26 NCVector(size_t n) : ptr_(0), size_(0), alloc_(0) { append(n); }
28 void resize(size_t n) {
30 erase(ptr_ + n, ptr_ + size_);
34 void swap(NCVector<T> &);
35 void clear() { erase(ptr_, ptr_ + size_); }
36 size_t size() const { return size_; }
37 T &operator[](size_t i) { return ptr_[i]; }
38 const T &operator[](size_t i) const { return ptr_[i]; }
39 iterator begin() { return ptr_; }
40 const_iterator begin() const { return ptr_; }
41 T &back() { return ptr_[size_ - 1]; }
42 const T &back() const { return ptr_[size_ - 1]; }
43 void reserve(size_t n) { if (n > alloc_) reserve1(n); }
44 iterator erase(const_iterator, const_iterator);
47 void reserve1(size_t);
51 size_t alloc_; // allocated size
58 #endif /* not NCVector_INCLUDED */
60 #ifdef SP_DEFINE_TEMPLATES