| 发表于:2007-09-19 14:28:573楼 得分:5 |
summary a sequence that supports random access iterators. synopsis #include <vector> template <class t, class allocator = allocator <t> > class vector ; description vector <t, allocator> is a type of sequence that supports random access iterators. in addition, it supports amortized constant time insert and erase operations at the end. insert and erase in the middle take linear time. storage management is handled automatically. in vector, iterator is a random access iterator referring to t. const_iterator is a constant random access iterator that returns a const t& when dereferenced. a constructor for iterator and const_iterator is guaranteed. size_type is an unsigned integral type. difference_type is a signed integral type. any type used for the template parameter t must provide the following (where t is the type, t is a value of t and u is a const value of t): copy constructors t(t) and t(u) destructor t.~t() address of &t and &u yielding t* and const t* respectively assignment t = a where a is a (possibly const) value of t special case vectors of bit values, that is boolean 1/0 values, are handled as a special case by the standard library, so that they can be efficiently packed several elements to a word. the operations for a boolean vector, vector <bool> , are a superset of those for an ordinary vector, only the implementation is more efficient. two member functions are available to the boolean vector data type. one is flip(), which inverts all the bits of the vector. boolean vectors also return as reference an internal value that also supports the flip() member function. the other vector <bool> -specific member function is a second form of the swap() function interface template <class t, class allocator = allocator <t> > class vector { public: // types typedef t value_type; typedef allocator allocator_type; typedef typename allocator::reference reference; typedef typename allocator::const_reference const_reference; class iterator; class const_iterator; typedef typename allocator::size_type size_type; typedef typename allocator::difference_type difference_type; typedef typename std::reverse_iterator <iterator> reverse_iterator; typedef typename std::reverse_iterator <const iterator> const_reverse_iterator; // construct/copy/destroy explicit vector (const allocator& = allocator()); explicit vector (size_type, const allocator& = allocator ()); vector (size_type, const t&, const allocator& = allocator()); vector (const vector <t, allocator> &); template <class inputiterator> vector (inputiterator, inputiterator, const allocator& = allocator ()); ~vector (); vector <t,allocator> & operator= (const vector <t, allocator> &); template <class inputiterator> void assign (inputiterator first, inputiterator last); void assign (size_type, const); allocator_type get_allocator () const; // iterators 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; // capacity size_type size () const; size_type max_size () const; void resize (size_type); void resize (size_type, t); size_type capacity () const; bool empty () const; void reserve (size_type); // element access reference operator[] (size_type); const_reference operator[] (size_type) const; reference at (size_type); const_reference at (size_type) const; reference front (); const_reference front () const; reference back (); const_reference back () const; // modifiers void push_back (const t&); void pop_back (); iterator insert (iterator, const t&); void insert (iterator, size_type, const t&); template <class inputiterator> void insert (iterator, inputiterator, inputiterator); iterator erase (iterator); iterator erase (iterator, iterator); void swap (vector <t, allocator> &); void clear() }; // non-member operators template <class t> bool operator== (const vector <t,allocator> &, const vector <t,allocator> &); template <class t> bool operator!= (const vector <t,allocator> &, const vector <t,allocator> &); template <class t> bool operator < (const vector <t,allocator> &, const vector <t,allocator> &); template <class t> bool operator> (const vector <t,allocator> &, const vector <t,allocator> &); template <class t> bool operator <= (const vector <t,allocator> &, const vector <t,allocator> &); | | |
|