diff options
author | François Dumont <fdumont@gcc.gnu.org> | 2014-09-24 19:55:35 +0000 |
---|---|---|
committer | François Dumont <fdumont@gcc.gnu.org> | 2014-09-24 19:55:35 +0000 |
commit | c6195f588b1b8980b07d53394edaaa2cd6807588 (patch) | |
tree | 6ac18352bbabea764bd719c371cf8c3175164ef1 /libstdc++-v3/testsuite/23_containers/multiset/allocator | |
parent | 00de328a7ac2c812c0ea4f12c44fbd8d71028b91 (diff) | |
download | gcc-c6195f588b1b8980b07d53394edaaa2cd6807588.tar.gz |
re PR libstdc++/29988 (More stl_tree.h enhancements: improving operator=)
2014-09-24 François Dumont <fdumont@gcc.gnu.org>
PR libstdc++/29988
* include/bits/stl_tree.h (_Rb_tree_reuse_or_alloc_node<>): New.
(_Rb_tree_alloc_node<>): New.
(_Rb_tree<>::operator=(_Rb_tree<>&&)): New.
(_Rb_tree<>::_M_assign_unique): New.
(_Rb_tree<>::_M_assign_equal): New.
(_Rb_tree<>): Adapt to reuse allocated nodes as much as possible.
* include/bits/stl_map.h
(std::map<>::operator=(std::map<>&&)): Default implementation.
(std::map<>::operator=(initializer_list<>)): Adapt to use
_Rb_tree::_M_assign_unique.
* include/bits/stl_multimap.h
(std::multimap<>::operator=(std::multimap<>&&)): Default implementation.
(std::multimap<>::operator=(initializer_list<>)): Adapt to use
_Rb_tree::_M_assign_equal.
* include/bits/stl_set.h
(std::set<>::operator=(std::set<>&&)): Default implementation.
(std::set<>::operator=(initializer_list<>)): Adapt to use
_Rb_tree::_M_assign_unique.
* include/bits/stl_multiset.h
(std::multiset<>::operator=(std::multiset<>&&)): Default implementation.
(std::multiset<>::operator=(initializer_list<>)): Adapt to use
_Rb_tree::_M_assign_equal.
* testsuite/23_containers/map/allocator/copy_assign.cc (test03): New.
* testsuite/23_containers/map/allocator/init-list.cc: New.
* testsuite/23_containers/map/allocator/move_assign.cc (test03): New.
* testsuite/23_containers/multimap/allocator/copy_assign.cc
(test03): New.
* testsuite/23_containers/multimap/allocator/init-list.cc: New.
* testsuite/23_containers/multimap/allocator/move_assign.cc
(test03): New.
* testsuite/23_containers/multiset/allocator/copy_assign.cc
(test03): New.
* testsuite/23_containers/multiset/allocator/init-list.cc: New.
* testsuite/23_containers/multiset/allocator/move_assign.cc
(test03): New.
* testsuite/23_containers/set/allocator/copy_assign.cc (test03): New.
* testsuite/23_containers/set/allocator/init-list.cc: New.
* testsuite/23_containers/set/allocator/move_assign.cc (test03): New.
From-SVN: r215568
Diffstat (limited to 'libstdc++-v3/testsuite/23_containers/multiset/allocator')
3 files changed, 110 insertions, 0 deletions
diff --git a/libstdc++-v3/testsuite/23_containers/multiset/allocator/copy_assign.cc b/libstdc++-v3/testsuite/23_containers/multiset/allocator/copy_assign.cc index 140af8c4f6b..f5921ab59b0 100644 --- a/libstdc++-v3/testsuite/23_containers/multiset/allocator/copy_assign.cc +++ b/libstdc++-v3/testsuite/23_containers/multiset/allocator/copy_assign.cc @@ -57,9 +57,33 @@ void test02() VERIFY(1 == v2.get_allocator().get_personality()); } +void test03() +{ + bool test __attribute__((unused)) = true; + + using namespace __gnu_test; + + typedef tracker_allocator<int> alloc_type; + typedef std::multiset<int, std::less<int>, alloc_type> test_type; + + tracker_allocator_counter::reset(); + + test_type v1 = { 0, 0 }; + test_type v2 = { 1, 1 }; + + auto allocs = tracker_allocator_counter::get_allocation_count(); + auto constructs = tracker_allocator_counter::get_construct_count(); + + v1 = v2; + + VERIFY( tracker_allocator_counter::get_allocation_count() == allocs ); + VERIFY( tracker_allocator_counter::get_construct_count() == constructs + 2 ); +} + int main() { test01(); test02(); + test03(); return 0; } diff --git a/libstdc++-v3/testsuite/23_containers/multiset/allocator/init-list.cc b/libstdc++-v3/testsuite/23_containers/multiset/allocator/init-list.cc new file mode 100644 index 00000000000..a657ae0f6cf --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/multiset/allocator/init-list.cc @@ -0,0 +1,55 @@ +// Copyright (C) 2014 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. +// + +// { dg-options "-std=gnu++11" } + +#include <set> +#include <testsuite_hooks.h> +#include <testsuite_allocator.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + + using namespace __gnu_test; + + typedef tracker_allocator<int> alloc_type; + typedef std::multiset<int, std::less<int>, alloc_type> test_type; + + tracker_allocator_counter::reset(); + + test_type v1; + v1 = { 0, 0 }; + + auto allocs = tracker_allocator_counter::get_allocation_count(); + auto constructs = tracker_allocator_counter::get_construct_count(); + + VERIFY( allocs != 0 ); + VERIFY( constructs != 0 ); + + // Check no allocation on list initialization. + v1 = { 1, 1 }; + + VERIFY( tracker_allocator_counter::get_allocation_count() == allocs ); + VERIFY( tracker_allocator_counter::get_construct_count() == constructs + 2 ); +} + +int main() +{ + test01(); +} diff --git a/libstdc++-v3/testsuite/23_containers/multiset/allocator/move_assign.cc b/libstdc++-v3/testsuite/23_containers/multiset/allocator/move_assign.cc index 956f885462c..405aff1d3d6 100644 --- a/libstdc++-v3/testsuite/23_containers/multiset/allocator/move_assign.cc +++ b/libstdc++-v3/testsuite/23_containers/multiset/allocator/move_assign.cc @@ -59,9 +59,40 @@ void test02() VERIFY( it == v2.begin() ); } +void test03() +{ + bool test __attribute__((unused)) = true; + + using namespace __gnu_test; + + typedef propagating_allocator<int, false, tracker_allocator<int>> alloc_type; + typedef std::multiset<int, std::less<int>, alloc_type> test_type; + + tracker_allocator_counter::reset(); + + test_type v1(alloc_type(1)); + v1 = { 0, 0 }; + + test_type v2(alloc_type(2)); + v2 = { 2, 2 }; + + auto allocs = tracker_allocator_counter::get_allocation_count(); + auto constructs = tracker_allocator_counter::get_construct_count(); + + // Check no allocation on move assignment with non propagating allocators. + v1 = std::move(v2); + + VERIFY( 1 == v1.get_allocator().get_personality() ); + VERIFY( 2 == v2.get_allocator().get_personality() ); + + VERIFY( tracker_allocator_counter::get_allocation_count() == allocs ); + VERIFY( tracker_allocator_counter::get_construct_count() == constructs + 2 ); +} + int main() { test01(); test02(); + test03(); return 0; } |