]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/23_containers/multiset/operations/1.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 23_containers / multiset / operations / 1.cc
1 // 2006-11-25 Paolo Carlini <pcarlini@suse.de>
2
3 // Copyright (C) 2006-2020 Free Software Foundation, Inc.
4 //
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 3, or (at your option)
9 // any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING3. If not see
18 // <http://www.gnu.org/licenses/>.
19 //
20
21 #include <set>
22 #include <testsuite_hooks.h>
23
24 // A few tests for equal_range, in the occasion of libstdc++/29385.
25 void test01()
26 {
27 using namespace std;
28
29 multiset<int> ms0;
30 typedef multiset<int>::iterator iterator;
31 typedef multiset<int>::const_iterator const_iterator;
32 pair<iterator, iterator> pp0;
33
34 pp0 = ms0.equal_range(1);
35 VERIFY( ms0.count(1) == 0 );
36 VERIFY( pp0.first == ms0.end() );
37 VERIFY( pp0.second == ms0.end() );
38
39 iterator iter0 = ms0.insert(1);
40 iterator iter1 = ms0.insert(2);
41 iterator iter2 = ms0.insert(3);
42
43 pp0 = ms0.equal_range(2);
44 VERIFY( ms0.count(2) == 1 );
45 VERIFY( *pp0.first == 2 );
46 VERIFY( *pp0.second == 3 );
47 VERIFY( pp0.first == iter1 );
48 VERIFY( --pp0.first == iter0 );
49 VERIFY( pp0.second == iter2 );
50
51 ms0.insert(3);
52 iterator iter3 = ms0.insert(3);
53 iterator iter4 = ms0.insert(4);
54
55 pp0 = ms0.equal_range(3);
56 VERIFY( ms0.count(3) == 3 );
57 VERIFY( *pp0.first == 3 );
58 VERIFY( *pp0.second == 4 );
59 VERIFY( pp0.first == iter2 );
60 VERIFY( --pp0.first == iter1 );
61 VERIFY( pp0.second == iter4 );
62
63 iterator iter5 = ms0.insert(0);
64 ms0.insert(1);
65 ms0.insert(1);
66 ms0.insert(1);
67
68 pp0 = ms0.equal_range(1);
69 VERIFY( ms0.count(1) == 4 );
70 VERIFY( *pp0.first == 1 );
71 VERIFY( *pp0.second == 2 );
72 VERIFY( pp0.first == iter0 );
73 VERIFY( --pp0.first == iter5 );
74 VERIFY( pp0.second == iter1 );
75
76 iterator iter6 = ms0.insert(5);
77 ms0.insert(5);
78 ms0.insert(5);
79
80 pp0 = ms0.equal_range(5);
81 VERIFY( ms0.count(5) == 3 );
82 VERIFY( *pp0.first == 5 );
83 VERIFY( pp0.first == iter6 );
84 VERIFY( --pp0.first == iter4 );
85 VERIFY( pp0.second == ms0.end() );
86
87 ms0.insert(4);
88 ms0.insert(4);
89 ms0.insert(4);
90
91 pp0 = ms0.equal_range(4);
92 VERIFY( ms0.count(4) == 4 );
93 VERIFY( *pp0.first == 4 );
94 VERIFY( *pp0.second == 5 );
95 VERIFY( pp0.first == iter4 );
96 VERIFY( --pp0.first == iter3 );
97 VERIFY( pp0.second == iter6 );
98
99 ms0.insert(0);
100 iterator iter7 = ms0.insert(0);
101 ms0.insert(1);
102
103 pp0 = ms0.equal_range(0);
104 VERIFY( ms0.count(0) == 3 );
105 VERIFY( *pp0.first == 0 );
106 VERIFY( *pp0.second == 1 );
107 VERIFY( pp0.first == iter5 );
108 VERIFY( pp0.first == ms0.begin() );
109 VERIFY( pp0.second == iter0 );
110
111 const multiset<int>& ms1 = ms0;
112 pair<const_iterator, const_iterator> pp1 = ms1.equal_range(1);
113 VERIFY( ms1.count(1) == 5 );
114 VERIFY( *pp1.first == 1 );
115 VERIFY( *pp1.second == 2 );
116 VERIFY( pp1.first == iter0 );
117 VERIFY( --pp1.first == iter7 );
118 VERIFY( pp1.second == iter1 );
119 }
120
121 int
122 main()
123 {
124 test01();
125 return 0;
126 }