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.
61 #ifndef __GLIBCPP_INTERNAL_VECTOR_H
62 #define __GLIBCPP_INTERNAL_VECTOR_H
64 #include <bits/stl_iterator_base_funcs.h>
65 #include <bits/functexcept.h>
66 #include <bits/concept_check.h>
70 /// @if maint Primary default version. @endif
73 * See bits/stl_deque.h's _Deque_alloc_base for an explanation.
76 template<typename _Tp
, typename _Allocator
, bool _IsStatic
>
77 class _Vector_alloc_base
80 typedef typename _Alloc_traits
<_Tp
, _Allocator
>::allocator_type
84 get_allocator() const { return _M_data_allocator
; }
86 _Vector_alloc_base(const allocator_type
& __a
)
87 : _M_data_allocator(__a
), _M_start(0), _M_finish(0), _M_end_of_storage(0)
91 allocator_type _M_data_allocator
;
94 _Tp
* _M_end_of_storage
;
97 _M_allocate(size_t __n
) { return _M_data_allocator
.allocate(__n
); }
100 _M_deallocate(_Tp
* __p
, size_t __n
)
101 { if (__p
) _M_data_allocator
.deallocate(__p
, __n
); }
104 /// @if maint Specialization for instanceless allocators. @endif
105 template<typename _Tp
, typename _Allocator
>
106 class _Vector_alloc_base
<_Tp
, _Allocator
, true>
109 typedef typename _Alloc_traits
<_Tp
, _Allocator
>::allocator_type
113 get_allocator() const { return allocator_type(); }
115 _Vector_alloc_base(const allocator_type
&)
116 : _M_start(0), _M_finish(0), _M_end_of_storage(0)
122 _Tp
* _M_end_of_storage
;
124 typedef typename _Alloc_traits
<_Tp
, _Allocator
>::_Alloc_type _Alloc_type
;
127 _M_allocate(size_t __n
) { return _Alloc_type::allocate(__n
); }
130 _M_deallocate(_Tp
* __p
, size_t __n
) { _Alloc_type::deallocate(__p
, __n
);}
136 * See bits/stl_deque.h's _Deque_base for an explanation.
139 template<typename _Tp
, typename _Alloc
>
141 : public _Vector_alloc_base
<_Tp
, _Alloc
,
142 _Alloc_traits
<_Tp
, _Alloc
>::_S_instanceless
>
145 typedef _Vector_alloc_base
<_Tp
, _Alloc
,
146 _Alloc_traits
<_Tp
, _Alloc
>::_S_instanceless
>
148 typedef typename
_Base::allocator_type allocator_type
;
150 _Vector_base(const allocator_type
& __a
)
153 _Vector_base(size_t __n
, const allocator_type
& __a
)
156 this->_M_start
= _M_allocate(__n
);
157 this->_M_finish
= this->_M_start
;
158 this->_M_end_of_storage
= this->_M_start
+ __n
;
162 { _M_deallocate(this->_M_start
,
163 this->_M_end_of_storage
- this->_M_start
); }
168 * @brief A standard container which offers fixed time access to individual
169 * elements in any order.
171 * @ingroup Containers
174 * Meets the requirements of a <a href="tables.html#65">container</a>, a
175 * <a href="tables.html#66">reversible container</a>, and a
176 * <a href="tables.html#67">sequence</a>, including the
177 * <a href="tables.html#68">optional sequence requirements</a> with the
178 * %exception of @c push_front and @c pop_front.
180 * In some terminology a %vector can be described as a dynamic C-style array,
181 * it offers fast and efficient access to individual elements in any order
182 * and saves the user from worrying about memory and size allocation.
183 * Subscripting ( @c [] ) access is also provided as with C-style arrays.
185 template<typename _Tp
, typename _Alloc
= allocator
<_Tp
> >
186 class vector
: protected _Vector_base
<_Tp
, _Alloc
>
188 // Concept requirements.
189 __glibcpp_class_requires(_Tp
, _SGIAssignableConcept
)
191 typedef _Vector_base
<_Tp
, _Alloc
> _Base
;
192 typedef vector
<_Tp
, _Alloc
> vector_type
;
195 typedef _Tp value_type
;
196 typedef value_type
* pointer
;
197 typedef const value_type
* const_pointer
;
198 typedef __gnu_cxx::__normal_iterator
<pointer
, vector_type
> iterator
;
199 typedef __gnu_cxx::__normal_iterator
<const_pointer
, vector_type
>
201 typedef std::reverse_iterator
<const_iterator
> const_reverse_iterator
;
202 typedef std::reverse_iterator
<iterator
> reverse_iterator
;
203 typedef value_type
& reference
;
204 typedef const value_type
& const_reference
;
205 typedef size_t size_type
;
206 typedef ptrdiff_t difference_type
;
207 typedef typename
_Base::allocator_type allocator_type
;
211 * These two functions and three data members are all from the
212 * top-most base class, which varies depending on the type of
213 * %allocator. They should be pretty self-explanatory, as
214 * %vector uses a simple contiguous allocation scheme. @endif
216 using _Base::_M_allocate
;
217 using _Base::_M_deallocate
;
218 using _Base::_M_start
;
219 using _Base::_M_finish
;
220 using _Base::_M_end_of_storage
;
223 // [23.2.4.1] construct/copy/destroy
224 // (assign() and get_allocator() are also listed in this section)
226 * @brief Default constructor creates no elements.
229 vector(const allocator_type
& __a
= allocator_type())
233 * @brief Create a %vector with copies of an exemplar element.
234 * @param n The number of elements to initially create.
235 * @param value An element to copy.
237 * This constructor fills the %vector with @a n copies of @a value.
239 vector(size_type __n
, const value_type
& __value
,
240 const allocator_type
& __a
= allocator_type())
242 { this->_M_finish
= uninitialized_fill_n(this->_M_start
, __n
, __value
); }
245 * @brief Create a %vector with default elements.
246 * @param n The number of elements to initially create.
248 * This constructor fills the %vector with @a n copies of a
249 * default-constructed element.
252 vector(size_type __n
)
253 : _Base(__n
, allocator_type())
254 { this->_M_finish
= uninitialized_fill_n(this->_M_start
,
255 __n
, value_type()); }
258 * @brief %Vector copy constructor.
259 * @param x A %vector of identical element and allocator types.
261 * The newly-created %vector uses a copy of the allocation
262 * object used by @a x. All the elements of @a x are copied,
263 * but any extra memory in
264 * @a x (for fast expansion) will not be copied.
266 vector(const vector
& __x
)
267 : _Base(__x
.size(), __x
.get_allocator())
268 { this->_M_finish
= uninitialized_copy(__x
.begin(), __x
.end(),
273 * @brief Builds a %vector from a range.
274 * @param first An input iterator.
275 * @param last An input iterator.
277 * Create a %vector consisting of copies of the elements from
280 * If the iterators are forward, bidirectional, or random-access, then
281 * this will call the elements' copy constructor N times (where N is
282 * distance(first,last)) and do no memory reallocation. But if only
283 * input iterators are used, then this will do at most 2N calls to the
284 * copy constructor, and logN memory reallocations.
286 template<typename _InputIterator
>
287 vector(_InputIterator __first
, _InputIterator __last
,
288 const allocator_type
& __a
= allocator_type())
291 // Check whether it's an integral type. If so, it's not an iterator.
292 typedef typename _Is_integer
<_InputIterator
>::_Integral _Integral
;
293 _M_initialize_dispatch(__first
, __last
, _Integral());
297 * The dtor only erases the elements, and note that if the elements
298 * themselves are pointers, the pointed-to memory is not touched in any
299 * way. Managing the pointer is the user's responsibilty.
301 ~vector() { _Destroy(this->_M_start
, this->_M_finish
); }
304 * @brief %Vector assignment operator.
305 * @param x A %vector of identical element and allocator types.
307 * All the elements of @a x are copied, but any extra memory in
308 * @a x (for fast expansion) will not be copied. Unlike the
309 * copy constructor, the allocator object is not copied.
312 operator=(const vector
& __x
);
315 * @brief Assigns a given value to a %vector.
316 * @param n Number of elements to be assigned.
317 * @param val Value to be assigned.
319 * This function fills a %vector with @a n copies of the given
320 * value. Note that the assignment completely changes the
321 * %vector and that the resulting %vector's size is the same as
322 * the number of elements assigned. Old data may be lost.
325 assign(size_type __n
, const value_type
& __val
)
326 { _M_fill_assign(__n
, __val
); }
329 * @brief Assigns a range to a %vector.
330 * @param first An input iterator.
331 * @param last An input iterator.
333 * This function fills a %vector with copies of the elements in the
334 * range [first,last).
336 * Note that the assignment completely changes the %vector and
337 * that the resulting %vector's size is the same as the number
338 * of elements assigned. Old data may be lost.
340 template<typename _InputIterator
>
342 assign(_InputIterator __first
, _InputIterator __last
)
344 // Check whether it's an integral type. If so, it's not an iterator.
345 typedef typename _Is_integer
<_InputIterator
>::_Integral _Integral
;
346 _M_assign_dispatch(__first
, __last
, _Integral());
349 /// Get a copy of the memory allocation object.
351 get_allocator() const { return _Base::get_allocator(); }
355 * Returns a read/write iterator that points to the first element in the
356 * %vector. Iteration is done in ordinary element order.
359 begin() { return iterator (this->_M_start
); }
362 * Returns a read-only (constant) iterator that points to the
363 * first element in the %vector. Iteration is done in ordinary
367 begin() const { return const_iterator (this->_M_start
); }
370 * Returns a read/write iterator that points one past the last
371 * element in the %vector. Iteration is done in ordinary
375 end() { return iterator (this->_M_finish
); }
378 * Returns a read-only (constant) iterator that points one past the last
379 * element in the %vector. Iteration is done in ordinary element order.
382 end() const { return const_iterator (this->_M_finish
); }
385 * Returns a read/write reverse iterator that points to the
386 * last element in the %vector. Iteration is done in reverse
390 rbegin() { return reverse_iterator(end()); }
393 * Returns a read-only (constant) reverse iterator that points
394 * to the last element in the %vector. Iteration is done in
395 * reverse element order.
397 const_reverse_iterator
398 rbegin() const { return const_reverse_iterator(end()); }
401 * Returns a read/write reverse iterator that points to one before the
402 * first element in the %vector. Iteration is done in reverse element
406 rend() { return reverse_iterator(begin()); }
409 * Returns a read-only (constant) reverse iterator that points
410 * to one before the first element in the %vector. Iteration
411 * is done in reverse element order.
413 const_reverse_iterator
414 rend() const { return const_reverse_iterator(begin()); }
416 // [23.2.4.2] capacity
417 /** Returns the number of elements in the %vector. */
419 size() const { return size_type(end() - begin()); }
421 /** Returns the size() of the largest possible %vector. */
423 max_size() const { return size_type(-1) / sizeof(value_type
); }
426 * @brief Resizes the %vector to the specified number of elements.
427 * @param new_size Number of elements the %vector should contain.
428 * @param x Data with which new elements should be populated.
430 * This function will %resize the %vector to the specified
431 * number of elements. If the number is smaller than the
432 * %vector's current size the %vector is truncated, otherwise
433 * the %vector is extended and new elements are populated with
437 resize(size_type __new_size
, const value_type
& __x
)
439 if (__new_size
< size())
440 erase(begin() + __new_size
, end());
442 insert(end(), __new_size
- size(), __x
);
446 * @brief Resizes the %vector to the specified number of elements.
447 * @param new_size Number of elements the %vector should contain.
449 * This function will resize the %vector to the specified
450 * number of elements. If the number is smaller than the
451 * %vector's current size the %vector is truncated, otherwise
452 * the %vector is extended and new elements are
453 * default-constructed.
456 resize(size_type __new_size
) { resize(__new_size
, value_type()); }
459 * Returns the total number of elements that the %vector can hold before
460 * needing to allocate more memory.
464 { return size_type(const_iterator(this->_M_end_of_storage
) - begin()); }
467 * Returns true if the %vector is empty. (Thus begin() would
471 empty() const { return begin() == end(); }
474 * @brief Attempt to preallocate enough memory for specified number of
476 * @param n Number of elements required.
477 * @throw std::length_error If @a n exceeds @c max_size().
479 * This function attempts to reserve enough memory for the
480 * %vector to hold the specified number of elements. If the
481 * number requested is more than max_size(), length_error is
484 * The advantage of this function is that if optimal code is a
485 * necessity and the user can determine the number of elements
486 * that will be required, the user can reserve the memory in
487 * %advance, and thus prevent a possible reallocation of memory
488 * and copying of %vector data.
491 reserve(size_type __n
);
495 * @brief Subscript access to the data contained in the %vector.
496 * @param n The index of the element for which data should be accessed.
497 * @return Read/write reference to data.
499 * This operator allows for easy, array-style, data access.
500 * Note that data access with this operator is unchecked and
501 * out_of_range lookups are not defined. (For checked lookups
505 operator[](size_type __n
) { return *(begin() + __n
); }
508 * @brief Subscript access to the data contained in the %vector.
509 * @param n The index of the element for which data should be
511 * @return Read-only (constant) reference to data.
513 * This operator allows for easy, array-style, data access.
514 * Note that data access with this operator is unchecked and
515 * out_of_range lookups are not defined. (For checked lookups
519 operator[](size_type __n
) const { return *(begin() + __n
); }
522 /// @if maint Safety check used only from at(). @endif
524 _M_range_check(size_type __n
) const
526 if (__n
>= this->size())
527 __throw_out_of_range(__N("std::vector [] access out of range"));
532 * @brief Provides access to the data contained in the %vector.
533 * @param n The index of the element for which data should be
535 * @return Read/write reference to data.
536 * @throw std::out_of_range If @a n is an invalid index.
538 * This function provides for safer data access. The parameter is first
539 * checked that it is in the range of the vector. The function throws
540 * out_of_range if the check fails.
543 at(size_type __n
) { _M_range_check(__n
); return (*this)[__n
]; }
546 * @brief Provides access to the data contained in the %vector.
547 * @param n The index of the element for which data should be
549 * @return Read-only (constant) reference to data.
550 * @throw std::out_of_range If @a n is an invalid index.
552 * This function provides for safer data access. The parameter
553 * is first checked that it is in the range of the vector. The
554 * function throws out_of_range if the check fails.
557 at(size_type __n
) const { _M_range_check(__n
); return (*this)[__n
]; }
560 * Returns a read/write reference to the data at the first
561 * element of the %vector.
564 front() { return *begin(); }
567 * Returns a read-only (constant) reference to the data at the first
568 * element of the %vector.
571 front() const { return *begin(); }
574 * Returns a read/write reference to the data at the last element of the
578 back() { return *(end() - 1); }
581 * Returns a read-only (constant) reference to the data at the last
582 * element of the %vector.
585 back() const { return *(end() - 1); }
587 // [23.2.4.3] modifiers
589 * @brief Add data to the end of the %vector.
590 * @param x Data to be added.
592 * This is a typical stack operation. The function creates an
593 * element at the end of the %vector and assigns the given data
594 * to it. Due to the nature of a %vector this operation can be
595 * done in constant time if the %vector has preallocated space
599 push_back(const value_type
& __x
)
601 if (this->_M_finish
!= this->_M_end_of_storage
)
603 _Construct(this->_M_finish
, __x
);
607 _M_insert_aux(end(), __x
);
611 * @brief Removes last element.
613 * This is a typical stack operation. It shrinks the %vector by one.
615 * Note that no data is returned, and if the last element's data is
616 * needed, it should be retrieved before pop_back() is called.
622 _Destroy(this->_M_finish
);
626 * @brief Inserts given value into %vector before specified iterator.
627 * @param position An iterator into the %vector.
628 * @param x Data to be inserted.
629 * @return An iterator that points to the inserted data.
631 * This function will insert a copy of the given value before
632 * the specified location. Note that this kind of operation
633 * could be expensive for a %vector and if it is frequently
634 * used the user should consider using std::list.
637 insert(iterator __position
, const value_type
& __x
);
640 * @brief Inserts a number of copies of given data into the %vector.
641 * @param position An iterator into the %vector.
642 * @param n Number of elements to be inserted.
643 * @param x Data to be inserted.
645 * This function will insert a specified number of copies of
646 * the given data before the location specified by @a position.
648 * Note that this kind of operation could be expensive for a
649 * %vector and if it is frequently used the user should
650 * consider using std::list.
653 insert(iterator __pos
, size_type __n
, const value_type
& __x
)
654 { _M_fill_insert(__pos
, __n
, __x
); }
657 * @brief Inserts a range into the %vector.
658 * @param pos An iterator into the %vector.
659 * @param first An input iterator.
660 * @param last An input iterator.
662 * This function will insert copies of the data in the range
663 * [first,last) into the %vector before the location specified
666 * Note that this kind of operation could be expensive for a
667 * %vector and if it is frequently used the user should
668 * consider using std::list.
670 template<typename _InputIterator
>
672 insert(iterator __pos
, _InputIterator __first
, _InputIterator __last
)
674 // Check whether it's an integral type. If so, it's not an iterator.
675 typedef typename _Is_integer
<_InputIterator
>::_Integral _Integral
;
676 _M_insert_dispatch(__pos
, __first
, __last
, _Integral());
680 * @brief Remove element at given position.
681 * @param position Iterator pointing to element to be erased.
682 * @return An iterator pointing to the next element (or end()).
684 * This function will erase the element at the given position and thus
685 * shorten the %vector by one.
687 * Note This operation could be expensive and if it is
688 * frequently used the user should consider using std::list.
689 * The user is also cautioned that this function only erases
690 * the element, and that if the element is itself a pointer,
691 * the pointed-to memory is not touched in any way. Managing
692 * the pointer is the user's responsibilty.
695 erase(iterator __position
);
698 * @brief Remove a range of elements.
699 * @param first Iterator pointing to the first element to be erased.
700 * @param last Iterator pointing to one past the last element to be
702 * @return An iterator pointing to the element pointed to by @a last
703 * prior to erasing (or end()).
705 * This function will erase the elements in the range [first,last) and
706 * shorten the %vector accordingly.
708 * Note This operation could be expensive and if it is
709 * frequently used the user should consider using std::list.
710 * The user is also cautioned that this function only erases
711 * the elements, and that if the elements themselves are
712 * pointers, the pointed-to memory is not touched in any way.
713 * Managing the pointer is the user's responsibilty.
716 erase(iterator __first
, iterator __last
);
719 * @brief Swaps data with another %vector.
720 * @param x A %vector of the same element and allocator types.
722 * This exchanges the elements between two vectors in constant time.
723 * (Three pointers, so it should be quite fast.)
724 * Note that the global std::swap() function is specialized such that
725 * std::swap(v1,v2) will feed to this function.
730 std::swap(this->_M_start
, __x
._M_start
);
731 std::swap(this->_M_finish
, __x
._M_finish
);
732 std::swap(this->_M_end_of_storage
, __x
._M_end_of_storage
);
736 * Erases all the elements. Note that this function only erases the
737 * elements, and that if the elements themselves are pointers, the
738 * pointed-to memory is not touched in any way. Managing the pointer is
739 * the user's responsibilty.
742 clear() { erase(begin(), end()); }
747 * Memory expansion handler. Uses the member allocation function to
748 * obtain @a n bytes of memory, and then copies [first,last) into it.
751 template<typename _ForwardIterator
>
753 _M_allocate_and_copy(size_type __n
,
754 _ForwardIterator __first
, _ForwardIterator __last
)
756 pointer __result
= _M_allocate(__n
);
759 uninitialized_copy(__first
, __last
, __result
);
764 _M_deallocate(__result
, __n
);
765 __throw_exception_again
;
770 // Internal constructor functions follow.
772 // Called by the range constructor to implement [23.1.1]/9
773 template<typename _Integer
>
775 _M_initialize_dispatch(_Integer __n
, _Integer __value
, __true_type
)
777 this->_M_start
= _M_allocate(__n
);
778 this->_M_end_of_storage
= this->_M_start
+ __n
;
779 this->_M_finish
= uninitialized_fill_n(this->_M_start
, __n
, __value
);
782 // Called by the range constructor to implement [23.1.1]/9
783 template<typename _InputIter
>
785 _M_initialize_dispatch(_InputIter __first
, _InputIter __last
,
788 typedef typename iterator_traits
<_InputIter
>::iterator_category
790 _M_range_initialize(__first
, __last
, _IterCategory());
793 // Called by the second initialize_dispatch above
794 template<typename _InputIterator
>
796 _M_range_initialize(_InputIterator __first
,
797 _InputIterator __last
, input_iterator_tag
)
799 for ( ; __first
!= __last
; ++__first
)
803 // Called by the second initialize_dispatch above
804 template<typename _ForwardIterator
>
806 _M_range_initialize(_ForwardIterator __first
,
807 _ForwardIterator __last
, forward_iterator_tag
)
809 size_type __n
= std::distance(__first
, __last
);
810 this->_M_start
= _M_allocate(__n
);
811 this->_M_end_of_storage
= this->_M_start
+ __n
;
812 this->_M_finish
= uninitialized_copy(__first
, __last
,
817 // Internal assign functions follow. The *_aux functions do the actual
818 // assignment work for the range versions.
820 // Called by the range assign to implement [23.1.1]/9
821 template<typename _Integer
>
823 _M_assign_dispatch(_Integer __n
, _Integer __val
, __true_type
)
825 _M_fill_assign(static_cast<size_type
>(__n
),
826 static_cast<value_type
>(__val
));
829 // Called by the range assign to implement [23.1.1]/9
830 template<typename _InputIter
>
832 _M_assign_dispatch(_InputIter __first
, _InputIter __last
, __false_type
)
834 typedef typename iterator_traits
<_InputIter
>::iterator_category
836 _M_assign_aux(__first
, __last
, _IterCategory());
839 // Called by the second assign_dispatch above
840 template<typename _InputIterator
>
842 _M_assign_aux(_InputIterator __first
, _InputIterator __last
,
845 // Called by the second assign_dispatch above
846 template<typename _ForwardIterator
>
848 _M_assign_aux(_ForwardIterator __first
, _ForwardIterator __last
,
849 forward_iterator_tag
);
851 // Called by assign(n,t), and the range assign when it turns out
852 // to be the same thing.
854 _M_fill_assign(size_type __n
, const value_type
& __val
);
857 // Internal insert functions follow.
859 // Called by the range insert to implement [23.1.1]/9
860 template<typename _Integer
>
862 _M_insert_dispatch(iterator __pos
, _Integer __n
, _Integer __val
,
865 _M_fill_insert(__pos
, static_cast<size_type
>(__n
),
866 static_cast<value_type
>(__val
));
869 // Called by the range insert to implement [23.1.1]/9
870 template<typename _InputIterator
>
872 _M_insert_dispatch(iterator __pos
, _InputIterator __first
,
873 _InputIterator __last
, __false_type
)
875 typedef typename iterator_traits
<_InputIterator
>::iterator_category
877 _M_range_insert(__pos
, __first
, __last
, _IterCategory());
880 // Called by the second insert_dispatch above
881 template<typename _InputIterator
>
883 _M_range_insert(iterator __pos
, _InputIterator __first
,
884 _InputIterator __last
, input_iterator_tag
);
886 // Called by the second insert_dispatch above
887 template<typename _ForwardIterator
>
889 _M_range_insert(iterator __pos
, _ForwardIterator __first
,
890 _ForwardIterator __last
, forward_iterator_tag
);
892 // Called by insert(p,n,x), and the range insert when it turns out to be
895 _M_fill_insert(iterator __pos
, size_type __n
, const value_type
& __x
);
897 // Called by insert(p,x)
899 _M_insert_aux(iterator __position
, const value_type
& __x
);
904 * @brief Vector equality comparison.
905 * @param x A %vector.
906 * @param y A %vector of the same type as @a x.
907 * @return True iff the size and elements of the vectors are equal.
909 * This is an equivalence relation. It is linear in the size of the
910 * vectors. Vectors are considered equivalent if their sizes are equal,
911 * and if corresponding elements compare equal.
913 template<typename _Tp
, typename _Alloc
>
915 operator==(const vector
<_Tp
,_Alloc
>& __x
, const vector
<_Tp
,_Alloc
>& __y
)
917 return __x
.size() == __y
.size() &&
918 equal(__x
.begin(), __x
.end(), __y
.begin());
922 * @brief Vector ordering relation.
923 * @param x A %vector.
924 * @param y A %vector of the same type as @a x.
925 * @return True iff @a x is lexicographically less than @a y.
927 * This is a total ordering relation. It is linear in the size of the
928 * vectors. The elements must be comparable with @c <.
930 * See std::lexicographical_compare() for how the determination is made.
932 template<typename _Tp
, typename _Alloc
>
934 operator<(const vector
<_Tp
,_Alloc
>& __x
, const vector
<_Tp
,_Alloc
>& __y
)
936 return lexicographical_compare(__x
.begin(), __x
.end(),
937 __y
.begin(), __y
.end());
940 /// Based on operator==
941 template<typename _Tp
, typename _Alloc
>
943 operator!=(const vector
<_Tp
,_Alloc
>& __x
, const vector
<_Tp
,_Alloc
>& __y
)
944 { return !(__x
== __y
); }
946 /// Based on operator<
947 template<typename _Tp
, typename _Alloc
>
949 operator>(const vector
<_Tp
,_Alloc
>& __x
, const vector
<_Tp
,_Alloc
>& __y
)
950 { return __y
< __x
; }
952 /// Based on operator<
953 template<typename _Tp
, typename _Alloc
>
955 operator<=(const vector
<_Tp
,_Alloc
>& __x
, const vector
<_Tp
,_Alloc
>& __y
)
956 { return !(__y
< __x
); }
958 /// Based on operator<
959 template<typename _Tp
, typename _Alloc
>
961 operator>=(const vector
<_Tp
,_Alloc
>& __x
, const vector
<_Tp
,_Alloc
>& __y
)
962 { return !(__x
< __y
); }
964 /// See std::vector::swap().
965 template<typename _Tp
, typename _Alloc
>
967 swap(vector
<_Tp
,_Alloc
>& __x
, vector
<_Tp
,_Alloc
>& __y
)
971 #endif /* __GLIBCPP_INTERNAL_VECTOR_H */