Merge -r 127928:132243 from trunk
[official-gcc.git] / libstdc++-v3 / testsuite / 23_containers / map / operations / 1.cc
blob35355380461126edd3872ff4feb02c289a045a8d
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 map<int, int> m0;
40 typedef map<int, int>::iterator iterator;
41 typedef pair<iterator, bool> insert_return_type;
42 pair<iterator, iterator> pp0;
43 typedef map<int, int>::value_type value_type;
45 pp0 = m0.equal_range(1);
46 VERIFY( m0.count(1) == 0 );
47 VERIFY( pp0.first == m0.end() );
48 VERIFY( pp0.second == m0.end() );
50 insert_return_type irt0 = m0.insert(value_type(1, 1));
51 insert_return_type irt1 = m0.insert(value_type(2, 2));
52 insert_return_type irt2 = m0.insert(value_type(3, 3));
54 pp0 = m0.equal_range(2);
55 VERIFY( m0.count(2) == 1 );
56 VERIFY( *pp0.first == value_type(2, 2) );
57 VERIFY( *pp0.second == value_type(3, 3) );
58 VERIFY( pp0.first == irt1.first );
59 VERIFY( --pp0.first == irt0.first );
60 VERIFY( pp0.second == irt2.first );
62 m0.insert(value_type(3, 4));
63 insert_return_type irt3 = m0.insert(value_type(3, 5));
64 insert_return_type irt4 = m0.insert(value_type(4, 6));
66 pp0 = m0.equal_range(3);
67 VERIFY( m0.count(3) == 1 );
68 VERIFY( *pp0.first == value_type(3, 3) );
69 VERIFY( *pp0.second == value_type(4, 6) );
70 VERIFY( pp0.first == irt2.first );
71 VERIFY( --pp0.first == irt1.first );
72 VERIFY( pp0.second == irt4.first );
74 insert_return_type irt5 = m0.insert(value_type(0, 7));
75 m0.insert(value_type(1, 8));
76 m0.insert(value_type(1, 9));
77 m0.insert(value_type(1, 10));
79 pp0 = m0.equal_range(1);
80 VERIFY( m0.count(1) == 1 );
81 VERIFY( *pp0.first == value_type(1, 1) );
82 VERIFY( *pp0.second == value_type(2, 2) );
83 VERIFY( pp0.first == irt0.first );
84 VERIFY( --pp0.first == irt5.first );
85 VERIFY( pp0.second == irt1.first );
87 insert_return_type irt6 = m0.insert(value_type(5, 11));
88 m0.insert(value_type(5, 12));
89 m0.insert(value_type(5, 13));
91 pp0 = m0.equal_range(5);
92 VERIFY( m0.count(5) == 1 );
93 VERIFY( *pp0.first == value_type(5, 11) );
94 VERIFY( pp0.first == irt6.first );
95 VERIFY( --pp0.first == irt4.first );
96 VERIFY( pp0.second == m0.end() );
98 m0.insert(value_type(4, 14));
99 m0.insert(value_type(4, 15));
100 m0.insert(value_type(4, 16));
102 pp0 = m0.equal_range(4);
103 VERIFY( m0.count(4) == 1 );
104 VERIFY( *pp0.first == value_type(4, 6) );
105 VERIFY( *pp0.second == value_type(5, 11) );
106 VERIFY( pp0.first == irt4.first );
107 VERIFY( --pp0.first == irt3.first );
108 VERIFY( pp0.second == irt6.first );
110 m0.insert(value_type(0, 17));
111 insert_return_type irt7 = m0.insert(value_type(0, 18));
112 m0.insert(value_type(1, 19));
114 pp0 = m0.equal_range(0);
115 VERIFY( m0.count(0) == 1 );
116 VERIFY( *pp0.first == value_type(0, 7) );
117 VERIFY( *pp0.second == value_type(1, 1) );
118 VERIFY( pp0.first == irt5.first );
119 VERIFY( pp0.first == m0.begin() );
120 VERIFY( pp0.second == irt0.first );
122 pp0 = m0.equal_range(1);
123 VERIFY( m0.count(1) == 1 );
124 VERIFY( *pp0.first == value_type(1, 1) );
125 VERIFY( *pp0.second == value_type(2, 2) );
126 VERIFY( pp0.first == irt0.first );
127 VERIFY( --pp0.first == irt7.first);
128 VERIFY( pp0.second == irt1.first );
132 main()
134 test01();
135 return 0;