Name

Vector — Portable, light-weight and fast version of a vector.

Synopsis

template<typename T> 
class Vector {
public:
  // types
  typedef size_t    size_type;     
  typedef T *       iterator;      
  typedef const T * const_iterator;

  // construct/copy/destruct
  Vector();
  Vector(size_type);
  Vector(size_type, const T &);
  Vector(const Vector< T > &);
  Vector& operator=(const Vector< T > &);
  ~Vector();

  // public member functions

  void resize(size_type) ;
  void assign(size_type, const T &) ;
  iterator push_back(const T &) ;
  void pop_back() ;
  iterator insert(const_iterator, size_type, const T &) ;
  iterator insert(const_iterator, const_iterator, const_iterator) ;
  iterator insert(const_iterator, const T &) ;
  void swap(Vector< T > &) ;
  void clear() ;
  size_type size() const;
  T & operator[](size_type) ;
  const T & operator[](size_type) const;
  iterator begin() ;
  const_iterator begin() const;
  iterator end() ;
  const_iterator end() const;
  T & back() ;
  const T & back() const;
  void reserve(size_type) ;
  iterator erase(const_iterator, const_iterator) ;
  void erase(size_type) ;
  Vector< T > & operator+=(const Vector< T > &) ;
  T * release() ;

  // private member functions

  void append(size_type) ;
  void reserve1(size_type) ;
};

Description

This vector has one important difference from the STL one: this vector does not use copy constructors for moving objects around; it uses memmove() instead. So, objects which keep pointers to themselves may not behave correctly in this Vector.

Vector construct/copy/destruct

  1. Vector();

    default constructor


  2. Vector(size_type n);

    reserve place for n objects


  3. Vector(size_type n, const T & t);

    create n identical copies of the object in a vector


  4. Vector(const Vector< T > & v);

    copy constructor


  5. Vector& operator=(const Vector< T > & );

    assignment operator


  6. ~Vector();


Vector public member functions

  1. void resize(size_type n) ;

    adjust vector size to n


  2. void assign(size_type n, const T & ) ;

    initialize vector with n objects of type T


  3. iterator push_back(const T & t) ;

    add object T to the tail of the vector


  4. void pop_back() ;

    remove object from the tail of the vector


  5. iterator insert(const_iterator p, size_type n, const T & t) ;

    insert n objects T before p


  6. iterator insert(const_iterator p, const_iterator q1, const_iterator q2) ;

    insert objects q1...q2 before p


  7. iterator insert(const_iterator p, const T & t) ;

    insert single object T before p


  8. void swap(Vector< T > & ) ;

    swap contents of the vector with another vector


  9. void clear() ;

    clear vector


  10. size_type size() const;

    returns size of the vector


  11. T & operator[](size_type i) ;


  12. const T & operator[](size_type i) const;


  13. iterator begin() ;

    returns begin of the vector


  14. const_iterator begin() const;


  15. iterator end() ;

    returns pointer right beyond the last element of the vector


  16. const_iterator end() const;


  17. T & back() ;

    returns reference to the last element of the vector


  18. const T & back() const;


  19. void reserve(size_type n) ;

    reserve memory for at least n objects


  20. iterator erase(const_iterator q1, const_iterator q2) ;

    erase objects q1...q2


  21. void erase(size_type idx) ;

    erase object with index idx


  22. Vector< T > & operator+=(const Vector< T > & v1) ;

    append vector v1 to the current vector


  23. T * release() ;

    Give up ownership of the data; reset the vector.


Vector private member functions

  1. void append(size_type ) ;


  2. void reserve1(size_type ) ;