1 // Vector implementation -*- C++ -*-
3 // Copyright (C) 2001, 2002 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>
68 // Since this entire file is within namespace std, there's no reason to
69 // waste two spaces along the left column. Thus the leading indentation is
70 // slightly violated from here on.
74 /// @if maint Primary default version. @endif
77 * See bits/stl_deque.h's _Deque_alloc_base for an explanation.
80 template <typename _Tp
, typename _Allocator
, bool _IsStatic
>
81 class _Vector_alloc_base
84 typedef typename _Alloc_traits
<_Tp
, _Allocator
>::allocator_type
88 get_allocator() const { return _M_data_allocator
; }
90 _Vector_alloc_base(const allocator_type
& __a
)
91 : _M_data_allocator(__a
), _M_start(0), _M_finish(0), _M_end_of_storage(0)
95 allocator_type _M_data_allocator
;
98 _Tp
* _M_end_of_storage
;
101 _M_allocate(size_t __n
) { return _M_data_allocator
.allocate(__n
); }
104 _M_deallocate(_Tp
* __p
, size_t __n
)
105 { if (__p
) _M_data_allocator
.deallocate(__p
, __n
); }
108 /// @if maint Specialization for instanceless allocators. @endif
109 template <typename _Tp
, typename _Allocator
>
110 class _Vector_alloc_base
<_Tp
, _Allocator
, true>
113 typedef typename _Alloc_traits
<_Tp
, _Allocator
>::allocator_type
117 get_allocator() const { return allocator_type(); }
119 _Vector_alloc_base(const allocator_type
&)
120 : _M_start(0), _M_finish(0), _M_end_of_storage(0)
126 _Tp
* _M_end_of_storage
;
128 typedef typename _Alloc_traits
<_Tp
, _Allocator
>::_Alloc_type _Alloc_type
;
131 _M_allocate(size_t __n
) { return _Alloc_type::allocate(__n
); }
134 _M_deallocate(_Tp
* __p
, size_t __n
) { _Alloc_type::deallocate(__p
, __n
);}
140 * See bits/stl_deque.h's _Deque_base for an explanation.
143 template <typename _Tp
, typename _Alloc
>
145 : public _Vector_alloc_base
<_Tp
, _Alloc
,
146 _Alloc_traits
<_Tp
, _Alloc
>::_S_instanceless
>
149 typedef _Vector_alloc_base
<_Tp
, _Alloc
,
150 _Alloc_traits
<_Tp
, _Alloc
>::_S_instanceless
>
152 typedef typename
_Base::allocator_type allocator_type
;
154 _Vector_base(const allocator_type
& __a
)
156 _Vector_base(size_t __n
, const allocator_type
& __a
)
159 _M_start
= _M_allocate(__n
);
160 _M_finish
= _M_start
;
161 _M_end_of_storage
= _M_start
+ __n
;
164 ~_Vector_base() { _M_deallocate(_M_start
, _M_end_of_storage
- _M_start
); }
169 * @brief A standard container which offers fixed time access to individual
170 * elements in any order.
172 * @ingroup Containers
175 * Meets the requirements of a <a href="tables.html#65">container</a>, a
176 * <a href="tables.html#66">reversible container</a>, and a
177 * <a href="tables.html#67">sequence</a>, including the
178 * <a href="tables.html#68">optional sequence requirements</a> with the
179 * %exception of @c push_front and @c pop_front.
181 * In some terminology a %vector can be described as a dynamic C-style array,
182 * it offers fast and efficient access to individual elements in any order
183 * and saves the user from worrying about memory and size allocation.
184 * Subscripting ( @c [] ) access is also provided as with C-style arrays.
186 template <typename _Tp
, typename _Alloc
= allocator
<_Tp
> >
187 class vector
: protected _Vector_base
<_Tp
, _Alloc
>
189 // concept requirements
190 __glibcpp_class_requires(_Tp
, _SGIAssignableConcept
)
192 typedef _Vector_base
<_Tp
, _Alloc
> _Base
;
193 typedef vector
<_Tp
, _Alloc
> vector_type
;
196 typedef _Tp value_type
;
197 typedef value_type
* pointer
;
198 typedef const value_type
* const_pointer
;
199 typedef __gnu_cxx::__normal_iterator
<pointer
, vector_type
> iterator
;
200 typedef __gnu_cxx::__normal_iterator
<const_pointer
, vector_type
>
202 typedef reverse_iterator
<const_iterator
> const_reverse_iterator
;
203 typedef reverse_iterator
<iterator
> reverse_iterator
;
204 typedef value_type
& reference
;
205 typedef const value_type
& const_reference
;
206 typedef size_t size_type
;
207 typedef ptrdiff_t difference_type
;
208 typedef typename
_Base::allocator_type allocator_type
;
212 * These two functions and three data members are all from the top-most
213 * base class, which varies depending on the type of %allocator. They
214 * should be pretty self-explanatory, as %vector uses a simple contiguous
218 using _Base::_M_allocate
;
219 using _Base::_M_deallocate
;
220 using _Base::_M_start
;
221 using _Base::_M_finish
;
222 using _Base::_M_end_of_storage
;
225 // [23.2.4.1] construct/copy/destroy
226 // (assign() and get_allocator() are also listed in this section)
228 * @brief Default constructor creates no elements.
231 vector(const allocator_type
& __a
= allocator_type())
235 * @brief Create a %vector with copies of an exemplar element.
236 * @param n The number of elements to initially create.
237 * @param value An element to copy.
239 * This constructor fills the %vector with @a n copies of @a value.
241 vector(size_type __n
, const value_type
& __value
,
242 const allocator_type
& __a
= allocator_type())
244 { _M_finish
= uninitialized_fill_n(_M_start
, __n
, __value
); }
247 * @brief Create a %vector with default elements.
248 * @param n The number of elements to initially create.
250 * This constructor fills the %vector with @a n copies of a
251 * default-constructed element.
254 vector(size_type __n
)
255 : _Base(__n
, allocator_type())
256 { _M_finish
= uninitialized_fill_n(_M_start
, __n
, _Tp()); }
259 * @brief %Vector copy constructor.
260 * @param x A %vector of identical element and allocator types.
262 * The newly-created %vector uses a copy of the allocation object used
263 * by @a x. All the elements of @a x are copied, 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 { _M_finish
= uninitialized_copy(__x
.begin(), __x
.end(), _M_start
); }
271 * @brief Builds a %vector from a range.
272 * @param first An input iterator.
273 * @param last An input iterator.
275 * Creats a %vector consisting of copies of the elements from [first,last).
277 * If the iterators are forward, bidirectional, or random-access, then
278 * this will call the elements' copy constructor N times (where N is
279 * distance(first,last)) and do no memory reallocation. But if only
280 * input iterators are used, then this will do at most 2N calls to the
281 * copy constructor, and logN memory reallocations.
283 template <typename _InputIterator
>
284 vector(_InputIterator __first
, _InputIterator __last
,
285 const allocator_type
& __a
= allocator_type())
288 // Check whether it's an integral type. If so, it's not an iterator.
289 typedef typename _Is_integer
<_InputIterator
>::_Integral _Integral
;
290 _M_initialize_dispatch(__first
, __last
, _Integral());
294 * The dtor only erases the elements, and note that if the elements
295 * themselves are pointers, the pointed-to memory is not touched in any
296 * way. Managing the pointer is the user's responsibilty.
298 ~vector() { _Destroy(_M_start
, _M_finish
); }
301 * @brief %Vector assignment operator.
302 * @param x A %vector of identical element and allocator types.
304 * All the elements of @a x are copied, but any extra memory in @a x (for
305 * fast expansion) will not be copied. Unlike the copy constructor, the
306 * allocator object is not copied.
309 operator=(const vector
& __x
);
312 * @brief Assigns a given value to a %vector.
313 * @param n Number of elements to be assigned.
314 * @param val Value to be assigned.
316 * This function fills a %vector with @a n copies of the given value.
317 * Note that the assignment completely changes the %vector and that the
318 * resulting %vector's size is the same as the number of elements assigned.
319 * Old data may be lost.
322 assign(size_type __n
, const value_type
& __val
) { _M_fill_assign(__n
, __val
); }
325 * @brief Assigns a range to a %vector.
326 * @param first An input iterator.
327 * @param last An input iterator.
329 * This function fills a %vector with copies of the elements in the
330 * range [first,last).
332 * Note that the assignment completely changes the %vector and that the
333 * resulting %vector's size is the same as the number of elements assigned.
334 * Old data may be lost.
336 template<typename _InputIterator
>
338 assign(_InputIterator __first
, _InputIterator __last
)
340 // Check whether it's an integral type. If so, it's not an iterator.
341 typedef typename _Is_integer
<_InputIterator
>::_Integral _Integral
;
342 _M_assign_dispatch(__first
, __last
, _Integral());
345 /// Get a copy of the memory allocation object.
347 get_allocator() const { return _Base::get_allocator(); }
351 * Returns a read/write iterator that points to the first element in the
352 * %vector. Iteration is done in ordinary element order.
355 begin() { return iterator (_M_start
); }
358 * Returns a read-only (constant) iterator that points to the first element
359 * in the %vector. Iteration is done in ordinary element order.
362 begin() const { return const_iterator (_M_start
); }
365 * Returns a read/write iterator that points one past the last element in
366 * the %vector. Iteration is done in ordinary element order.
369 end() { return iterator (_M_finish
); }
372 * Returns a read-only (constant) iterator that points one past the last
373 * element in the %vector. Iteration is done in ordinary element order.
376 end() const { return const_iterator (_M_finish
); }
379 * Returns a read/write reverse iterator that points to the last element in
380 * the %vector. Iteration is done in reverse element order.
383 rbegin() { return reverse_iterator(end()); }
386 * Returns a read-only (constant) reverse iterator that points to the last
387 * element in the %vector. Iteration is done in reverse element order.
389 const_reverse_iterator
390 rbegin() const { return const_reverse_iterator(end()); }
393 * Returns a read/write reverse iterator that points to one before the
394 * first element in the %vector. Iteration is done in reverse element
398 rend() { return reverse_iterator(begin()); }
401 * Returns a read-only (constant) reverse iterator that points to one
402 * before the first element in the %vector. Iteration is done in reverse
405 const_reverse_iterator
406 rend() const { return const_reverse_iterator(begin()); }
408 // [23.2.4.2] capacity
409 /** Returns the number of elements in the %vector. */
411 size() const { return size_type(end() - begin()); }
413 /** Returns the size() of the largest possible %vector. */
415 max_size() const { return size_type(-1) / sizeof(value_type
); }
418 * @brief Resizes the %vector to the specified number of elements.
419 * @param new_size Number of elements the %vector should contain.
420 * @param x Data with which new elements should be populated.
422 * This function will %resize the %vector to the specified number of
423 * elements. If the number is smaller than the %vector's current size the
424 * %vector is truncated, otherwise the %vector is extended and new elements
425 * are populated with given data.
428 resize(size_type __new_size
, const value_type
& __x
)
430 if (__new_size
< size())
431 erase(begin() + __new_size
, end());
433 insert(end(), __new_size
- size(), __x
);
437 * @brief Resizes the %vector to the specified number of elements.
438 * @param new_size Number of elements the %vector should contain.
440 * This function will resize the %vector to the specified number of
441 * elements. If the number is smaller than the %vector's current size the
442 * %vector is truncated, otherwise the %vector is extended and new elements
443 * are default-constructed.
446 resize(size_type __new_size
) { resize(__new_size
, value_type()); }
449 * Returns the total number of elements that the %vector can hold before
450 * needing to allocate more memory.
454 { return size_type(const_iterator(_M_end_of_storage
) - begin()); }
457 * Returns true if the %vector is empty. (Thus begin() would equal end().)
460 empty() const { return begin() == end(); }
463 * @brief Attempt to preallocate enough memory for specified number of
465 * @param n Number of elements required.
466 * @throw std::length_error If @a n exceeds @c max_size().
468 * This function attempts to reserve enough memory for the %vector to hold
469 * the specified number of elements. If the number requested is more than
470 * max_size(), length_error is thrown.
472 * The advantage of this function is that if optimal code is a necessity
473 * and the user can determine the number of elements that will be required,
474 * the user can reserve the memory in %advance, and thus prevent a possible
475 * reallocation of memory and copying of %vector data.
478 reserve(size_type __n
);
482 * @brief Subscript access to the data contained in the %vector.
483 * @param n The index of the element for which data should be accessed.
484 * @return Read/write reference to data.
486 * This operator allows for easy, array-style, data access.
487 * Note that data access with this operator is unchecked and out_of_range
488 * lookups are not defined. (For checked lookups see at().)
491 operator[](size_type __n
) { return *(begin() + __n
); }
492 // XXX do we need to convert to normal_iterator first?
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-only (constant) reference to data.
499 * This operator allows for easy, array-style, data access.
500 * Note that data access with this operator is unchecked and out_of_range
501 * lookups are not defined. (For checked lookups see at().)
504 operator[](size_type __n
) const { return *(begin() + __n
); }
507 /// @if maint Safety check used only from at(). @endif
509 _M_range_check(size_type __n
) const
511 if (__n
>= this->size())
512 __throw_out_of_range("vector [] access out of range");
517 * @brief Provides access to the data contained in the %vector.
518 * @param n The index of the element for which data should be accessed.
519 * @return Read/write reference to data.
520 * @throw std::out_of_range If @a n is an invalid index.
522 * This function provides for safer data access. The parameter is first
523 * checked that it is in the range of the vector. The function throws
524 * out_of_range if the check fails.
527 at(size_type __n
) { _M_range_check(__n
); return (*this)[__n
]; }
530 * @brief Provides access to the data contained in the %vector.
531 * @param n The index of the element for which data should be accessed.
532 * @return Read-only (constant) reference to data.
533 * @throw std::out_of_range If @a n is an invalid index.
535 * This function provides for safer data access. The parameter is first
536 * checked that it is in the range of the vector. The function throws
537 * out_of_range if the check fails.
540 at(size_type __n
) const { _M_range_check(__n
); return (*this)[__n
]; }
543 * Returns a read/write reference to the data at the first element of the
547 front() { return *begin(); }
548 // XXX do we need to convert to normal_iterator first?
551 * Returns a read-only (constant) reference to the data at the first
552 * element of the %vector.
555 front() const { return *begin(); }
558 * Returns a read/write reference to the data at the last element of the
562 back() { return *(end() - 1); }
565 * Returns a read-only (constant) reference to the data at the last
566 * element of the %vector.
569 back() const { return *(end() - 1); }
571 // [23.2.4.3] modifiers
573 * @brief Add data to the end of the %vector.
574 * @param x Data to be added.
576 * This is a typical stack operation. The function creates an element at
577 * the end of the %vector and assigns the given data to it.
578 * Due to the nature of a %vector this operation can be done in constant
579 * time if the %vector has preallocated space available.
582 push_back(const value_type
& __x
)
584 if (_M_finish
!= _M_end_of_storage
)
586 _Construct(_M_finish
, __x
);
590 _M_insert_aux(end(), __x
);
594 * @brief Removes last element.
596 * This is a typical stack operation. It shrinks the %vector by one.
598 * Note that no data is returned, and if the last element's data is
599 * needed, it should be retrieved before pop_back() is called.
609 * @brief Inserts given value into %vector before specified iterator.
610 * @param position An iterator into the %vector.
611 * @param x Data to be inserted.
612 * @return An iterator that points to the inserted data.
614 * This function will insert a copy of the given value before the specified
616 * Note that this kind of operation could be expensive for a %vector and if
617 * it is frequently used the user should consider using std::list.
620 insert(iterator __position
, const value_type
& __x
);
622 #ifdef _GLIBCPP_DEPRECATED
624 * @brief Inserts an element into the %vector.
625 * @param position An iterator into the %vector.
626 * @return An iterator that points to the inserted element.
628 * This function will insert a default-constructed element before the
629 * specified location. You should consider using
630 * insert(position,value_type()) instead.
631 * Note that this kind of operation could be expensive for a vector and if
632 * it is frequently used the user should consider using std::list.
634 * @note This was deprecated in 3.2 and will be removed in 3.3. You must
635 * define @c _GLIBCPP_DEPRECATED to make this visible in 3.2; see
639 insert(iterator __position
)
640 { return insert(__position
, value_type()); }
644 * @brief Inserts a number of copies of given data into the %vector.
645 * @param position An iterator into the %vector.
646 * @param n Number of elements to be inserted.
647 * @param x Data to be inserted.
649 * This function will insert a specified number of copies of the given data
650 * before the location specified by @a position.
652 * Note that this kind of operation could be expensive for a %vector and if
653 * it is frequently used the user should consider using std::list.
656 insert (iterator __pos
, size_type __n
, const value_type
& __x
)
657 { _M_fill_insert(__pos
, __n
, __x
); }
660 * @brief Inserts a range into the %vector.
661 * @param pos An iterator into the %vector.
662 * @param first An input iterator.
663 * @param last An input iterator.
665 * This function will insert copies of the data in the range [first,last)
666 * into the %vector before the location specified by @a pos.
668 * Note that this kind of operation could be expensive for a %vector and if
669 * it is frequently used the user should consider using std::list.
671 template<typename _InputIterator
>
673 insert(iterator __pos
, _InputIterator __first
, _InputIterator __last
)
675 // Check whether it's an integral type. If so, it's not an iterator.
676 typedef typename _Is_integer
<_InputIterator
>::_Integral _Integral
;
677 _M_insert_dispatch(__pos
, __first
, __last
, _Integral());
681 * @brief Remove element at given position.
682 * @param position Iterator pointing to element to be erased.
683 * @return An iterator pointing to the next element (or end()).
685 * This function will erase the element at the given position and thus
686 * shorten the %vector by one.
688 * Note This operation could be expensive and if it is frequently used the
689 * user should consider using std::list. The user is also cautioned that
690 * this function only erases the element, and that if the element is itself
691 * a pointer, 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 erased.
701 * @return An iterator pointing to the element pointed to by @a last
702 * prior to erasing (or end()).
704 * This function will erase the elements in the range [first,last) and
705 * shorten the %vector accordingly.
707 * Note This operation could be expensive and if it is frequently used the
708 * user should consider using std::list. The user is also cautioned that
709 * this function only erases the elements, and that if the elements
710 * themselves are pointers, the pointed-to memory is not touched in any
711 * way. Managing the pointer is the user's responsibilty.
714 erase(iterator __first
, iterator __last
);
717 * @brief Swaps data with another %vector.
718 * @param x A %vector of the same element and allocator types.
720 * This exchanges the elements between two vectors in constant time.
721 * (Three pointers, so it should be quite fast.)
722 * Note that the global std::swap() function is specialized such that
723 * std::swap(v1,v2) will feed to this function.
728 std::swap(_M_start
, __x
._M_start
);
729 std::swap(_M_finish
, __x
._M_finish
);
730 std::swap(_M_end_of_storage
, __x
._M_end_of_storage
);
734 * Erases all the elements. Note that this function only erases the
735 * elements, and that if the elements themselves are pointers, the
736 * pointed-to memory is not touched in any way. Managing the pointer is
737 * the user's responsibilty.
740 clear() { erase(begin(), end()); }
745 * Memory expansion handler. Uses the member allocation function to
746 * obtain @a n bytes of memory, and then copies [first,last) into it.
749 template <typename _ForwardIterator
>
751 _M_allocate_and_copy(size_type __n
,
752 _ForwardIterator __first
, _ForwardIterator __last
)
754 pointer __result
= _M_allocate(__n
);
757 uninitialized_copy(__first
, __last
, __result
);
762 _M_deallocate(__result
, __n
);
763 __throw_exception_again
;
768 // Internal constructor functions follow.
770 // called by the range constructor to implement [23.1.1]/9
771 template<typename _Integer
>
773 _M_initialize_dispatch(_Integer __n
, _Integer __value
, __true_type
)
775 _M_start
= _M_allocate(__n
);
776 _M_end_of_storage
= _M_start
+ __n
;
777 _M_finish
= uninitialized_fill_n(_M_start
, __n
, __value
);
780 // called by the range constructor to implement [23.1.1]/9
781 template<typename _InputIter
>
783 _M_initialize_dispatch(_InputIter __first
, _InputIter __last
, __false_type
)
785 typedef typename iterator_traits
<_InputIter
>::iterator_category
787 _M_range_initialize(__first
, __last
, _IterCategory());
790 // called by the second initialize_dispatch above
791 template <typename _InputIterator
>
793 _M_range_initialize(_InputIterator __first
,
794 _InputIterator __last
, input_iterator_tag
)
796 for ( ; __first
!= __last
; ++__first
)
800 // called by the second initialize_dispatch above
801 template <typename _ForwardIterator
>
802 void _M_range_initialize(_ForwardIterator __first
,
803 _ForwardIterator __last
, forward_iterator_tag
)
805 size_type __n
= distance(__first
, __last
);
806 _M_start
= _M_allocate(__n
);
807 _M_end_of_storage
= _M_start
+ __n
;
808 _M_finish
= uninitialized_copy(__first
, __last
, _M_start
);
812 // Internal assign functions follow. The *_aux functions do the actual
813 // assignment work for the range versions.
815 // called by the range assign to implement [23.1.1]/9
816 template<typename _Integer
>
818 _M_assign_dispatch(_Integer __n
, _Integer __val
, __true_type
)
820 _M_fill_assign(static_cast<size_type
>(__n
),
821 static_cast<value_type
>(__val
));
824 // called by the range assign to implement [23.1.1]/9
825 template<typename _InputIter
>
827 _M_assign_dispatch(_InputIter __first
, _InputIter __last
, __false_type
)
829 typedef typename iterator_traits
<_InputIter
>::iterator_category
831 _M_assign_aux(__first
, __last
, _IterCategory());
834 // called by the second assign_dispatch above
835 template <typename _InputIterator
>
837 _M_assign_aux(_InputIterator __first
, _InputIterator __last
,
840 // called by the second assign_dispatch above
841 template <typename _ForwardIterator
>
843 _M_assign_aux(_ForwardIterator __first
, _ForwardIterator __last
,
844 forward_iterator_tag
);
846 // Called by assign(n,t), and the range assign when it turns out to be the
849 _M_fill_assign(size_type __n
, const value_type
& __val
);
852 // Internal insert functions follow.
854 // called by the range insert to implement [23.1.1]/9
855 template<typename _Integer
>
857 _M_insert_dispatch(iterator __pos
, _Integer __n
, _Integer __val
,
860 _M_fill_insert(__pos
, static_cast<size_type
>(__n
),
861 static_cast<value_type
>(__val
));
864 // called by the range insert to implement [23.1.1]/9
865 template<typename _InputIterator
>
867 _M_insert_dispatch(iterator __pos
, _InputIterator __first
,
868 _InputIterator __last
, __false_type
)
870 typedef typename iterator_traits
<_InputIterator
>::iterator_category
872 _M_range_insert(__pos
, __first
, __last
, _IterCategory());
875 // called by the second insert_dispatch above
876 template <typename _InputIterator
>
878 _M_range_insert(iterator __pos
,
879 _InputIterator __first
, _InputIterator __last
,
882 // called by the second insert_dispatch above
883 template <typename _ForwardIterator
>
885 _M_range_insert(iterator __pos
,
886 _ForwardIterator __first
, _ForwardIterator __last
,
887 forward_iterator_tag
);
889 // Called by insert(p,n,x), and the range insert when it turns out to be
892 _M_fill_insert (iterator __pos
, size_type __n
, const value_type
& __x
);
894 // called by insert(p,x)
896 _M_insert_aux(iterator __position
, const value_type
& __x
);
898 #ifdef _GLIBCPP_DEPRECATED
899 // unused now (same situation as in deque)
900 void _M_insert_aux(iterator __position
);
906 * @brief Vector equality comparison.
907 * @param x A %vector.
908 * @param y A %vector of the same type as @a x.
909 * @return True iff the size and elements of the vectors are equal.
911 * This is an equivalence relation. It is linear in the size of the
912 * vectors. Vectors are considered equivalent if their sizes are equal,
913 * and if corresponding elements compare equal.
915 template <typename _Tp
, typename _Alloc
>
917 operator==(const vector
<_Tp
, _Alloc
>& __x
, const vector
<_Tp
, _Alloc
>& __y
)
919 return __x
.size() == __y
.size() &&
920 equal(__x
.begin(), __x
.end(), __y
.begin());
924 * @brief Vector ordering relation.
925 * @param x A %vector.
926 * @param y A %vector of the same type as @a x.
927 * @return True iff @a x is lexographically less than @a y.
929 * This is a total ordering relation. It is linear in the size of the
930 * vectors. The elements must be comparable with @c <.
932 * See std::lexographical_compare() for how the determination is made.
934 template <typename _Tp
, typename _Alloc
>
936 operator<(const vector
<_Tp
, _Alloc
>& __x
, const vector
<_Tp
, _Alloc
>& __y
)
938 return lexicographical_compare(__x
.begin(), __x
.end(),
939 __y
.begin(), __y
.end());
942 /// Based on operator==
943 template <typename _Tp
, typename _Alloc
>
945 operator!=(const vector
<_Tp
, _Alloc
>& __x
, const vector
<_Tp
, _Alloc
>& __y
) {
946 return !(__x
== __y
);
949 /// Based on operator<
950 template <typename _Tp
, typename _Alloc
>
952 operator>(const vector
<_Tp
, _Alloc
>& __x
, const vector
<_Tp
, _Alloc
>& __y
) {
956 /// Based on operator<
957 template <typename _Tp
, typename _Alloc
>
959 operator<=(const vector
<_Tp
, _Alloc
>& __x
, const vector
<_Tp
, _Alloc
>& __y
) {
963 /// Based on operator<
964 template <typename _Tp
, typename _Alloc
>
966 operator>=(const vector
<_Tp
, _Alloc
>& __x
, const vector
<_Tp
, _Alloc
>& __y
) {
970 /// See std::vector::swap().
971 template <typename _Tp
, typename _Alloc
>
972 inline void swap(vector
<_Tp
, _Alloc
>& __x
, vector
<_Tp
, _Alloc
>& __y
)
979 #endif /* __GLIBCPP_INTERNAL_VECTOR_H */