DESCRIPTION
The class implement a reference counting wrapper for
the STL vector<T> container class, with shallow copies.
See also:
The standard template library, by Alexander Stephanov and Meng Lee.
This class provides the full vector<T>
interface specification
an could be used instead of vector<T>.
NOTE
The write accessors
T& operator[](size_type)
as in v[i]
may checks the reference count for each access.
For a loop, a better usage is:
Vector<T>::iterator i = v.begin(); Vector<T>::iterator last = v.end(); while (i != last) { ...}
and the reference count check step occurs only two time,
when accessing via begin() and end().
Thus, in order to encourage users to do it, we declare private
theses member functions. A synonym of operator[] is at.
IMPLEMENTATION
template<class T> class Vector : private smart_pointer<vector_rep<T> > { public: // typedefs: typedef iterator; typedef const_iterator; typedef pointer; typedef reference; typedef const_reference; typedef size_type; typedef difference_type; typedef value_type; typedef reverse_iterator; typedef const_reverse_iterator; // allocation/deallocation: explicit Vector (size_type n = 0, const T& value = T ()); Vector (const_iterator first, const_iterator last); void reserve (size_type n); void swap (Vector<T>& x) ; // accessors: iterator begin (); const_iterator begin () const; iterator end (); const_iterator end () const; reverse_iterator rbegin(); const_reverse_iterator rbegin() const; reverse_iterator rend(); const_reverse_iterator rend() const; size_type size () const; size_type max_size () const; size_type capacity () const; bool empty () const; void resize (size_type sz, T v = T ()); // non-standard ? private: const_reference operator[] (size_type n) const; reference operator[] (size_type n); public: const_reference at (size_type n) const; // non-standard ? reference at (size_type n); reference front (); const_reference front () const; reference back (); const_reference back () const; // insert/erase: void push_back (const T& x); iterator insert (iterator position, const T& x = T ()); void insert (iterator position, size_type n, const T& x); void insert (iterator position, const_iterator first, const_iterator last); void pop_back (); void erase (iterator position); void erase (iterator first, iterator last); };