Merge -r 127928:132243 from trunk
[official-gcc.git] / libstdc++-v3 / testsuite / 23_containers / multimap / operations / 1.cc
blobb781ca2f9479ab11ee9e08b2d459237b32ac1163
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 <map>
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 multimap<int, int> mm0;
40 typedef multimap<int, int>::iterator iterator;
41 pair<iterator, iterator> pp0;
42 typedef multimap<int, int>::value_type value_type;
44 pp0 = mm0.equal_range(1);
45 VERIFY( mm0.count(1) == 0 );
46 VERIFY( pp0.first == mm0.end() );
47 VERIFY( pp0.second == mm0.end() );
49 iterator iter0 = mm0.insert(value_type(1, 1));
50 iterator iter1 = mm0.insert(value_type(2, 2));
51 iterator iter2 = mm0.insert(value_type(3, 3));
53 pp0 = mm0.equal_range(2);
54 VERIFY( mm0.count(2) == 1 );
55 VERIFY( *pp0.first == value_type(2, 2) );
56 VERIFY( *pp0.second == value_type(3, 3) );
57 VERIFY( pp0.first == iter1 );
58 VERIFY( --pp0.first == iter0 );
59 VERIFY( pp0.second == iter2 );
61 mm0.insert(value_type(3, 4));
62 iterator iter3 = mm0.insert(value_type(3, 5));
63 iterator iter4 = mm0.insert(value_type(4, 6));
65 pp0 = mm0.equal_range(3);
66 VERIFY( mm0.count(3) == 3 );
67 VERIFY( *pp0.first == value_type(3, 3) );
68 VERIFY( *pp0.second == value_type(4, 6) );
69 VERIFY( pp0.first == iter2 );
70 VERIFY( --pp0.first == iter1 );
71 VERIFY( pp0.second == iter4 );
73 iterator iter5 = mm0.insert(value_type(0, 7));
74 mm0.insert(value_type(1, 8));
75 mm0.insert(value_type(1, 9));
76 mm0.insert(value_type(1, 10));
78 pp0 = mm0.equal_range(1);
79 VERIFY( mm0.count(1) == 4 );
80 VERIFY( *pp0.first == value_type(1, 1) );
81 VERIFY( *pp0.second == value_type(2, 2) );
82 VERIFY( pp0.first == iter0 );
83 VERIFY( --pp0.first == iter5 );
84 VERIFY( pp0.second == iter1 );
86 iterator iter6 = mm0.insert(value_type(5, 11));
87 mm0.insert(value_type(5, 12));
88 mm0.insert(value_type(5, 13));
90 pp0 = mm0.equal_range(5);
91 VERIFY( mm0.count(5) == 3 );
92 VERIFY( *pp0.first == value_type(5, 11) );
93 VERIFY( pp0.first == iter6 );
94 VERIFY( --pp0.first == iter4 );
95 VERIFY( pp0.second == mm0.end() );
97 mm0.insert(value_type(4, 14));
98 mm0.insert(value_type(4, 15));
99 mm0.insert(value_type(4, 16));
101 pp0 = mm0.equal_range(4);
102 VERIFY( mm0.count(4) == 4 );
103 VERIFY( *pp0.first == value_type(4, 6) );
104 VERIFY( *pp0.second == value_type(5, 11) );
105 VERIFY( pp0.first == iter4 );
106 VERIFY( --pp0.first == iter3 );
107 VERIFY( pp0.second == iter6 );
109 mm0.insert(value_type(0, 17));
110 iterator iter7 = mm0.insert(value_type(0, 18));
111 mm0.insert(value_type(1, 19));
113 pp0 = mm0.equal_range(0);
114 VERIFY( mm0.count(0) == 3 );
115 VERIFY( *pp0.first == value_type(0, 7) );
116 VERIFY( *pp0.second == value_type(1, 1) );
117 VERIFY( pp0.first == iter5 );
118 VERIFY( pp0.first == mm0.begin() );
119 VERIFY( pp0.second == iter0 );
121 pp0 = mm0.equal_range(1);
122 VERIFY( mm0.count(1) == 5 );
123 VERIFY( *pp0.first == value_type(1, 1) );
124 VERIFY( *pp0.second == value_type(2, 2) );
125 VERIFY( pp0.first == iter0 );
126 VERIFY( --pp0.first == iter7 );
127 VERIFY( pp0.second == iter1 );
131 main()
133 test01();
134 return 0;