1 // Vector implementation -*- C++ -*-
3 // Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc.
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 2, or (at your option)
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING. If not, write to the Free
18 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
21 // As a special exception, you may use this file as part of a free software
22 // library without restriction. Specifically, if other files instantiate
23 // templates or use macros or inline functions from this file, or you compile
24 // this file and link it with other files to produce an executable, this
25 // file does not by itself cause the resulting executable to be covered by
26 // the GNU General Public License. This exception does not however
27 // invalidate any other reasons why the executable file might be covered by
28 // the GNU General Public License.
33 * Hewlett-Packard Company
35 * Permission to use, copy, modify, distribute and sell this software
36 * and its documentation for any purpose is hereby granted without fee,
37 * provided that the above copyright notice appear in all copies and
38 * that both that copyright notice and this permission notice appear
39 * in supporting documentation. Hewlett-Packard Company makes no
40 * representations about the suitability of this software for any
41 * purpose. It is provided "as is" without express or implied warranty.
45 * Silicon Graphics Computer Systems, Inc.
47 * Permission to use, copy, modify, distribute and sell this software
48 * and its documentation for any purpose is hereby granted without fee,
49 * provided that the above copyright notice appear in all copies and
50 * that both that copyright notice and this permission notice appear
51 * in supporting documentation. Silicon Graphics makes no
52 * representations about the suitability of this software for any
53 * purpose. It is provided "as is" without express or implied warranty.
56 /** @file stl_vector.h
57 * This is an internal header file, included by other library headers.
58 * You should not attempt to use it directly.
64 #include <bits/stl_iterator_base_funcs.h>
65 #include <bits/functexcept.h>
66 #include <bits/concept_check.h>
68 namespace _GLIBCXX_STD
72 * See bits/stl_deque.h's _Deque_base for an explanation.
75 template<typename _Tp, typename _Alloc>
82 _Tp* _M_end_of_storage;
83 _Vector_impl (_Alloc const& __a)
84 : _Alloc(__a), _M_start(0), _M_finish(0), _M_end_of_storage(0)
89 typedef _Alloc allocator_type;
92 get_allocator() const { return *static_cast<const _Alloc*>(&this->_M_impl); }
94 _Vector_base(const allocator_type& __a) : _M_impl(__a)
97 _Vector_base(size_t __n, const allocator_type& __a)
100 this->_M_impl._M_start = this->_M_allocate(__n);
101 this->_M_impl._M_finish = this->_M_impl._M_start;
102 this->_M_impl._M_end_of_storage = this->_M_impl._M_start + __n;
106 { _M_deallocate(this->_M_impl._M_start,
107 this->_M_impl._M_end_of_storage - this->_M_impl._M_start); }
110 _Vector_impl _M_impl;
113 _M_allocate(size_t __n) { return _M_impl.allocate(__n); }
116 _M_deallocate(_Tp* __p, size_t __n)
117 { if (__p) _M_impl.deallocate(__p, __n); }
122 * @brief A standard container which offers fixed time access to
123 * individual elements in any order.
125 * @ingroup Containers
128 * Meets the requirements of a <a href="tables.html#65">container</a>, a
129 * <a href="tables.html#66">reversible container</a>, and a
130 * <a href="tables.html#67">sequence</a>, including the
131 * <a href="tables.html#68">optional sequence requirements</a> with the
132 * %exception of @c push_front and @c pop_front.
134 * In some terminology a %vector can be described as a dynamic
135 * C-style array, it offers fast and efficient access to individual
136 * elements in any order and saves the user from worrying about
137 * memory and size allocation. Subscripting ( @c [] ) access is
138 * also provided as with C-style arrays.
140 template<typename _Tp, typename _Alloc = allocator<_Tp> >
141 class vector : protected _Vector_base<_Tp, _Alloc>
143 // Concept requirements.
144 __glibcxx_class_requires(_Tp, _SGIAssignableConcept)
146 typedef _Vector_base<_Tp, _Alloc> _Base;
147 typedef vector<_Tp, _Alloc> vector_type;
150 typedef _Tp value_type;
151 typedef typename _Alloc::pointer pointer;
152 typedef typename _Alloc::const_pointer const_pointer;
153 typedef typename _Alloc::reference reference;
154 typedef typename _Alloc::const_reference const_reference;
155 typedef __gnu_cxx::__normal_iterator<pointer, vector_type> iterator;
156 typedef __gnu_cxx::__normal_iterator<const_pointer, vector_type>
158 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
159 typedef std::reverse_iterator<iterator> reverse_iterator;
160 typedef size_t size_type;
161 typedef ptrdiff_t difference_type;
162 typedef typename _Base::allocator_type allocator_type;
166 * These two functions and three data members are all from the
167 * base class. They should be pretty self-explanatory, as
168 * %vector uses a simple contiguous allocation scheme. @endif
170 using _Base::_M_allocate;
171 using _Base::_M_deallocate;
172 using _Base::_M_impl;
175 // [23.2.4.1] construct/copy/destroy
176 // (assign() and get_allocator() are also listed in this section)
178 * @brief Default constructor creates no elements.
181 vector(const allocator_type& __a = allocator_type())
185 * @brief Create a %vector with copies of an exemplar element.
186 * @param n The number of elements to initially create.
187 * @param value An element to copy.
189 * This constructor fills the %vector with @a n copies of @a value.
191 vector(size_type __n, const value_type& __value,
192 const allocator_type& __a = allocator_type())
194 { this->_M_impl._M_finish = std::uninitialized_fill_n(this->_M_impl._M_start,
198 * @brief Create a %vector with default elements.
199 * @param n The number of elements to initially create.
201 * This constructor fills the %vector with @a n copies of a
202 * default-constructed element.
205 vector(size_type __n)
206 : _Base(__n, allocator_type())
207 { this->_M_impl._M_finish = std::uninitialized_fill_n(this->_M_impl._M_start,
208 __n, value_type()); }
211 * @brief %Vector copy constructor.
212 * @param x A %vector of identical element and allocator types.
214 * The newly-created %vector uses a copy of the allocation
215 * object used by @a x. All the elements of @a x are copied,
216 * but any extra memory in
217 * @a x (for fast expansion) will not be copied.
219 vector(const vector& __x)
220 : _Base(__x.size(), __x.get_allocator())
221 { this->_M_impl._M_finish = std::uninitialized_copy(__x.begin(), __x.end(),
222 this->_M_impl._M_start);
226 * @brief Builds a %vector from a range.
227 * @param first An input iterator.
228 * @param last An input iterator.
230 * Create a %vector consisting of copies of the elements from
233 * If the iterators are forward, bidirectional, or
234 * random-access, then this will call the elements' copy
235 * constructor N times (where N is distance(first,last)) and do
236 * no memory reallocation. But if only input iterators are
237 * used, then this will do at most 2N calls to the copy
238 * constructor, and logN memory reallocations.
240 template<typename _InputIterator>
241 vector(_InputIterator __first, _InputIterator __last,
242 const allocator_type& __a = allocator_type())
245 // Check whether it's an integral type. If so, it's not an iterator.
246 typedef typename _Is_integer<_InputIterator>::_Integral _Integral;
247 _M_initialize_dispatch(__first, __last, _Integral());
251 * The dtor only erases the elements, and note that if the
252 * elements themselves are pointers, the pointed-to memory is
253 * not touched in any way. Managing the pointer is the user's
256 ~vector() { std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish); }
259 * @brief %Vector assignment operator.
260 * @param x A %vector of identical element and allocator types.
262 * All the elements of @a x are copied, but any extra memory in
263 * @a x (for fast expansion) will not be copied. Unlike the
264 * copy constructor, the allocator object is not copied.
267 operator=(const vector& __x);
270 * @brief Assigns a given value to a %vector.
271 * @param n Number of elements to be assigned.
272 * @param val Value to be assigned.
274 * This function fills a %vector with @a n copies of the given
275 * value. Note that the assignment completely changes the
276 * %vector and that the resulting %vector's size is the same as
277 * the number of elements assigned. Old data may be lost.
280 assign(size_type __n, const value_type& __val)
281 { _M_fill_assign(__n, __val); }
284 * @brief Assigns a range to a %vector.
285 * @param first An input iterator.
286 * @param last An input iterator.
288 * This function fills a %vector with copies of the elements in the
289 * range [first,last).
291 * Note that the assignment completely changes the %vector and
292 * that the resulting %vector's size is the same as the number
293 * of elements assigned. Old data may be lost.
295 template<typename _InputIterator>
297 assign(_InputIterator __first, _InputIterator __last)
299 // Check whether it's an integral type. If so, it's not an iterator.
300 typedef typename _Is_integer<_InputIterator>::_Integral _Integral;
301 _M_assign_dispatch(__first, __last, _Integral());
304 /// Get a copy of the memory allocation object.
305 using _Base::get_allocator;
309 * Returns a read/write iterator that points to the first
310 * element in the %vector. Iteration is done in ordinary
314 begin() { return iterator (this->_M_impl._M_start); }
317 * Returns a read-only (constant) iterator that points to the
318 * first element in the %vector. Iteration is done in ordinary
322 begin() const { return const_iterator (this->_M_impl._M_start); }
325 * Returns a read/write iterator that points one past the last
326 * element in the %vector. Iteration is done in ordinary
330 end() { return iterator (this->_M_impl._M_finish); }
333 * Returns a read-only (constant) iterator that points one past
334 * the last element in the %vector. Iteration is done in
335 * ordinary element order.
338 end() const { return const_iterator (this->_M_impl._M_finish); }
341 * Returns a read/write reverse iterator that points to the
342 * last element in the %vector. Iteration is done in reverse
346 rbegin() { return reverse_iterator(end()); }
349 * Returns a read-only (constant) reverse iterator that points
350 * to the last element in the %vector. Iteration is done in
351 * reverse element order.
353 const_reverse_iterator
354 rbegin() const { return const_reverse_iterator(end()); }
357 * Returns a read/write reverse iterator that points to one
358 * before the first element in the %vector. Iteration is done
359 * in reverse element order.
362 rend() { return reverse_iterator(begin()); }
365 * Returns a read-only (constant) reverse iterator that points
366 * to one before the first element in the %vector. Iteration
367 * is done in reverse element order.
369 const_reverse_iterator
370 rend() const { return const_reverse_iterator(begin()); }
372 // [23.2.4.2] capacity
373 /** Returns the number of elements in the %vector. */
375 size() const { return size_type(end() - begin()); }
377 /** Returns the size() of the largest possible %vector. */
379 max_size() const { return size_type(-1) / sizeof(value_type); }
382 * @brief Resizes the %vector to the specified number of elements.
383 * @param new_size Number of elements the %vector should contain.
384 * @param x Data with which new elements should be populated.
386 * This function will %resize the %vector to the specified
387 * number of elements. If the number is smaller than the
388 * %vector's current size the %vector is truncated, otherwise
389 * the %vector is extended and new elements are populated with
393 resize(size_type __new_size, const value_type& __x)
395 if (__new_size < size())
396 erase(begin() + __new_size, end());
398 insert(end(), __new_size - size(), __x);
402 * @brief Resizes the %vector to the specified number of elements.
403 * @param new_size Number of elements the %vector should contain.
405 * This function will resize the %vector to the specified
406 * number of elements. If the number is smaller than the
407 * %vector's current size the %vector is truncated, otherwise
408 * the %vector is extended and new elements are
409 * default-constructed.
412 resize(size_type __new_size) { resize(__new_size, value_type()); }
415 * Returns the total number of elements that the %vector can
416 * hold before needing to allocate more memory.
420 { return size_type(const_iterator(this->_M_impl._M_end_of_storage) - begin()); }
423 * Returns true if the %vector is empty. (Thus begin() would
427 empty() const { return begin() == end(); }
430 * @brief Attempt to preallocate enough memory for specified number of
432 * @param n Number of elements required.
433 * @throw std::length_error If @a n exceeds @c max_size().
435 * This function attempts to reserve enough memory for the
436 * %vector to hold the specified number of elements. If the
437 * number requested is more than max_size(), length_error is
440 * The advantage of this function is that if optimal code is a
441 * necessity and the user can determine the number of elements
442 * that will be required, the user can reserve the memory in
443 * %advance, and thus prevent a possible reallocation of memory
444 * and copying of %vector data.
447 reserve(size_type __n);
451 * @brief Subscript access to the data contained in the %vector.
452 * @param n The index of the element for which data should be
454 * @return Read/write reference to data.
456 * This operator allows for easy, array-style, data access.
457 * Note that data access with this operator is unchecked and
458 * out_of_range lookups are not defined. (For checked lookups
462 operator[](size_type __n) { return *(begin() + __n); }
465 * @brief Subscript access to the data contained in the %vector.
466 * @param n The index of the element for which data should be
468 * @return Read-only (constant) reference to data.
470 * This operator allows for easy, array-style, data access.
471 * Note that data access with this operator is unchecked and
472 * out_of_range lookups are not defined. (For checked lookups
476 operator[](size_type __n) const { return *(begin() + __n); }
479 /// @if maint Safety check used only from at(). @endif
481 _M_range_check(size_type __n) const
483 if (__n >= this->size())
484 __throw_out_of_range(__N("vector::_M_range_check"));
489 * @brief Provides access to the data contained in the %vector.
490 * @param n The index of the element for which data should be
492 * @return Read/write reference to data.
493 * @throw std::out_of_range If @a n is an invalid index.
495 * This function provides for safer data access. The parameter
496 * is first checked that it is in the range of the vector. The
497 * function throws out_of_range if the check fails.
500 at(size_type __n) { _M_range_check(__n); return (*this)[__n]; }
503 * @brief Provides access to the data contained in the %vector.
504 * @param n The index of the element for which data should be
506 * @return Read-only (constant) reference to data.
507 * @throw std::out_of_range If @a n is an invalid index.
509 * This function provides for safer data access. The parameter
510 * is first checked that it is in the range of the vector. The
511 * function throws out_of_range if the check fails.
514 at(size_type __n) const { _M_range_check(__n); return (*this)[__n]; }
517 * Returns a read/write reference to the data at the first
518 * element of the %vector.
521 front() { return *begin(); }
524 * Returns a read-only (constant) reference to the data at the first
525 * element of the %vector.
528 front() const { return *begin(); }
531 * Returns a read/write reference to the data at the last
532 * element of the %vector.
535 back() { return *(end() - 1); }
538 * Returns a read-only (constant) reference to the data at the
539 * last element of the %vector.
542 back() const { return *(end() - 1); }
544 // [23.2.4.3] modifiers
546 * @brief Add data to the end of the %vector.
547 * @param x Data to be added.
549 * This is a typical stack operation. The function creates an
550 * element at the end of the %vector and assigns the given data
551 * to it. Due to the nature of a %vector this operation can be
552 * done in constant time if the %vector has preallocated space
556 push_back(const value_type& __x)
558 if (this->_M_impl._M_finish != this->_M_impl._M_end_of_storage)
560 std::_Construct(this->_M_impl._M_finish, __x);
561 ++this->_M_impl._M_finish;
564 _M_insert_aux(end(), __x);
568 * @brief Removes last element.
570 * This is a typical stack operation. It shrinks the %vector by one.
572 * Note that no data is returned, and if the last element's
573 * data is needed, it should be retrieved before pop_back() is
579 --this->_M_impl._M_finish;
580 std::_Destroy(this->_M_impl._M_finish);
584 * @brief Inserts given value into %vector before specified iterator.
585 * @param position An iterator into the %vector.
586 * @param x Data to be inserted.
587 * @return An iterator that points to the inserted data.
589 * This function will insert a copy of the given value before
590 * the specified location. Note that this kind of operation
591 * could be expensive for a %vector and if it is frequently
592 * used the user should consider using std::list.
595 insert(iterator __position, const value_type& __x);
598 * @brief Inserts a number of copies of given data into the %vector.
599 * @param position An iterator into the %vector.
600 * @param n Number of elements to be inserted.
601 * @param x Data to be inserted.
603 * This function will insert a specified number of copies of
604 * the given data before the location specified by @a position.
606 * Note that this kind of operation could be expensive for a
607 * %vector and if it is frequently used the user should
608 * consider using std::list.
611 insert(iterator __position, size_type __n, const value_type& __x)
612 { _M_fill_insert(__position, __n, __x); }
615 * @brief Inserts a range into the %vector.
616 * @param position An iterator into the %vector.
617 * @param first An input iterator.
618 * @param last An input iterator.
620 * This function will insert copies of the data in the range
621 * [first,last) into the %vector before the location specified
624 * Note that this kind of operation could be expensive for a
625 * %vector and if it is frequently used the user should
626 * consider using std::list.
628 template<typename _InputIterator>
630 insert(iterator __position, _InputIterator __first,
631 _InputIterator __last)
633 // Check whether it's an integral type. If so, it's not an iterator.
634 typedef typename _Is_integer<_InputIterator>::_Integral _Integral;
635 _M_insert_dispatch(__position, __first, __last, _Integral());
639 * @brief Remove element at given position.
640 * @param position Iterator pointing to element to be erased.
641 * @return An iterator pointing to the next element (or end()).
643 * This function will erase the element at the given position and thus
644 * shorten the %vector by one.
646 * Note This operation could be expensive and if it is
647 * frequently used the user should consider using std::list.
648 * The user is also cautioned that this function only erases
649 * the element, and that if the element is itself a pointer,
650 * the pointed-to memory is not touched in any way. Managing
651 * the pointer is the user's responsibilty.
654 erase(iterator __position);
657 * @brief Remove a range of elements.
658 * @param first Iterator pointing to the first element to be erased.
659 * @param last Iterator pointing to one past the last element to be
661 * @return An iterator pointing to the element pointed to by @a last
662 * prior to erasing (or end()).
664 * This function will erase the elements in the range [first,last) and
665 * shorten the %vector accordingly.
667 * Note This operation could be expensive and if it is
668 * frequently used the user should consider using std::list.
669 * The user is also cautioned that this function only erases
670 * the elements, and that if the elements themselves are
671 * pointers, the pointed-to memory is not touched in any way.
672 * Managing the pointer is the user's responsibilty.
675 erase(iterator __first, iterator __last);
678 * @brief Swaps data with another %vector.
679 * @param x A %vector of the same element and allocator types.
681 * This exchanges the elements between two vectors in constant time.
682 * (Three pointers, so it should be quite fast.)
683 * Note that the global std::swap() function is specialized such that
684 * std::swap(v1,v2) will feed to this function.
689 std::swap(this->_M_impl._M_start, __x._M_impl._M_start);
690 std::swap(this->_M_impl._M_finish, __x._M_impl._M_finish);
691 std::swap(this->_M_impl._M_end_of_storage, __x._M_impl._M_end_of_storage);
695 * Erases all the elements. Note that this function only erases the
696 * elements, and that if the elements themselves are pointers, the
697 * pointed-to memory is not touched in any way. Managing the pointer is
698 * the user's responsibilty.
701 clear() { erase(begin(), end()); }
706 * Memory expansion handler. Uses the member allocation function to
707 * obtain @a n bytes of memory, and then copies [first,last) into it.
710 template<typename _ForwardIterator>
712 _M_allocate_and_copy(size_type __n,
713 _ForwardIterator __first, _ForwardIterator __last)
715 pointer __result = this->_M_allocate(__n);
718 std::uninitialized_copy(__first, __last, __result);
723 _M_deallocate(__result, __n);
724 __throw_exception_again;
729 // Internal constructor functions follow.
731 // Called by the range constructor to implement [23.1.1]/9
732 template<typename _Integer>
734 _M_initialize_dispatch(_Integer __n, _Integer __value, __true_type)
736 this->_M_impl._M_start = _M_allocate(__n);
737 this->_M_impl._M_end_of_storage = this->_M_impl._M_start + __n;
738 this->_M_impl._M_finish = std::uninitialized_fill_n(this->_M_impl._M_start,
742 // Called by the range constructor to implement [23.1.1]/9
743 template<typename _InputIterator>
745 _M_initialize_dispatch(_InputIterator __first, _InputIterator __last,
748 typedef typename iterator_traits<_InputIterator>::iterator_category
750 _M_range_initialize(__first, __last, _IterCategory());
753 // Called by the second initialize_dispatch above
754 template<typename _InputIterator>
756 _M_range_initialize(_InputIterator __first,
757 _InputIterator __last, input_iterator_tag)
759 for ( ; __first != __last; ++__first)
763 // Called by the second initialize_dispatch above
764 template<typename _ForwardIterator>
766 _M_range_initialize(_ForwardIterator __first,
767 _ForwardIterator __last, forward_iterator_tag)
769 size_type __n = std::distance(__first, __last);
770 this->_M_impl._M_start = this->_M_allocate(__n);
771 this->_M_impl._M_end_of_storage = this->_M_impl._M_start + __n;
772 this->_M_impl._M_finish = std::uninitialized_copy(__first, __last,
773 this->_M_impl._M_start);
777 // Internal assign functions follow. The *_aux functions do the actual
778 // assignment work for the range versions.
780 // Called by the range assign to implement [23.1.1]/9
781 template<typename _Integer>
783 _M_assign_dispatch(_Integer __n, _Integer __val, __true_type)
785 _M_fill_assign(static_cast<size_type>(__n),
786 static_cast<value_type>(__val));
789 // Called by the range assign to implement [23.1.1]/9
790 template<typename _InputIterator>
792 _M_assign_dispatch(_InputIterator __first, _InputIterator __last,
795 typedef typename iterator_traits<_InputIterator>::iterator_category
797 _M_assign_aux(__first, __last, _IterCategory());
800 // Called by the second assign_dispatch above
801 template<typename _InputIterator>
803 _M_assign_aux(_InputIterator __first, _InputIterator __last,
806 // Called by the second assign_dispatch above
807 template<typename _ForwardIterator>
809 _M_assign_aux(_ForwardIterator __first, _ForwardIterator __last,
810 forward_iterator_tag);
812 // Called by assign(n,t), and the range assign when it turns out
813 // to be the same thing.
815 _M_fill_assign(size_type __n, const value_type& __val);
818 // Internal insert functions follow.
820 // Called by the range insert to implement [23.1.1]/9
821 template<typename _Integer>
823 _M_insert_dispatch(iterator __pos, _Integer __n, _Integer __val,
826 _M_fill_insert(__pos, static_cast<size_type>(__n),
827 static_cast<value_type>(__val));
830 // Called by the range insert to implement [23.1.1]/9
831 template<typename _InputIterator>
833 _M_insert_dispatch(iterator __pos, _InputIterator __first,
834 _InputIterator __last, __false_type)
836 typedef typename iterator_traits<_InputIterator>::iterator_category
838 _M_range_insert(__pos, __first, __last, _IterCategory());
841 // Called by the second insert_dispatch above
842 template<typename _InputIterator>
844 _M_range_insert(iterator __pos, _InputIterator __first,
845 _InputIterator __last, input_iterator_tag);
847 // Called by the second insert_dispatch above
848 template<typename _ForwardIterator>
850 _M_range_insert(iterator __pos, _ForwardIterator __first,
851 _ForwardIterator __last, forward_iterator_tag);
853 // Called by insert(p,n,x), and the range insert when it turns out to be
856 _M_fill_insert(iterator __pos, size_type __n, const value_type& __x);
858 // Called by insert(p,x)
860 _M_insert_aux(iterator __position, const value_type& __x);
865 * @brief Vector equality comparison.
866 * @param x A %vector.
867 * @param y A %vector of the same type as @a x.
868 * @return True iff the size and elements of the vectors are equal.
870 * This is an equivalence relation. It is linear in the size of the
871 * vectors. Vectors are considered equivalent if their sizes are equal,
872 * and if corresponding elements compare equal.
874 template<typename _Tp, typename _Alloc>
876 operator==(const vector<_Tp,_Alloc>& __x, const vector<_Tp,_Alloc>& __y)
878 return __x.size() == __y.size() &&
879 std::equal(__x.begin(), __x.end(), __y.begin());
883 * @brief Vector ordering relation.
884 * @param x A %vector.
885 * @param y A %vector of the same type as @a x.
886 * @return True iff @a x is lexicographically less than @a y.
888 * This is a total ordering relation. It is linear in the size of the
889 * vectors. The elements must be comparable with @c <.
891 * See std::lexicographical_compare() for how the determination is made.
893 template<typename _Tp, typename _Alloc>
895 operator<(const vector<_Tp,_Alloc>& __x, const vector<_Tp,_Alloc>& __y)
897 return std::lexicographical_compare(__x.begin(), __x.end(),
898 __y.begin(), __y.end());
901 /// Based on operator==
902 template<typename _Tp, typename _Alloc>
904 operator!=(const vector<_Tp,_Alloc>& __x, const vector<_Tp,_Alloc>& __y)
905 { return !(__x == __y); }
907 /// Based on operator<
908 template<typename _Tp, typename _Alloc>
910 operator>(const vector<_Tp,_Alloc>& __x, const vector<_Tp,_Alloc>& __y)
911 { return __y < __x; }
913 /// Based on operator<
914 template<typename _Tp, typename _Alloc>
916 operator<=(const vector<_Tp,_Alloc>& __x, const vector<_Tp,_Alloc>& __y)
917 { return !(__y < __x); }
919 /// Based on operator<
920 template<typename _Tp, typename _Alloc>
922 operator>=(const vector<_Tp,_Alloc>& __x, const vector<_Tp,_Alloc>& __y)
923 { return !(__x < __y); }
925 /// See std::vector::swap().
926 template<typename _Tp, typename _Alloc>
928 swap(vector<_Tp,_Alloc>& __x, vector<_Tp,_Alloc>& __y)
932 #endif /* _VECTOR_H */