]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/23_containers/unordered_multiset/insert/multiset_single_move.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 23_containers / unordered_multiset / insert / multiset_single_move.cc
1 // { dg-do run { target c++11 } }
2
3 // 2010-10-27 Paolo Carlini <paolo.carlini@oracle.com>
4 //
5 // Copyright (C) 2010-2022 Free Software Foundation, Inc.
6 //
7 // This file is part of the GNU ISO C++ Library. This library is free
8 // software; you can redistribute it and/or modify it under the
9 // terms of the GNU General Public License as published by the
10 // Free Software Foundation; either version 3, or (at your option)
11 // any later version.
12 //
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
17 //
18 // You should have received a copy of the GNU General Public License along
19 // with this library; see the file COPYING3. If not see
20 // <http://www.gnu.org/licenses/>.
21
22 // Single-element insert
23
24 #include <iterator>
25 #include <unordered_set>
26 #include <testsuite_hooks.h>
27 #include <testsuite_rvalref.h>
28
29 namespace
30 {
31 template <typename _Tp>
32 std::size_t
33 get_nb_bucket_elems(const std::unordered_multiset<_Tp>& us)
34 {
35 std::size_t nb = 0;
36 for (std::size_t b = 0; b != us.bucket_count(); ++b)
37 nb += us.bucket_size(b);
38 return nb;
39 }
40 }
41
42 void test01()
43 {
44 using __gnu_test::rvalstruct;
45
46 typedef std::unordered_multiset<rvalstruct> Set;
47 Set s;
48 VERIFY( s.empty() );
49
50 Set::iterator i = s.insert(rvalstruct(1));
51 VERIFY( s.size() == 1 );
52 VERIFY( get_nb_bucket_elems(s) == 1 );
53 VERIFY( std::distance(s.begin(), s.end()) == 1 );
54 VERIFY( i == s.begin() );
55 VERIFY( (*i).val == 1 );
56 }
57
58 void test02()
59 {
60 using __gnu_test::rvalstruct;
61
62 typedef std::unordered_multiset<rvalstruct> Set;
63 Set s;
64 VERIFY( s.empty() );
65
66 s.insert(rvalstruct(2));
67 Set::iterator i = s.insert(rvalstruct(2));
68 VERIFY( s.size() == 2 );
69 VERIFY( get_nb_bucket_elems(s) == 2 );
70 VERIFY( std::distance(s.begin(), s.end()) == 2 );
71 VERIFY( (*i).val == 2 );
72
73 Set::iterator i2 = s.begin();
74 ++i2;
75 VERIFY( i == s.begin() || i == i2 );
76 VERIFY( (*(s.begin())).val == 2 && (*i2).val == 2 );
77 }
78
79 int main()
80 {
81 test01();
82 test02();
83 return 0;
84 }