mirror of
git://gcc.gnu.org/git/gcc.git
synced 2025-02-24 00:59:38 +08:00
stl_deque.h (deque<>::resize, [...]): Avoid troubles with ADL, user defined operators and _Deque_iterator.
2005-12-19 Paolo Carlini <pcarlini@suse.de> * include/bits/stl_deque.h (deque<>::resize, _M_fill_assign): Avoid troubles with ADL, user defined operators and _Deque_iterator. (operator-(const _Deque_iterator<>&, const _Deque_iterator<>&): Add overload for left and right iterators of the same type. * include/bits/deque.tcc (erase(iterator)): Avoid troubles with ADL, user defined operators and _Deque_iterator. * testsuite/23_containers/deque/types/1.cc: Add. * include/bits/deque.tcc (_M_insert_aux(iterator, size_type, const value_type&)): Qualify with std:: fill call. From-SVN: r108827
This commit is contained in:
parent
31ec030f39
commit
1b4454bfd5
@ -1,3 +1,16 @@
|
|||||||
|
2005-12-19 Paolo Carlini <pcarlini@suse.de>
|
||||||
|
|
||||||
|
* include/bits/stl_deque.h (deque<>::resize, _M_fill_assign):
|
||||||
|
Avoid troubles with ADL, user defined operators and _Deque_iterator.
|
||||||
|
(operator-(const _Deque_iterator<>&, const _Deque_iterator<>&):
|
||||||
|
Add overload for left and right iterators of the same type.
|
||||||
|
* include/bits/deque.tcc (erase(iterator)): Avoid troubles with ADL,
|
||||||
|
user defined operators and _Deque_iterator.
|
||||||
|
* testsuite/23_containers/deque/types/1.cc: Add.
|
||||||
|
|
||||||
|
* include/bits/deque.tcc (_M_insert_aux(iterator, size_type,
|
||||||
|
const value_type&)): Qualify with std:: fill call.
|
||||||
|
|
||||||
2005-12-18 Benjamin Kosnik <bkoz@redhat.com>
|
2005-12-18 Benjamin Kosnik <bkoz@redhat.com>
|
||||||
|
|
||||||
* include/bits/c++config: Add in revised namespace associations.
|
* include/bits/c++config: Add in revised namespace associations.
|
||||||
|
@ -87,14 +87,14 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD)
|
|||||||
template <typename _Tp, typename _Alloc>
|
template <typename _Tp, typename _Alloc>
|
||||||
typename deque<_Tp, _Alloc>::iterator
|
typename deque<_Tp, _Alloc>::iterator
|
||||||
deque<_Tp, _Alloc>::
|
deque<_Tp, _Alloc>::
|
||||||
insert(iterator position, const value_type& __x)
|
insert(iterator __position, const value_type& __x)
|
||||||
{
|
{
|
||||||
if (position._M_cur == this->_M_impl._M_start._M_cur)
|
if (__position._M_cur == this->_M_impl._M_start._M_cur)
|
||||||
{
|
{
|
||||||
push_front(__x);
|
push_front(__x);
|
||||||
return this->_M_impl._M_start;
|
return this->_M_impl._M_start;
|
||||||
}
|
}
|
||||||
else if (position._M_cur == this->_M_impl._M_finish._M_cur)
|
else if (__position._M_cur == this->_M_impl._M_finish._M_cur)
|
||||||
{
|
{
|
||||||
push_back(__x);
|
push_back(__x);
|
||||||
iterator __tmp = this->_M_impl._M_finish;
|
iterator __tmp = this->_M_impl._M_finish;
|
||||||
@ -102,7 +102,7 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD)
|
|||||||
return __tmp;
|
return __tmp;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return _M_insert_aux(position, __x);
|
return _M_insert_aux(__position, __x);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename _Tp, typename _Alloc>
|
template <typename _Tp, typename _Alloc>
|
||||||
@ -112,8 +112,8 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD)
|
|||||||
{
|
{
|
||||||
iterator __next = __position;
|
iterator __next = __position;
|
||||||
++__next;
|
++__next;
|
||||||
const size_type __index = __position - begin();
|
const difference_type __index = __position - begin();
|
||||||
if (__index < (size() >> 1))
|
if (static_cast<size_type>(__index) < (size() >> 1))
|
||||||
{
|
{
|
||||||
if (__position != begin())
|
if (__position != begin())
|
||||||
std::copy_backward(begin(), __position, __next);
|
std::copy_backward(begin(), __position, __next);
|
||||||
@ -185,8 +185,7 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD)
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
std::__uninitialized_fill_a(__new_start, this->_M_impl._M_start,
|
std::__uninitialized_fill_a(__new_start, this->_M_impl._M_start,
|
||||||
__x,
|
__x, _M_get_Tp_allocator());
|
||||||
_M_get_Tp_allocator());
|
|
||||||
this->_M_impl._M_start = __new_start;
|
this->_M_impl._M_start = __new_start;
|
||||||
}
|
}
|
||||||
catch(...)
|
catch(...)
|
||||||
@ -483,7 +482,7 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD)
|
|||||||
_M_get_Tp_allocator());
|
_M_get_Tp_allocator());
|
||||||
this->_M_impl._M_start = __new_start;
|
this->_M_impl._M_start = __new_start;
|
||||||
std::copy(__start_n, __pos, __old_start);
|
std::copy(__start_n, __pos, __old_start);
|
||||||
fill(__pos - difference_type(__n), __pos, __x_copy);
|
std::fill(__pos - difference_type(__n), __pos, __x_copy);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -321,6 +321,17 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD)
|
|||||||
// According to the resolution of DR179 not only the various comparison
|
// According to the resolution of DR179 not only the various comparison
|
||||||
// operators but also operator- must accept mixed iterator/const_iterator
|
// operators but also operator- must accept mixed iterator/const_iterator
|
||||||
// parameters.
|
// parameters.
|
||||||
|
template<typename _Tp, typename _Ref, typename _Ptr>
|
||||||
|
inline typename _Deque_iterator<_Tp, _Ref, _Ptr>::difference_type
|
||||||
|
operator-(const _Deque_iterator<_Tp, _Ref, _Ptr>& __x,
|
||||||
|
const _Deque_iterator<_Tp, _Ref, _Ptr>& __y)
|
||||||
|
{
|
||||||
|
return typename _Deque_iterator<_Tp, _Ref, _Ptr>::difference_type
|
||||||
|
(_Deque_iterator<_Tp, _Ref, _Ptr>::_S_buffer_size())
|
||||||
|
* (__x._M_node - __y._M_node - 1) + (__x._M_cur - __x._M_first)
|
||||||
|
+ (__y._M_last - __y._M_cur);
|
||||||
|
}
|
||||||
|
|
||||||
template<typename _Tp, typename _RefL, typename _PtrL,
|
template<typename _Tp, typename _RefL, typename _PtrL,
|
||||||
typename _RefR, typename _PtrR>
|
typename _RefR, typename _PtrR>
|
||||||
inline typename _Deque_iterator<_Tp, _RefL, _PtrL>::difference_type
|
inline typename _Deque_iterator<_Tp, _RefL, _PtrL>::difference_type
|
||||||
@ -871,7 +882,7 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD)
|
|||||||
{
|
{
|
||||||
const size_type __len = size();
|
const size_type __len = size();
|
||||||
if (__new_size < __len)
|
if (__new_size < __len)
|
||||||
_M_erase_at_end(this->_M_impl._M_start + __new_size);
|
_M_erase_at_end(this->_M_impl._M_start + difference_type(__new_size));
|
||||||
else
|
else
|
||||||
insert(this->_M_impl._M_finish, __new_size - __len, __x);
|
insert(this->_M_impl._M_finish, __new_size - __len, __x);
|
||||||
}
|
}
|
||||||
@ -1097,7 +1108,7 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD)
|
|||||||
* specified location.
|
* specified location.
|
||||||
*/
|
*/
|
||||||
iterator
|
iterator
|
||||||
insert(iterator position, const value_type& __x);
|
insert(iterator __position, const value_type& __x);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Inserts a number of copies of given data into the %deque.
|
* @brief Inserts a number of copies of given data into the %deque.
|
||||||
@ -1318,7 +1329,7 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_M_erase_at_end(begin() + __n);
|
_M_erase_at_end(begin() + difference_type(__n));
|
||||||
std::fill(begin(), end(), __val);
|
std::fill(begin(), end(), __val);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1491,7 +1502,7 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD)
|
|||||||
* @endif
|
* @endif
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
_M_reserve_map_at_back (size_type __nodes_to_add = 1)
|
_M_reserve_map_at_back(size_type __nodes_to_add = 1)
|
||||||
{
|
{
|
||||||
if (__nodes_to_add + 1 > this->_M_impl._M_map_size
|
if (__nodes_to_add + 1 > this->_M_impl._M_map_size
|
||||||
- (this->_M_impl._M_finish._M_node - this->_M_impl._M_map))
|
- (this->_M_impl._M_finish._M_node - this->_M_impl._M_map))
|
||||||
|
55
libstdc++-v3/testsuite/23_containers/deque/types/1.cc
Normal file
55
libstdc++-v3/testsuite/23_containers/deque/types/1.cc
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
// 2005-12-18 Paolo Carlini <pcarlini@suse.de>
|
||||||
|
|
||||||
|
// Copyright (C) 2005 Free Software Foundation, Inc.
|
||||||
|
//
|
||||||
|
// This file is part of the GNU ISO C++ Library. This library is free
|
||||||
|
// software; you can redistribute it and/or modify it under the
|
||||||
|
// terms of the GNU General Public License as published by the
|
||||||
|
// Free Software Foundation; either version 2, or (at your option)
|
||||||
|
// any later version.
|
||||||
|
|
||||||
|
// This library is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
|
||||||
|
// You should have received a copy of the GNU General Public License along
|
||||||
|
// with this library; see the file COPYING. If not, write to the Free
|
||||||
|
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
|
||||||
|
// USA.
|
||||||
|
|
||||||
|
// { dg-do compile }
|
||||||
|
|
||||||
|
#include <deque>
|
||||||
|
|
||||||
|
namespace N
|
||||||
|
{
|
||||||
|
struct X { };
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
X operator+(T, std::size_t)
|
||||||
|
{ return X(); }
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
X operator-(T, T)
|
||||||
|
{ return X(); }
|
||||||
|
}
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
std::deque<N::X> d(5);
|
||||||
|
const std::deque<N::X> e(1);
|
||||||
|
|
||||||
|
d[0];
|
||||||
|
e[0];
|
||||||
|
d.size();
|
||||||
|
d.erase(d.begin());
|
||||||
|
d.resize(1);
|
||||||
|
d.assign(1, N::X());
|
||||||
|
d.insert(d.begin(), N::X());
|
||||||
|
d.insert(d.begin(), 1, N::X());
|
||||||
|
d.insert(d.begin(), e.begin(), e.end());
|
||||||
|
d = e;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user