]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/23_containers/set/operations/1.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 23_containers / set / operations / 1.cc
1 // 2006-11-25 Paolo Carlini <pcarlini@suse.de>
2
3 // Copyright (C) 2006-2016 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 bool test __attribute__((unused)) = true;
28 using namespace std;
29
30 set<int> s0;
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;
35
36 pp0 = s0.equal_range(1);
37 VERIFY( s0.count(1) == 0 );
38 VERIFY( pp0.first == s0.end() );
39 VERIFY( pp0.second == s0.end() );
40
41 insert_return_type irt0 = s0.insert(1);
42 insert_return_type irt1 = s0.insert(2);
43 insert_return_type irt2 = s0.insert(3);
44
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 );
52
53 s0.insert(3);
54 insert_return_type irt3 = s0.insert(3);
55 insert_return_type irt4 = s0.insert(4);
56
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 );
64
65 insert_return_type irt5 = s0.insert(0);
66 s0.insert(1);
67 s0.insert(1);
68 s0.insert(1);
69
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 );
77
78 insert_return_type irt6 = s0.insert(5);
79 s0.insert(5);
80 s0.insert(5);
81
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() );
88
89 s0.insert(4);
90 s0.insert(4);
91 s0.insert(4);
92
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 );
100
101 s0.insert(0);
102 insert_return_type irt7 = s0.insert(0);
103 s0.insert(1);
104
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 );
112
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 );
121 }
122
123 int
124 main()
125 {
126 test01();
127 return 0;
128 }