From: Paolo Carlini Date: Sun, 8 Jan 2006 17:34:32 +0000 (+0000) Subject: PR libstdc++/22102 (insert as close to hint as possible) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=cf1e03717aecec7390802df60679b2921a4d3f91;p=gcc.git PR libstdc++/22102 (insert as close to hint as possible) 2006-01-08 Paolo Carlini PR libstdc++/22102 (insert as close to hint as possible) * include/bits/stl_tree.h (_Rb_tree<>::_M_insert_lower, _M_insert_equal_lower): New. (_M_insert_equal(iterator, const _Val&), _M_insert_equal(const_iterator, const _Val&)): Use the above. * docs/html/ext/howto.html: Add an entry for DR 233. * testsuite/23_containers/multiset/modifiers/insert/22102.cc: New. * testsuite/23_containers/multimap/modifiers/insert/22102.cc: New. * testsuite/23_containers/set/insert/: Move... * testsuite/23_containers/set/modifiers/insert/: ...here. * testsuite/23_containers/map/insert/: Move... * testsuite/23_containers/map/modifiers/insert/: ...here. * testsuite/23_containers/multiset/insert/: Move... * testsuite/23_containers/multiset/modifiers/insert/: ...here. From-SVN: r109473 --- diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 820d7c15833..5e5e1b86ffd 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,21 @@ +2006-01-08 Paolo Carlini + + PR libstdc++/22102 (insert as close to hint as possible) + * include/bits/stl_tree.h (_Rb_tree<>::_M_insert_lower, + _M_insert_equal_lower): New. + (_M_insert_equal(iterator, const _Val&), + _M_insert_equal(const_iterator, const _Val&)): Use the above. + * docs/html/ext/howto.html: Add an entry for DR 233. + * testsuite/23_containers/multiset/modifiers/insert/22102.cc: New. + * testsuite/23_containers/multimap/modifiers/insert/22102.cc: New. + + * testsuite/23_containers/set/insert/: Move... + * testsuite/23_containers/set/modifiers/insert/: ...here. + * testsuite/23_containers/map/insert/: Move... + * testsuite/23_containers/map/modifiers/insert/: ...here. + * testsuite/23_containers/multiset/insert/: Move... + * testsuite/23_containers/multiset/modifiers/insert/: ...here. + 2006-01-06 Paolo Carlini * include/bits/stl_tree.h (_Rb_tree<>::insert_unique): Rename diff --git a/libstdc++-v3/docs/html/ext/howto.html b/libstdc++-v3/docs/html/ext/howto.html index 9d86bc04162..bc0b358b9f3 100644 --- a/libstdc++-v3/docs/html/ext/howto.html +++ b/libstdc++-v3/docs/html/ext/howto.html @@ -399,6 +399,13 @@ is specified in the conversion specification. +
233: + Insertion hints in associative containers +
+
Implement N1780, first check before then check after, insert as close + to hint as possible. +
+
235: No specification of default ctor for reverse_iterator
diff --git a/libstdc++-v3/include/bits/stl_tree.h b/libstdc++-v3/include/bits/stl_tree.h index 031e37f44fb..ecea171c457 100644 --- a/libstdc++-v3/include/bits/stl_tree.h +++ b/libstdc++-v3/include/bits/stl_tree.h @@ -548,6 +548,11 @@ _GLIBCXX_BEGIN_NAMESPACE(std) iterator _M_insert(_Base_ptr __x, _Base_ptr __y, const value_type& __v); + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 233. Insertion hints in associative containers. + iterator + _M_insert_lower(_Base_ptr __x, _Base_ptr __y, const value_type& __v); + const_iterator _M_insert(_Const_Base_ptr __x, _Const_Base_ptr __y, const value_type& __v); @@ -657,6 +662,11 @@ _GLIBCXX_BEGIN_NAMESPACE(std) iterator _M_insert_equal(const value_type& __x); + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 233. Insertion hints in associative containers. + iterator + _M_insert_equal_lower(const value_type& __x); + iterator _M_insert_unique(iterator __position, const value_type& __x); @@ -833,6 +843,24 @@ _GLIBCXX_BEGIN_NAMESPACE(std) return iterator(__z); } + template + typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator + _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>:: + _M_insert_lower(_Base_ptr __x, _Base_ptr __p, const _Val& __v) + { + bool __insert_left = (__x != 0 || __p == _M_end() + || !_M_impl._M_key_compare(_S_key(__p), + _KeyOfValue()(__v))); + + _Link_type __z = _M_create_node(__v); + + _Rb_tree_insert_and_rebalance(__insert_left, __z, __p, + this->_M_impl._M_header); + ++_M_impl._M_node_count; + return iterator(__z); + } + template typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::const_iterator @@ -869,6 +897,23 @@ _GLIBCXX_BEGIN_NAMESPACE(std) return _M_insert(__x, __y, __v); } + template + typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator + _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>:: + _M_insert_equal_lower(const _Val& __v) + { + _Link_type __x = _M_begin(); + _Link_type __y = _M_end(); + while (__x != 0) + { + __y = __x; + __x = !_M_impl._M_key_compare(_S_key(__x), _KeyOfValue()(__v)) ? + _S_left(__x) : _S_right(__x); + } + return _M_insert_lower(__x, __y, __v); + } + template void @@ -1110,7 +1155,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) return _M_insert(__after._M_node, __after._M_node, __v); } else - return _M_insert_equal(__v); + return _M_insert_equal_lower(__v); } } @@ -1164,7 +1209,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) return _M_insert(__after._M_node, __after._M_node, __v); } else - return const_iterator(_M_insert_equal(__v)); + return const_iterator(_M_insert_equal_lower(__v)); } } diff --git a/libstdc++-v3/testsuite/23_containers/map/insert/1.cc b/libstdc++-v3/testsuite/23_containers/map/insert/1.cc deleted file mode 100644 index 7bf7a6cb96a..00000000000 --- a/libstdc++-v3/testsuite/23_containers/map/insert/1.cc +++ /dev/null @@ -1,68 +0,0 @@ -// 2001-08-23 pme & Sylvain.Pion@sophia.inria.fr - -// Copyright (C) 2001, 2003, 2004, 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. - -// 23.3.1.2, table 69 -- map::insert(p,t) - -#include -#include - -// { dg-do run } - -// libstdc++/3349 and -// http://gcc.gnu.org/ml/gcc-patches/2001-08/msg01375.html -void test01() -{ - bool test __attribute__((unused)) = true; - typedef std::map Map; - Map M; - Map::iterator hint; - - hint = M.insert(Map::value_type(7, 0)).first; - - M.insert(hint, Map::value_type(8, 1)); - M.insert(M.begin(), Map::value_type(9, 2)); - -#if 0 - // The tree's __rb_verify() member must be exposed in map<> before this - // will even compile. It's good test to see that "missing" entries are - // in fact present in the {map,tree}, but in the wrong place. - if (0) - { - Map::iterator i = M.begin(); - while (i != M.end()) { - std::cerr << '(' << i->first << ',' << i->second << ")\n"; - ++i; - } - std::cerr << "tree internal verify: " - << std::boolalpha << M.__rb_verify() << "\n"; - } -#endif - - VERIFY ( M.find(7) != M.end() ); - VERIFY ( M.find(8) != M.end() ); - VERIFY ( M.find(9) != M.end() ); -} - -int main() -{ - test01(); - return 0; -} - diff --git a/libstdc++-v3/testsuite/23_containers/map/insert/16813.cc b/libstdc++-v3/testsuite/23_containers/map/insert/16813.cc deleted file mode 100644 index 1132aad7748..00000000000 --- a/libstdc++-v3/testsuite/23_containers/map/insert/16813.cc +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright (C) 2004 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. - -#include -#include - -// libstdc++/16813 -void test01() -{ - using debug::map; - bool test __attribute__((unused)) = true; - - map m1, m2; - - m1[3] = 3.0f; - m1[11] = -67.0f; - - m2.insert(m1.begin(), m1.end()); - - VERIFY( m1 == m2 ); -} - -int main() -{ - test01(); - return 0; -} diff --git a/libstdc++-v3/testsuite/23_containers/map/modifiers/insert/1.cc b/libstdc++-v3/testsuite/23_containers/map/modifiers/insert/1.cc new file mode 100644 index 00000000000..7bf7a6cb96a --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/map/modifiers/insert/1.cc @@ -0,0 +1,68 @@ +// 2001-08-23 pme & Sylvain.Pion@sophia.inria.fr + +// Copyright (C) 2001, 2003, 2004, 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. + +// 23.3.1.2, table 69 -- map::insert(p,t) + +#include +#include + +// { dg-do run } + +// libstdc++/3349 and +// http://gcc.gnu.org/ml/gcc-patches/2001-08/msg01375.html +void test01() +{ + bool test __attribute__((unused)) = true; + typedef std::map Map; + Map M; + Map::iterator hint; + + hint = M.insert(Map::value_type(7, 0)).first; + + M.insert(hint, Map::value_type(8, 1)); + M.insert(M.begin(), Map::value_type(9, 2)); + +#if 0 + // The tree's __rb_verify() member must be exposed in map<> before this + // will even compile. It's good test to see that "missing" entries are + // in fact present in the {map,tree}, but in the wrong place. + if (0) + { + Map::iterator i = M.begin(); + while (i != M.end()) { + std::cerr << '(' << i->first << ',' << i->second << ")\n"; + ++i; + } + std::cerr << "tree internal verify: " + << std::boolalpha << M.__rb_verify() << "\n"; + } +#endif + + VERIFY ( M.find(7) != M.end() ); + VERIFY ( M.find(8) != M.end() ); + VERIFY ( M.find(9) != M.end() ); +} + +int main() +{ + test01(); + return 0; +} + diff --git a/libstdc++-v3/testsuite/23_containers/map/modifiers/insert/16813.cc b/libstdc++-v3/testsuite/23_containers/map/modifiers/insert/16813.cc new file mode 100644 index 00000000000..1132aad7748 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/map/modifiers/insert/16813.cc @@ -0,0 +1,42 @@ +// Copyright (C) 2004 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. + +#include +#include + +// libstdc++/16813 +void test01() +{ + using debug::map; + bool test __attribute__((unused)) = true; + + map m1, m2; + + m1[3] = 3.0f; + m1[11] = -67.0f; + + m2.insert(m1.begin(), m1.end()); + + VERIFY( m1 == m2 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/multimap/modifiers/insert/22102.cc b/libstdc++-v3/testsuite/23_containers/multimap/modifiers/insert/22102.cc new file mode 100644 index 00000000000..dfaf4c252d7 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/multimap/modifiers/insert/22102.cc @@ -0,0 +1,141 @@ +// 2006-01-07 Paolo Carlini + +// Copyright (C) 2006 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. + +// 23.3.2 Class template multimap + +#include +#include + +// libstdc++/22102 +void test01() +{ + bool test __attribute__((unused)) = true; + typedef std::multimap Mmap; + typedef Mmap::value_type value_type; + typedef Mmap::iterator iterator; + + Mmap mm1; + + const iterator it1 = mm1.insert(value_type(0, 0)); + const iterator it2 = mm1.insert(value_type(1, 1)); + const iterator it3 = mm1.insert(value_type(2, 2)); + + const value_type vt1(2, 1); + const iterator it4 = mm1.insert(it1, vt1); + iterator it5 = it4; + iterator it6 = it4; + VERIFY( mm1.size() == 4 ); + VERIFY( *it4 == vt1 ); + VERIFY( ++it5 == it3 ); + VERIFY( --it6 == it2 ); + VERIFY( *it5 == *it3 ); + VERIFY( *it6 == *it2 ); + + const value_type vt2(2, 0); + const iterator it7 = mm1.insert(mm1.begin(), vt2); + iterator it8 = it7; + iterator it9 = it7; + VERIFY( mm1.size() == 5 ); + VERIFY( *it7 == vt2 ); + VERIFY( ++it8 == it4 ); + VERIFY( --it9 == it2 ); + VERIFY( *it8 == *it4 ); + VERIFY( *it9 == *it2 ); + + const value_type vt3(2, -1); + const iterator it10 = mm1.insert(it1, vt3); + iterator it11 = it10; + iterator it12 = it10; + VERIFY( mm1.size() == 6 ); + VERIFY( *it10 == vt3 ); + VERIFY( ++it11 == it7 ); + VERIFY( --it12 == it2 ); + VERIFY( *it11 == *it7 ); + VERIFY( *it12 == *it2 ); + + const value_type vt4(0, 1); + const iterator it13 = mm1.insert(it10, vt4); + iterator it14 = it13; + iterator it15 = it13; + VERIFY( mm1.size() == 7 ); + VERIFY( *it13 == vt4 ); + VERIFY( ++it14 == it2 ); + VERIFY( --it15 == it1 ); + VERIFY( *it14 == *it2 ); + VERIFY( *it15 == *it1 ); + + const value_type vt5(1, 0); + const iterator it16 = mm1.insert(it13, vt5); + iterator it17 = it16; + iterator it18 = it16; + VERIFY( mm1.size() == 8 ); + VERIFY( *it16 == vt5 ); + VERIFY( ++it17 == it2 ); + VERIFY( --it18 == it13 ); + VERIFY( *it17 == *it2 ); + VERIFY( *it18 == *it13 ); + + const value_type vt6(0, -1); + const iterator it19 = mm1.insert(it1, vt6); + iterator it20 = it19; + VERIFY( mm1.size() == 9 ); + VERIFY( *it19 == vt6 ); + VERIFY( it19 == mm1.begin() ); + VERIFY( ++it20 == it1 ); + VERIFY( *it20 == *it1 ); + + const value_type vt7(3, 3); + const iterator it21 = mm1.insert(it19, vt7); + iterator it22 = it21; + iterator it23 = it21; + VERIFY( mm1.size() == 10 ); + VERIFY( *it21 == vt7 ); + VERIFY( ++it22 == mm1.end() ); + VERIFY( --it23 == it3 ); + VERIFY( *it23 == *it3 ); + + const value_type vt8(2, 3); + const iterator it24 = mm1.insert(mm1.end(), vt8); + iterator it25 = it24; + iterator it26 = it24; + VERIFY( mm1.size() == 11 ); + VERIFY( *it24 == vt8 ); + VERIFY( ++it25 == it21 ); + VERIFY( --it26 == it3 ); + VERIFY( *it25 == *it21 ); + VERIFY( *it26 == *it3 ); + + const value_type vt9(3, 2); + const iterator it27 = mm1.insert(it3, vt9); + iterator it28 = it27; + iterator it29 = it27; + VERIFY( mm1.size() == 12 ); + VERIFY( *it27 == vt9 ); + VERIFY( ++it28 == it21 ); + VERIFY( --it29 == it24 ); + VERIFY( *it28 == *it21 ); + VERIFY( *it29 == *it24 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/multiset/insert/1.cc b/libstdc++-v3/testsuite/23_containers/multiset/insert/1.cc deleted file mode 100644 index c1a5de3dc74..00000000000 --- a/libstdc++-v3/testsuite/23_containers/multiset/insert/1.cc +++ /dev/null @@ -1,65 +0,0 @@ -// 1999-06-24 bkoz - -// Copyright (C) 1999, 2004, 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. - -// 23.3.4 template class multiset - -#include -#include -#include -#include -#include - -namespace std -{ - std::ostream& - operator<<(std::ostream& os, std::pair const& p) - { return os << p.first << ' ' << p.second; } -} - -bool -operator<(std::pair const& lhs, std::pair const& rhs) -{ return lhs.first < rhs.first; } - -int main () -{ - bool test __attribute__((unused)) = true; - typedef std::multiset >::iterator iterator; - std::pair p(69, 0); - std::multiset > s; - - for (p.second = 0; p.second < 5; ++p.second) - s.insert(p); - for (iterator it = s.begin(); it != s.end(); ++it) - if (it->second < 5) - { - s.insert(it, p); - ++p.second; - } - - std::ostringstream stream; - std::copy(s.begin(), s.end(), - std::ostream_iterator >(stream, "\n")); - const std::string expected("69 0\n69 1\n69 2\n69 3\n69 4\n" - "69 5\n69 6\n69 7\n69 8\n69 9\n"); - std::string tested(stream.str()); - VERIFY( tested == expected ); - - return 0; -} diff --git a/libstdc++-v3/testsuite/23_containers/multiset/insert/2.cc b/libstdc++-v3/testsuite/23_containers/multiset/insert/2.cc deleted file mode 100644 index 0f654cb0500..00000000000 --- a/libstdc++-v3/testsuite/23_containers/multiset/insert/2.cc +++ /dev/null @@ -1,92 +0,0 @@ -// 2005-01-17 Paolo Carlini - -// 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. -// -// As a special exception, you may use this file as part of a free software -// library without restriction. Specifically, if other files instantiate -// templates or use macros or inline functions from this file, or you compile -// this file and link it with other files to produce an executable, this -// file does not by itself cause the resulting executable to be covered by -// the GNU General Public License. This exception does not however -// invalidate any other reasons why the executable file might be covered by -// the GNU General Public License. - -#include -#include - -// A few tests for insert with hint, in the occasion of libstdc++/19422 -// and libstdc++/19433. -void test01() -{ - bool test __attribute__((unused)) = true; - using namespace std; - - multiset ms0, ms1; - multiset::iterator iter1; - - ms0.insert(1); - ms1.insert(ms1.end(), 1); - VERIFY( ms0 == ms1 ); - - ms0.insert(3); - ms1.insert(ms1.begin(), 3); - VERIFY( ms0 == ms1 ); - - ms0.insert(4); - iter1 = ms1.insert(ms1.end(), 4); - VERIFY( ms0 == ms1 ); - - ms0.insert(6); - ms1.insert(iter1, 6); - VERIFY( ms0 == ms1 ); - - ms0.insert(2); - ms1.insert(ms1.begin(), 2); - VERIFY( ms0 == ms1 ); - - ms0.insert(7); - ms1.insert(ms1.end(), 7); - VERIFY( ms0 == ms1 ); - - ms0.insert(5); - ms1.insert(ms1.find(4), 5); - VERIFY( ms0 == ms1 ); - - ms0.insert(0); - ms1.insert(ms1.end(), 0); - VERIFY( ms0 == ms1 ); - - ms0.insert(8); - ms1.insert(ms1.find(3), 8); - VERIFY( ms0 == ms1 ); - - ms0.insert(9); - ms1.insert(ms1.end(), 9); - VERIFY( ms0 == ms1 ); - - ms0.insert(10); - ms1.insert(ms1.begin(), 10); - VERIFY( ms0 == ms1 ); -} - -int main () -{ - test01(); - return 0; -} diff --git a/libstdc++-v3/testsuite/23_containers/multiset/modifiers/insert/1.cc b/libstdc++-v3/testsuite/23_containers/multiset/modifiers/insert/1.cc new file mode 100644 index 00000000000..c1a5de3dc74 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/multiset/modifiers/insert/1.cc @@ -0,0 +1,65 @@ +// 1999-06-24 bkoz + +// Copyright (C) 1999, 2004, 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. + +// 23.3.4 template class multiset + +#include +#include +#include +#include +#include + +namespace std +{ + std::ostream& + operator<<(std::ostream& os, std::pair const& p) + { return os << p.first << ' ' << p.second; } +} + +bool +operator<(std::pair const& lhs, std::pair const& rhs) +{ return lhs.first < rhs.first; } + +int main () +{ + bool test __attribute__((unused)) = true; + typedef std::multiset >::iterator iterator; + std::pair p(69, 0); + std::multiset > s; + + for (p.second = 0; p.second < 5; ++p.second) + s.insert(p); + for (iterator it = s.begin(); it != s.end(); ++it) + if (it->second < 5) + { + s.insert(it, p); + ++p.second; + } + + std::ostringstream stream; + std::copy(s.begin(), s.end(), + std::ostream_iterator >(stream, "\n")); + const std::string expected("69 0\n69 1\n69 2\n69 3\n69 4\n" + "69 5\n69 6\n69 7\n69 8\n69 9\n"); + std::string tested(stream.str()); + VERIFY( tested == expected ); + + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/multiset/modifiers/insert/2.cc b/libstdc++-v3/testsuite/23_containers/multiset/modifiers/insert/2.cc new file mode 100644 index 00000000000..0f654cb0500 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/multiset/modifiers/insert/2.cc @@ -0,0 +1,92 @@ +// 2005-01-17 Paolo Carlini + +// 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. +// +// As a special exception, you may use this file as part of a free software +// library without restriction. Specifically, if other files instantiate +// templates or use macros or inline functions from this file, or you compile +// this file and link it with other files to produce an executable, this +// file does not by itself cause the resulting executable to be covered by +// the GNU General Public License. This exception does not however +// invalidate any other reasons why the executable file might be covered by +// the GNU General Public License. + +#include +#include + +// A few tests for insert with hint, in the occasion of libstdc++/19422 +// and libstdc++/19433. +void test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + multiset ms0, ms1; + multiset::iterator iter1; + + ms0.insert(1); + ms1.insert(ms1.end(), 1); + VERIFY( ms0 == ms1 ); + + ms0.insert(3); + ms1.insert(ms1.begin(), 3); + VERIFY( ms0 == ms1 ); + + ms0.insert(4); + iter1 = ms1.insert(ms1.end(), 4); + VERIFY( ms0 == ms1 ); + + ms0.insert(6); + ms1.insert(iter1, 6); + VERIFY( ms0 == ms1 ); + + ms0.insert(2); + ms1.insert(ms1.begin(), 2); + VERIFY( ms0 == ms1 ); + + ms0.insert(7); + ms1.insert(ms1.end(), 7); + VERIFY( ms0 == ms1 ); + + ms0.insert(5); + ms1.insert(ms1.find(4), 5); + VERIFY( ms0 == ms1 ); + + ms0.insert(0); + ms1.insert(ms1.end(), 0); + VERIFY( ms0 == ms1 ); + + ms0.insert(8); + ms1.insert(ms1.find(3), 8); + VERIFY( ms0 == ms1 ); + + ms0.insert(9); + ms1.insert(ms1.end(), 9); + VERIFY( ms0 == ms1 ); + + ms0.insert(10); + ms1.insert(ms1.begin(), 10); + VERIFY( ms0 == ms1 ); +} + +int main () +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/multiset/modifiers/insert/22102.cc b/libstdc++-v3/testsuite/23_containers/multiset/modifiers/insert/22102.cc new file mode 100644 index 00000000000..99b808f1b33 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/multiset/modifiers/insert/22102.cc @@ -0,0 +1,141 @@ +// 2006-01-07 Paolo Carlini + +// Copyright (C) 2006 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. + +// 23.3.4 Class template multiset + +#include +#include + +// libstdc++/22102 +void test01() +{ + bool test __attribute__((unused)) = true; + typedef std::multiset Mset; + typedef Mset::value_type value_type; + typedef Mset::iterator iterator; + + Mset ms1; + + const iterator it1 = ms1.insert(value_type(0)); + const iterator it2 = ms1.insert(value_type(1)); + const iterator it3 = ms1.insert(value_type(2)); + + const value_type vt1(2); + const iterator it4 = ms1.insert(it1, vt1); + iterator it5 = it4; + iterator it6 = it4; + VERIFY( ms1.size() == 4 ); + VERIFY( *it4 == vt1 ); + VERIFY( ++it5 == it3 ); + VERIFY( --it6 == it2 ); + VERIFY( *it5 == *it3 ); + VERIFY( *it6 == *it2 ); + + const value_type vt2(2); + const iterator it7 = ms1.insert(ms1.begin(), vt2); + iterator it8 = it7; + iterator it9 = it7; + VERIFY( ms1.size() == 5 ); + VERIFY( *it7 == vt2 ); + VERIFY( ++it8 == it4 ); + VERIFY( --it9 == it2 ); + VERIFY( *it8 == *it4 ); + VERIFY( *it9 == *it2 ); + + const value_type vt3(2); + const iterator it10 = ms1.insert(it1, vt3); + iterator it11 = it10; + iterator it12 = it10; + VERIFY( ms1.size() == 6 ); + VERIFY( *it10 == vt3 ); + VERIFY( ++it11 == it7 ); + VERIFY( --it12 == it2 ); + VERIFY( *it11 == *it7 ); + VERIFY( *it12 == *it2 ); + + const value_type vt4(0); + const iterator it13 = ms1.insert(it10, vt4); + iterator it14 = it13; + iterator it15 = it13; + VERIFY( ms1.size() == 7 ); + VERIFY( *it13 == vt4 ); + VERIFY( ++it14 == it2 ); + VERIFY( --it15 == it1 ); + VERIFY( *it14 == *it2 ); + VERIFY( *it15 == *it1 ); + + const value_type vt5(1); + const iterator it16 = ms1.insert(it13, vt5); + iterator it17 = it16; + iterator it18 = it16; + VERIFY( ms1.size() == 8 ); + VERIFY( *it16 == vt5 ); + VERIFY( ++it17 == it2 ); + VERIFY( --it18 == it13 ); + VERIFY( *it17 == *it2 ); + VERIFY( *it18 == *it13 ); + + const value_type vt6(0); + const iterator it19 = ms1.insert(it1, vt6); + iterator it20 = it19; + VERIFY( ms1.size() == 9 ); + VERIFY( *it19 == vt6 ); + VERIFY( it19 == ms1.begin() ); + VERIFY( ++it20 == it1 ); + VERIFY( *it20 == *it1 ); + + const value_type vt7(3); + const iterator it21 = ms1.insert(it19, vt7); + iterator it22 = it21; + iterator it23 = it21; + VERIFY( ms1.size() == 10 ); + VERIFY( *it21 == vt7 ); + VERIFY( ++it22 == ms1.end() ); + VERIFY( --it23 == it3 ); + VERIFY( *it23 == *it3 ); + + const value_type vt8(2); + const iterator it24 = ms1.insert(ms1.end(), vt8); + iterator it25 = it24; + iterator it26 = it24; + VERIFY( ms1.size() == 11 ); + VERIFY( *it24 == vt8 ); + VERIFY( ++it25 == it21 ); + VERIFY( --it26 == it3 ); + VERIFY( *it25 == *it21 ); + VERIFY( *it26 == *it3 ); + + const value_type vt9(3); + const iterator it27 = ms1.insert(it3, vt9); + iterator it28 = it27; + iterator it29 = it27; + VERIFY( ms1.size() == 12 ); + VERIFY( *it27 == vt9 ); + VERIFY( ++it28 == it21 ); + VERIFY( --it29 == it24 ); + VERIFY( *it28 == *it21 ); + VERIFY( *it29 == *it24 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/set/insert/1.cc b/libstdc++-v3/testsuite/23_containers/set/insert/1.cc deleted file mode 100644 index 22fdf0debbb..00000000000 --- a/libstdc++-v3/testsuite/23_containers/set/insert/1.cc +++ /dev/null @@ -1,92 +0,0 @@ -// 2005-01-17 Paolo Carlini - -// 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. -// -// As a special exception, you may use this file as part of a free software -// library without restriction. Specifically, if other files instantiate -// templates or use macros or inline functions from this file, or you compile -// this file and link it with other files to produce an executable, this -// file does not by itself cause the resulting executable to be covered by -// the GNU General Public License. This exception does not however -// invalidate any other reasons why the executable file might be covered by -// the GNU General Public License. - -#include -#include - -// A few tests for insert with hint, in the occasion of libstdc++/19422 -// and libstdc++/19433. -void test01() -{ - bool test __attribute__((unused)) = true; - using namespace std; - - set s0, s1; - set::iterator iter1; - - s0.insert(1); - s1.insert(s1.end(), 1); - VERIFY( s0 == s1 ); - - s0.insert(3); - s1.insert(s1.begin(), 3); - VERIFY( s0 == s1 ); - - s0.insert(4); - iter1 = s1.insert(s1.end(), 4); - VERIFY( s0 == s1 ); - - s0.insert(6); - s1.insert(iter1, 6); - VERIFY( s0 == s1 ); - - s0.insert(2); - s1.insert(s1.begin(), 2); - VERIFY( s0 == s1 ); - - s0.insert(7); - s1.insert(s1.end(), 7); - VERIFY( s0 == s1 ); - - s0.insert(5); - s1.insert(s1.find(4), 5); - VERIFY( s0 == s1 ); - - s0.insert(0); - s1.insert(s1.end(), 0); - VERIFY( s0 == s1 ); - - s0.insert(8); - s1.insert(s1.find(3), 8); - VERIFY( s0 == s1 ); - - s0.insert(9); - s1.insert(s1.end(), 9); - VERIFY( s0 == s1 ); - - s0.insert(10); - s1.insert(s1.begin(), 10); - VERIFY( s0 == s1 ); -} - -int main () -{ - test01(); - return 0; -} diff --git a/libstdc++-v3/testsuite/23_containers/set/modifiers/insert/1.cc b/libstdc++-v3/testsuite/23_containers/set/modifiers/insert/1.cc new file mode 100644 index 00000000000..22fdf0debbb --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/set/modifiers/insert/1.cc @@ -0,0 +1,92 @@ +// 2005-01-17 Paolo Carlini + +// 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. +// +// As a special exception, you may use this file as part of a free software +// library without restriction. Specifically, if other files instantiate +// templates or use macros or inline functions from this file, or you compile +// this file and link it with other files to produce an executable, this +// file does not by itself cause the resulting executable to be covered by +// the GNU General Public License. This exception does not however +// invalidate any other reasons why the executable file might be covered by +// the GNU General Public License. + +#include +#include + +// A few tests for insert with hint, in the occasion of libstdc++/19422 +// and libstdc++/19433. +void test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + set s0, s1; + set::iterator iter1; + + s0.insert(1); + s1.insert(s1.end(), 1); + VERIFY( s0 == s1 ); + + s0.insert(3); + s1.insert(s1.begin(), 3); + VERIFY( s0 == s1 ); + + s0.insert(4); + iter1 = s1.insert(s1.end(), 4); + VERIFY( s0 == s1 ); + + s0.insert(6); + s1.insert(iter1, 6); + VERIFY( s0 == s1 ); + + s0.insert(2); + s1.insert(s1.begin(), 2); + VERIFY( s0 == s1 ); + + s0.insert(7); + s1.insert(s1.end(), 7); + VERIFY( s0 == s1 ); + + s0.insert(5); + s1.insert(s1.find(4), 5); + VERIFY( s0 == s1 ); + + s0.insert(0); + s1.insert(s1.end(), 0); + VERIFY( s0 == s1 ); + + s0.insert(8); + s1.insert(s1.find(3), 8); + VERIFY( s0 == s1 ); + + s0.insert(9); + s1.insert(s1.end(), 9); + VERIFY( s0 == s1 ); + + s0.insert(10); + s1.insert(s1.begin(), 10); + VERIFY( s0 == s1 ); +} + +int main () +{ + test01(); + return 0; +}