1 // 2006-11-25 Paolo Carlini <pcarlini@suse.de>
3 // Copyright (C) 2006-2025 Free Software Foundation, Inc.
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)
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.
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/>.
22 #include <testsuite_hooks.h>
24 // A few tests for equal_range, in the occasion of libstdc++/29385.
30 typedef multiset
<int>::iterator iterator
;
31 typedef multiset
<int>::const_iterator const_iterator
;
32 pair
<iterator
, iterator
> pp0
;
34 pp0
= ms0
.equal_range(1);
35 VERIFY( ms0
.count(1) == 0 );
36 VERIFY( pp0
.first
== ms0
.end() );
37 VERIFY( pp0
.second
== ms0
.end() );
39 iterator iter0
= ms0
.insert(1);
40 iterator iter1
= ms0
.insert(2);
41 iterator iter2
= ms0
.insert(3);
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
);
52 iterator iter3
= ms0
.insert(3);
53 iterator iter4
= ms0
.insert(4);
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
);
63 iterator iter5
= ms0
.insert(0);
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
);
76 iterator iter6
= ms0
.insert(5);
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() );
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
);
100 iterator iter7
= ms0
.insert(0);
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
);
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
);