1 // 2006-11-25 Paolo Carlini <pcarlini@suse.de>
3 // Copyright (C) 2006-2016 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.
27 bool test
__attribute__((unused
)) = true;
31 typedef set
<int>::iterator iterator
;
32 typedef set
<int>::const_iterator const_iterator
;
33 typedef pair
<iterator
, bool> insert_return_type
;
34 pair
<iterator
, iterator
> pp0
;
36 pp0
= s0
.equal_range(1);
37 VERIFY( s0
.count(1) == 0 );
38 VERIFY( pp0
.first
== s0
.end() );
39 VERIFY( pp0
.second
== s0
.end() );
41 insert_return_type irt0
= s0
.insert(1);
42 insert_return_type irt1
= s0
.insert(2);
43 insert_return_type irt2
= s0
.insert(3);
45 pp0
= s0
.equal_range(2);
46 VERIFY( s0
.count(2) == 1 );
47 VERIFY( *pp0
.first
== 2 );
48 VERIFY( *pp0
.second
== 3 );
49 VERIFY( pp0
.first
== irt1
.first
);
50 VERIFY( --pp0
.first
== irt0
.first
);
51 VERIFY( pp0
.second
== irt2
.first
);
54 insert_return_type irt3
= s0
.insert(3);
55 insert_return_type irt4
= s0
.insert(4);
57 pp0
= s0
.equal_range(3);
58 VERIFY( s0
.count(3) == 1 );
59 VERIFY( *pp0
.first
== 3 );
60 VERIFY( *pp0
.second
== 4 );
61 VERIFY( pp0
.first
== irt2
.first
);
62 VERIFY( --pp0
.first
== irt1
.first
);
63 VERIFY( pp0
.second
== irt4
.first
);
65 insert_return_type irt5
= s0
.insert(0);
70 pp0
= s0
.equal_range(1);
71 VERIFY( s0
.count(1) == 1 );
72 VERIFY( *pp0
.first
== 1 );
73 VERIFY( *pp0
.second
== 2 );
74 VERIFY( pp0
.first
== irt0
.first
);
75 VERIFY( --pp0
.first
== irt5
.first
);
76 VERIFY( pp0
.second
== irt1
.first
);
78 insert_return_type irt6
= s0
.insert(5);
82 pp0
= s0
.equal_range(5);
83 VERIFY( s0
.count(5) == 1 );
84 VERIFY( *pp0
.first
== 5 );
85 VERIFY( pp0
.first
== irt6
.first
);
86 VERIFY( --pp0
.first
== irt4
.first
);
87 VERIFY( pp0
.second
== s0
.end() );
93 pp0
= s0
.equal_range(4);
94 VERIFY( s0
.count(4) == 1 );
95 VERIFY( *pp0
.first
== 4 );
96 VERIFY( *pp0
.second
== 5 );
97 VERIFY( pp0
.first
== irt4
.first
);
98 VERIFY( --pp0
.first
== irt3
.first
);
99 VERIFY( pp0
.second
== irt6
.first
);
102 insert_return_type irt7
= s0
.insert(0);
105 pp0
= s0
.equal_range(0);
106 VERIFY( s0
.count(0) == 1 );
107 VERIFY( *pp0
.first
== 0 );
108 VERIFY( *pp0
.second
== 1 );
109 VERIFY( pp0
.first
== irt5
.first
);
110 VERIFY( pp0
.first
== s0
.begin() );
111 VERIFY( pp0
.second
== irt0
.first
);
113 const set
<int>& s1
= s0
;
114 pair
<const_iterator
, const_iterator
> pp1
= s1
.equal_range(1);
115 VERIFY( s1
.count(1) == 1 );
116 VERIFY( *pp1
.first
== 1 );
117 VERIFY( *pp1
.second
== 2 );
118 VERIFY( pp1
.first
== irt0
.first
);
119 VERIFY( --pp1
.first
== irt7
.first
);
120 VERIFY( pp1
.second
== irt1
.first
);