]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/23_containers/multiset/operations/1.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 23_containers / multiset / operations / 1.cc
CommitLineData
639b490b
PC
1// 2006-11-25 Paolo Carlini <pcarlini@suse.de>
2
7adcbafe 3// Copyright (C) 2006-2022 Free Software Foundation, Inc.
639b490b
PC
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
748086b7 8// Free Software Foundation; either version 3, or (at your option)
639b490b
PC
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
748086b7
JJ
17// with this library; see the file COPYING3. If not see
18// <http://www.gnu.org/licenses/>.
639b490b 19//
639b490b
PC
20
21#include <set>
22#include <testsuite_hooks.h>
23
24// A few tests for equal_range, in the occasion of libstdc++/29385.
25void test01()
26{
639b490b
PC
27 using namespace std;
28
29 multiset<int> ms0;
30 typedef multiset<int>::iterator iterator;
d7b35f22 31 typedef multiset<int>::const_iterator const_iterator;
639b490b
PC
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 );
d7b35f22 48 VERIFY( --pp0.first == iter0 );
639b490b
PC
49 VERIFY( pp0.second == iter2 );
50
51 ms0.insert(3);
52 iterator iter3 = ms0.insert(3);
53 iterator iter4 = ms0.insert(4);
d7b35f22 54
639b490b
PC
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 );
d7b35f22 60 VERIFY( --pp0.first == iter1 );
639b490b
PC
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 );
d7b35f22 73 VERIFY( --pp0.first == iter5 );
639b490b
PC
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 );
d7b35f22 84 VERIFY( --pp0.first == iter4 );
639b490b
PC
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);
d7b35f22 92 VERIFY( ms0.count(4) == 4 );
639b490b 93 VERIFY( *pp0.first == 4 );
d7b35f22 94 VERIFY( *pp0.second == 5 );
639b490b 95 VERIFY( pp0.first == iter4 );
d7b35f22 96 VERIFY( --pp0.first == iter3 );
639b490b 97 VERIFY( pp0.second == iter6 );
d7b35f22 98
639b490b
PC
99 ms0.insert(0);
100 iterator iter7 = ms0.insert(0);
101 ms0.insert(1);
102
103 pp0 = ms0.equal_range(0);
d7b35f22 104 VERIFY( ms0.count(0) == 3 );
639b490b 105 VERIFY( *pp0.first == 0 );
d7b35f22 106 VERIFY( *pp0.second == 1 );
639b490b
PC
107 VERIFY( pp0.first == iter5 );
108 VERIFY( pp0.first == ms0.begin() );
109 VERIFY( pp0.second == iter0 );
110
d7b35f22
FD
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 );
639b490b
PC
119}
120
7919bb2f 121int
639b490b
PC
122main()
123{
124 test01();
125 return 0;
126}