Merge -r 127928:132243 from trunk
[official-gcc.git] / libstdc++-v3 / testsuite / 23_containers / multiset / operations / 1.cc
bloba37a0a1a637e5c7fa2e40ec41408f0788b86fcc5
1 // 2006-11-25 Paolo Carlini <pcarlini@suse.de>
3 // Copyright (C) 2006, 2007 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 2, or (at your option)
9 // any later version.
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 COPYING. If not, write to the Free
18 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
19 // USA.
21 // As a special exception, you may use this file as part of a free software
22 // library without restriction. Specifically, if other files instantiate
23 // templates or use macros or inline functions from this file, or you compile
24 // this file and link it with other files to produce an executable, this
25 // file does not by itself cause the resulting executable to be covered by
26 // the GNU General Public License. This exception does not however
27 // invalidate any other reasons why the executable file might be covered by
28 // the GNU General Public License.
30 #include <set>
31 #include <testsuite_hooks.h>
33 // A few tests for equal_range, in the occasion of libstdc++/29385.
34 void test01()
36 bool test __attribute__((unused)) = true;
37 using namespace std;
39 multiset<int> ms0;
40 typedef multiset<int>::iterator iterator;
41 pair<iterator, iterator> pp0;
43 pp0 = ms0.equal_range(1);
44 VERIFY( ms0.count(1) == 0 );
45 VERIFY( pp0.first == ms0.end() );
46 VERIFY( pp0.second == ms0.end() );
48 iterator iter0 = ms0.insert(1);
49 iterator iter1 = ms0.insert(2);
50 iterator iter2 = ms0.insert(3);
52 pp0 = ms0.equal_range(2);
53 VERIFY( ms0.count(2) == 1 );
54 VERIFY( *pp0.first == 2 );
55 VERIFY( *pp0.second == 3 );
56 VERIFY( pp0.first == iter1 );
57 VERIFY( --pp0.first == iter0 );
58 VERIFY( pp0.second == iter2 );
60 ms0.insert(3);
61 iterator iter3 = ms0.insert(3);
62 iterator iter4 = ms0.insert(4);
64 pp0 = ms0.equal_range(3);
65 VERIFY( ms0.count(3) == 3 );
66 VERIFY( *pp0.first == 3 );
67 VERIFY( *pp0.second == 4 );
68 VERIFY( pp0.first == iter2 );
69 VERIFY( --pp0.first == iter1 );
70 VERIFY( pp0.second == iter4 );
72 iterator iter5 = ms0.insert(0);
73 ms0.insert(1);
74 ms0.insert(1);
75 ms0.insert(1);
77 pp0 = ms0.equal_range(1);
78 VERIFY( ms0.count(1) == 4 );
79 VERIFY( *pp0.first == 1 );
80 VERIFY( *pp0.second == 2 );
81 VERIFY( pp0.first == iter0 );
82 VERIFY( --pp0.first == iter5 );
83 VERIFY( pp0.second == iter1 );
85 iterator iter6 = ms0.insert(5);
86 ms0.insert(5);
87 ms0.insert(5);
89 pp0 = ms0.equal_range(5);
90 VERIFY( ms0.count(5) == 3 );
91 VERIFY( *pp0.first == 5 );
92 VERIFY( pp0.first == iter6 );
93 VERIFY( --pp0.first == iter4 );
94 VERIFY( pp0.second == ms0.end() );
96 ms0.insert(4);
97 ms0.insert(4);
98 ms0.insert(4);
100 pp0 = ms0.equal_range(4);
101 VERIFY( ms0.count(4) == 4 );
102 VERIFY( *pp0.first == 4 );
103 VERIFY( *pp0.second == 5 );
104 VERIFY( pp0.first == iter4 );
105 VERIFY( --pp0.first == iter3 );
106 VERIFY( pp0.second == iter6 );
108 ms0.insert(0);
109 iterator iter7 = ms0.insert(0);
110 ms0.insert(1);
112 pp0 = ms0.equal_range(0);
113 VERIFY( ms0.count(0) == 3 );
114 VERIFY( *pp0.first == 0 );
115 VERIFY( *pp0.second == 1 );
116 VERIFY( pp0.first == iter5 );
117 VERIFY( pp0.first == ms0.begin() );
118 VERIFY( pp0.second == iter0 );
120 pp0 = ms0.equal_range(1);
121 VERIFY( ms0.count(1) == 5 );
122 VERIFY( *pp0.first == 1 );
123 VERIFY( *pp0.second == 2 );
124 VERIFY( pp0.first == iter0 );
125 VERIFY( --pp0.first == iter7 );
126 VERIFY( pp0.second == iter1 );
130 main()
132 test01();
133 return 0;