+2013-06-30 Paolo Carlini <paolo.carlini@oracle.com>
+
+ * include/bits/stl_deque.h (deque<>::insert(iterator,
+ size_type, const value_type&), deque<>::insert(iterator,
+ initializer_list<>), deque<>::insert(iterator, _InputIterator,
+ _InputIterator)): Adjust C++11 signatures to take a const_iterator.
+ * include/bits/stl_vector.h: Likewise.
+ * include/bits/stl_bvector.h: Likewise.
+ * include/debug/deque: Adjust.
+ * include/debug/vector: Likewise.
+ * include/profile/deque: Likewise.
+ * include/profile/vector: Likewise.
+ * testsuite/23_containers/deque/modifiers/insert/const_iterator.cc:
+ Extend.
+ * testsuite/23_containers/vector/bool/modifiers/insert/
+ const_iterator.cc: Likewise.
+ * testsuite/23_containers/vector/modifiers/insert/const_iterator.cc:
+ Likewise.
+
+ * testsuite/23_containers/deque/requirements/dr438/assign_neg.cc:
+ Adjust dg-error line number.
+ * testsuite/23_containers/deque/requirements/dr438/
+ constructor_1_neg.cc: Likewise.
+ * testsuite/23_containers/deque/requirements/dr438/
+ constructor_2_neg.cc: Likewise.
+ * testsuite/23_containers/deque/requirements/dr438/insert_neg.cc:
+ Likewise.
+ * testsuite/23_containers/vector/requirements/dr438/assign_neg.cc:
+ Likewise.
+ * testsuite/23_containers/vector/requirements/dr438/
+ constructor_1_neg.cc: Likewise.
+ * testsuite/23_containers/vector/requirements/dr438/
+ constructor_2_neg.cc: Likewise.
+ * testsuite/23_containers/vector/requirements/dr438/insert_neg.cc:
+ Likewise.
+
2013-06-27 Paolo Carlini <paolo.carlini@oracle.com>
* testsuite/21_strings/basic_string/operations/*: Move inside
#if __cplusplus >= 201103L
template<typename _InputIterator,
typename = std::_RequireInputIter<_InputIterator>>
- void
- insert(iterator __position,
+ iterator
+ insert(const_iterator __position,
_InputIterator __first, _InputIterator __last)
- { _M_insert_dispatch(__position, __first, __last, __false_type()); }
+ {
+ difference_type __offset = __position - cbegin();
+ _M_insert_dispatch(__position._M_const_cast(),
+ __first, __last, __false_type());
+ return begin() + __offset;
+ }
#else
template<typename _InputIterator>
void
}
#endif
+#if __cplusplus >= 201103L
+ iterator
+ insert(const_iterator __position, size_type __n, const bool& __x)
+ {
+ difference_type __offset = __position - cbegin();
+ _M_fill_insert(__position._M_const_cast(), __n, __x);
+ return begin() + __offset;
+ }
+#else
void
insert(iterator __position, size_type __n, const bool& __x)
{ _M_fill_insert(__position, __n, __x); }
+#endif
#if __cplusplus >= 201103L
- void insert(iterator __p, initializer_list<bool> __l)
- { this->insert(__p, __l.begin(), __l.end()); }
+ iterator
+ insert(const_iterator __p, initializer_list<bool> __l)
+ { return this->insert(__p, __l.begin(), __l.end()); }
#endif
void
* initializer_list @a __l into the %deque before the location
* specified by @a __p. This is known as <em>list insert</em>.
*/
- void
- insert(iterator __p, initializer_list<value_type> __l)
- { this->insert(__p, __l.begin(), __l.end()); }
+ iterator
+ insert(const_iterator __p, initializer_list<value_type> __l)
+ { return this->insert(__p, __l.begin(), __l.end()); }
#endif
+#if __cplusplus >= 201103L
+ /**
+ * @brief Inserts a number of copies of given data into the %deque.
+ * @param __position A const_iterator into the %deque.
+ * @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.
+ */
+ iterator
+ insert(const_iterator __position, size_type __n, const value_type& __x)
+ {
+ difference_type __offset = __position - cbegin();
+ _M_fill_insert(__position._M_const_cast(), __n, __x);
+ return begin() + __offset;
+ }
+#else
/**
* @brief Inserts a number of copies of given data into the %deque.
* @param __position An iterator into the %deque.
void
insert(iterator __position, size_type __n, const value_type& __x)
{ _M_fill_insert(__position, __n, __x); }
+#endif
+#if __cplusplus >= 201103L
/**
* @brief Inserts a range into the %deque.
- * @param __position An iterator into the %deque.
+ * @param __position A const_iterator into the %deque.
* @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 %deque before the location specified
* by @a __position. This is known as <em>range insert</em>.
*/
-#if __cplusplus >= 201103L
template<typename _InputIterator,
typename = std::_RequireInputIter<_InputIterator>>
- void
- insert(iterator __position, _InputIterator __first,
+ iterator
+ insert(const_iterator __position, _InputIterator __first,
_InputIterator __last)
- { _M_insert_dispatch(__position, __first, __last, __false_type()); }
+ {
+ difference_type __offset = __position - cbegin();
+ _M_insert_dispatch(__position._M_const_cast(),
+ __first, __last, __false_type());
+ return begin() + __offset;
+ }
#else
+ /**
+ * @brief Inserts a range into the %deque.
+ * @param __position An iterator into the %deque.
+ * @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 %deque before the location specified
+ * by @a __position. This is known as <em>range insert</em>.
+ */
template<typename _InputIterator>
void
insert(iterator __position, _InputIterator __first,
* %vector and if it is frequently used the user should
* consider using std::list.
*/
- void
- insert(iterator __position, initializer_list<value_type> __l)
- { this->insert(__position, __l.begin(), __l.end()); }
+ iterator
+ insert(const_iterator __position, initializer_list<value_type> __l)
+ { return this->insert(__position, __l.begin(), __l.end()); }
#endif
+#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(__position._M_const_cast(), __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.
void
insert(iterator __position, size_type __n, const value_type& __x)
{ _M_fill_insert(__position, __n, __x); }
+#endif
+#if __cplusplus >= 201103L
/**
* @brief Inserts a range into the %vector.
- * @param __position An iterator 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
* %vector and if it is frequently used the user should
* consider using std::list.
*/
-#if __cplusplus >= 201103L
template<typename _InputIterator,
typename = std::_RequireInputIter<_InputIterator>>
- void
- insert(iterator __position, _InputIterator __first,
+ iterator
+ insert(const_iterator __position, _InputIterator __first,
_InputIterator __last)
- { _M_insert_dispatch(__position, __first, __last, __false_type()); }
+ {
+ difference_type __offset = __position - cbegin();
+ _M_insert_dispatch(__position._M_const_cast(),
+ __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,
insert(const_iterator __position, _Tp&& __x)
{ return emplace(__position, std::move(__x)); }
- void
- insert(iterator __p, initializer_list<value_type> __l)
+ iterator
+ insert(const_iterator __position, initializer_list<value_type> __l)
{
- _Base::insert(__p, __l);
+ __glibcxx_check_insert(__position);
+ _Base_iterator __res = _Base::insert(__position.base(), __l);
this->_M_invalidate_all();
+ return iterator(__res, this);
}
#endif
+#if __cplusplus >= 201103L
+ iterator
+ insert(const_iterator __position, size_type __n, const _Tp& __x)
+ {
+ __glibcxx_check_insert(__position);
+ _Base_iterator __res = _Base::insert(__position.base(), __n, __x);
+ this->_M_invalidate_all();
+ return iterator(__res, this);
+ }
+#else
void
insert(iterator __position, size_type __n, const _Tp& __x)
{
_Base::insert(__position.base(), __n, __x);
this->_M_invalidate_all();
}
+#endif
#if __cplusplus >= 201103L
template<class _InputIterator,
typename = std::_RequireInputIter<_InputIterator>>
+ iterator
+ insert(const_iterator __position,
+ _InputIterator __first, _InputIterator __last)
+ {
+ __glibcxx_check_insert_range(__position, __first, __last);
+ _Base_iterator __res = _Base::insert(__position.base(),
+ __gnu_debug::__base(__first),
+ __gnu_debug::__base(__last));
+ this->_M_invalidate_all();
+ return iterator(__res, this);
+ }
#else
template<class _InputIterator>
-#endif
void
insert(iterator __position,
_InputIterator __first, _InputIterator __last)
__gnu_debug::__base(__last));
this->_M_invalidate_all();
}
+#endif
void
pop_front()
insert(const_iterator __position, _Tp&& __x)
{ return emplace(__position, std::move(__x)); }
- void
- insert(iterator __position, initializer_list<value_type> __l)
- { this->insert(__position, __l.begin(), __l.end()); }
+ iterator
+ insert(const_iterator __position, initializer_list<value_type> __l)
+ { return this->insert(__position, __l.begin(), __l.end()); }
#endif
+#if __cplusplus >= 201103L
+ iterator
+ insert(const_iterator __position, size_type __n, const _Tp& __x)
+ {
+ __glibcxx_check_insert(__position);
+ bool __realloc = _M_requires_reallocation(this->size() + __n);
+ difference_type __offset = __position.base() - _Base::cbegin();
+ _Base_iterator __res = _Base::insert(__position.base(), __n, __x);
+ if (__realloc)
+ this->_M_invalidate_all();
+ else
+ this->_M_invalidate_after_nth(__offset);
+ _M_update_guaranteed_capacity();
+ return iterator(__res, this);
+ }
+#else
void
insert(iterator __position, size_type __n, const _Tp& __x)
{
this->_M_invalidate_after_nth(__offset);
_M_update_guaranteed_capacity();
}
+#endif
#if __cplusplus >= 201103L
template<class _InputIterator,
typename = std::_RequireInputIter<_InputIterator>>
+ iterator
+ insert(const_iterator __position,
+ _InputIterator __first, _InputIterator __last)
+ {
+ __glibcxx_check_insert_range(__position, __first, __last);
+
+ /* Hard to guess if invalidation will occur, because __last
+ - __first can't be calculated in all cases, so we just
+ punt here by checking if it did occur. */
+ _Base_iterator __old_begin = _M_base().begin();
+ difference_type __offset = __position.base() - _Base::cbegin();
+ _Base_iterator __res = _Base::insert(__position.base(),
+ __gnu_debug::__base(__first),
+ __gnu_debug::__base(__last));
+
+ if (_M_base().begin() != __old_begin)
+ this->_M_invalidate_all();
+ else
+ this->_M_invalidate_after_nth(__offset);
+ _M_update_guaranteed_capacity();
+ return iterator(__res, this);
+ }
#else
template<class _InputIterator>
-#endif
void
insert(iterator __position,
_InputIterator __first, _InputIterator __last)
this->_M_invalidate_after_nth(__offset);
_M_update_guaranteed_capacity();
}
+#endif
iterator
#if __cplusplus >= 201103L
insert(const_iterator __position, _Tp&& __x)
{ return emplace(__position, std::move(__x)); }
- void
- insert(iterator __p, initializer_list<value_type> __l)
- {
- _Base::insert(__p, __l);
- }
+ iterator
+ insert(const_iterator __p, initializer_list<value_type> __l)
+ { return _Base::insert(__p, __l); }
#endif
+#if __cplusplus >= 201103L
+ iterator
+ insert(const_iterator __position, size_type __n, const _Tp& __x)
+ { return _Base::insert(__position, __n, __x); }
+#else
void
insert(iterator __position, size_type __n, const _Tp& __x)
- {
- _Base::insert(__position, __n, __x);
- }
+ { _Base::insert(__position, __n, __x); }
+#endif
#if __cplusplus >= 201103L
template<typename _InputIterator,
typename = std::_RequireInputIter<_InputIterator>>
+ iterator
+ insert(const_iterator __position,
+ _InputIterator __first, _InputIterator __last)
+ { return _Base::insert(__position, __first, __last); }
#else
template<typename _InputIterator>
-#endif
void
insert(iterator __position,
_InputIterator __first, _InputIterator __last)
- {
- _Base::insert(__position, __first, __last);
- }
+ { _Base::insert(__position, __first, __last); }
+#endif
void
pop_front()
{
typedef _GLIBCXX_STD_C::vector<_Tp, _Allocator> _Base;
+ typedef typename _Base::iterator _Base_iterator;
+ typedef typename _Base::const_iterator _Base_const_iterator;
+
#if __cplusplus >= 201103L
typedef __gnu_cxx::__alloc_traits<_Allocator> _Alloc_traits;
#endif
typedef typename _Base::reference reference;
typedef typename _Base::const_reference const_reference;
- typedef __iterator_tracker<typename _Base::iterator, vector>
+ typedef __iterator_tracker<_Base_iterator, vector>
iterator;
- typedef __iterator_tracker<typename _Base::const_iterator, vector>
+ typedef __iterator_tracker<_Base_const_iterator, vector>
const_iterator;
typedef typename _Base::size_type size_type;
__profcxx_vector_insert(this, __position.base() - _Base::begin(),
this->size());
size_type __old_size = this->capacity();
- typename _Base::iterator __res = _Base::insert(__position.base(), __x);
+ _Base_iterator __res = _Base::insert(__position.base(), __x);
_M_profile_resize(this, __old_size, this->capacity());
return iterator(__res, this);
}
iterator
insert(const_iterator __position, _Tp&& __x)
{
- __profcxx_vector_insert(this, __position.base() - _Base::begin(),
+ __profcxx_vector_insert(this, __position.base() - _Base::cbegin(),
this->size());
size_type __old_size = this->capacity();
- typename _Base::iterator __res = _Base::insert(__position.base(), __x);
+ _Base_iterator __res = _Base::insert(__position.base(), __x);
_M_profile_resize(this, __old_size, this->capacity());
return iterator(__res, this);
}
iterator
emplace(const_iterator __position, _Args&&... __args)
{
- typename _Base::iterator __res
- = _Base::emplace(__position.base(),
- std::forward<_Args>(__args)...);
+ _Base_iterator __res = _Base::emplace(__position.base(),
+ std::forward<_Args>(__args)...);
return iterator(__res, this);
}
- void
- insert(iterator __position, initializer_list<value_type> __l)
- { this->insert(__position, __l.begin(), __l.end()); }
+ iterator
+ insert(const_iterator __position, initializer_list<value_type> __l)
+ { return this->insert(__position, __l.begin(), __l.end()); }
#endif
#if __cplusplus >= 201103L
void
swap(vector& __x)
#if __cplusplus >= 201103L
- noexcept(_Alloc_traits::_S_nothrow_swap())
+ noexcept(_Alloc_traits::_S_nothrow_swap())
#endif
{
_Base::swap(__x);
}
+#if __cplusplus >= 201103L
+ iterator
+ insert(const_iterator __position, size_type __n, const _Tp& __x)
+ {
+ __profcxx_vector_insert(this, __position.base() - _Base::cbegin(),
+ this->size());
+ size_type __old_size = this->capacity();
+ _Base_iterator __res = _Base::insert(__position, __n, __x);
+ _M_profile_resize(this, __old_size, this->capacity());
+ return iterator(__res, this);
+ }
+#else
void
insert(iterator __position, size_type __n, const _Tp& __x)
{
_Base::insert(__position, __n, __x);
_M_profile_resize(this, __old_size, this->capacity());
}
+#endif
#if __cplusplus >= 201103L
template<typename _InputIterator,
typename = std::_RequireInputIter<_InputIterator>>
+ iterator
+ insert(const_iterator __position,
+ _InputIterator __first, _InputIterator __last)
+ {
+ __profcxx_vector_insert(this, __position.base() - _Base::cbegin(),
+ this->size());
+ size_type __old_size = this->capacity();
+ _Base_iterator __res = _Base::insert(__position, __first, __last);
+ _M_profile_resize(this, __old_size, this->capacity());
+ return iterator(__res, this);
+ }
#else
template<typename _InputIterator>
+ void
+ insert(iterator __position,
+ _InputIterator __first, _InputIterator __last)
+ {
+ __profcxx_vector_insert(this, __position.base() - _Base::begin(),
+ this->size());
+ size_type __old_size = this->capacity();
+ _Base::insert(__position, __first, __last);
+ _M_profile_resize(this, __old_size, this->capacity());
+ }
#endif
- void
- insert(iterator __position,
- _InputIterator __first, _InputIterator __last)
- {
- __profcxx_vector_insert(this, __position.base()-_Base::begin(),
- this->size());
- size_type __old_size = this->capacity();
- _Base::insert(__position, __first, __last);
- _M_profile_resize(this, __old_size, this->capacity());
- }
iterator
#if __cplusplus >= 201103L
erase(iterator __position)
#endif
{
- typename _Base::iterator __res = _Base::erase(__position.base());
+ _Base_iterator __res = _Base::erase(__position.base());
return iterator(__res, this);
}
{
// _GLIBCXX_RESOLVE_LIB_DEFECTS
// 151. can't currently clear() empty container
- typename _Base::iterator __res = _Base::erase(__first.base(),
- __last.base());
+ _Base_iterator __res = _Base::erase(__first.base(), __last.base());
return iterator(__res, this);
}
{
std::deque<int> d1;
int n = 0;
- d1.insert(d1.cbegin(), n);
- d1.insert(d1.cbegin(), 1);
+ std::deque<int>::iterator it = d1.insert(d1.cbegin(), n);
+ it = d1.insert(d1.cbegin(), 1);
+ it = d1.insert(d1.cbegin(), {2, 3});
+ it = d1.insert(d1.cbegin(), 1, 4);
+ it = d1.insert(d1.cbegin(), d1.begin(), d1.end());
}
// <http://www.gnu.org/licenses/>.
// { dg-do compile }
-// { dg-error "no matching" "" { target *-*-* } 1724 }
+// { dg-error "no matching" "" { target *-*-* } 1760 }
#include <deque>
// <http://www.gnu.org/licenses/>.
// { dg-do compile }
-// { dg-error "no matching" "" { target *-*-* } 1657 }
+// { dg-error "no matching" "" { target *-*-* } 1693 }
#include <deque>
// <http://www.gnu.org/licenses/>.
// { dg-do compile }
-// { dg-error "no matching" "" { target *-*-* } 1657 }
+// { dg-error "no matching" "" { target *-*-* } 1693 }
#include <deque>
#include <utility>
// <http://www.gnu.org/licenses/>.
// { dg-do compile }
-// { dg-error "no matching" "" { target *-*-* } 1808 }
+// { dg-error "no matching" "" { target *-*-* } 1844 }
#include <deque>
void test01()
{
std::vector<bool> vb1;
- vb1.insert(vb1.cbegin(), true);
+ std::vector<bool>::iterator it = vb1.insert(vb1.cbegin(), true);
+ it = vb1.insert(vb1.cbegin(), {false, true});
+ it = vb1.insert(vb1.cbegin(), 1, false);
+ it = vb1.insert(vb1.cbegin(), vb1.begin(), vb1.end());
}
{
std::vector<int> v1;
int n = 0;
- v1.insert(v1.cbegin(), n);
- v1.insert(v1.cbegin(), 1);
+ std::vector<int>::iterator it = v1.insert(v1.cbegin(), n);
+ it = v1.insert(v1.cbegin(), 1);
+ it = v1.insert(v1.cbegin(), {2, 3});
+ it = v1.insert(v1.cbegin(), 1, 4);
+ it = v1.insert(v1.cbegin(), v1.begin(), v1.end());
}
// <http://www.gnu.org/licenses/>.
// { dg-do compile }
-// { dg-error "no matching" "" { target *-*-* } 1264 }
+// { dg-error "no matching" "" { target *-*-* } 1308 }
#include <vector>
// <http://www.gnu.org/licenses/>.
// { dg-do compile }
-// { dg-error "no matching" "" { target *-*-* } 1190 }
+// { dg-error "no matching" "" { target *-*-* } 1234 }
#include <vector>
// <http://www.gnu.org/licenses/>.
// { dg-do compile }
-// { dg-error "no matching" "" { target *-*-* } 1190 }
+// { dg-error "no matching" "" { target *-*-* } 1234 }
#include <vector>
#include <utility>
// <http://www.gnu.org/licenses/>.
// { dg-do compile }
-// { dg-error "no matching" "" { target *-*-* } 1305 }
+// { dg-error "no matching" "" { target *-*-* } 1349 }
#include <vector>