vector容器的两种insert方法:
1: insert(const_iterator pos, int count,element);//迭代器指向位置pos插入count个元素element
#if __cplusplus >= 201103L
/**
* @brief Inserts a number of copies of given data into the %vector.
* @param __position A const_iterator into the %vector.
* @param __n Number of elements to be inserted.
* @param __x Data to be inserted.
* @return An iterator that points to the inserted data.
*
* This function will insert a specified number of copies of
* the given data before the location specified by @a position.
*
* Note that this kind of operation could be expensive for a
* %vector and if it is frequently used the user should
* consider using std::list.
*/
iterator insert(const_iterator __position, size_type __n, const value_type& __x)
{
difference_type __offset = __position - cbegin();
_M_fill_insert(begin() + __offset, __n, __x);
return begin() + __offset;
}
#else
/**
* @brief Inserts a number of copies of given data into the %vector.
* @param __position An iterator into the %vector.
* @param __n Number of elements to be inserted.
* @param __x Data to be inserted.
*
* This function will insert a specified number of copies of
* the given data before the location specified by @a position.
*
* Note that this kind of operation could be expensive for a
* %vector and if it is frequently used the user should
* consider using std::list.
*/
void insert(iterator __position, size_type __n, const value_type& __x)
{
_M_fill_insert(__position, __n, __x);
}
#endif
2: insert(const_iterator pos, const char* in,in+len);
#if __cplusplus >= 201103L
/**
* @brief Inserts a range into the %vector.
* @param __position A const_iterator into the %vector.
* @param __first An input iterator.
* @param __last An input iterator.
* @return An iterator that points to the inserted data.
*
* This function will insert copies of the data in the range
* [__first,__last) into the %vector before the location specified
* by @a pos.
*
* Note that this kind of operation could be expensive for a
* %vector and if it is frequently used the user should
* consider using std::list.
*/
template<typename _InputIterator, typename = std::_RequireInputIter<_InputIterator>>
iterator insert(const_iterator __position, _InputIterator __first, _InputIterator __last)
{
difference_type __offset = __position - cbegin();
_M_insert_dispatch(begin() + __offset, __first, __last, __false_type());
return begin() + __offset;
}
#else
/**
* @brief Inserts a range into the %vector.
* @param __position An iterator into the %vector.
* @param __first An input iterator.
* @param __last An input iterator.
*
* This function will insert copies of the data in the range
* [__first,__last) into the %vector before the location specified
* by @a pos.
*
* Note that this kind of operation could be expensive for a
* %vector and if it is frequently used the user should
* consider using std::list.
*/
template<typename _InputIterator>
void insert(iterator __position, _InputIterator __first, _InputIterator __last)
{
// Check whether it's an integral type. If so, it's not an iterator.
typedef typename std::__is_integer<_InputIterator>::__type _Integral;
_M_insert_dispatch(__position, __first, __last, _Integral());
}
#endif