]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/23_containers/map/operations/1.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 23_containers / map / operations / 1.cc
CommitLineData
639b490b
PC
1// 2006-11-25 Paolo Carlini <pcarlini@suse.de>
2
8d9254fc 3// Copyright (C) 2006-2020 Free Software Foundation, Inc.
639b490b
PC
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
748086b7 8// Free Software Foundation; either version 3, or (at your option)
639b490b
PC
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
748086b7
JJ
17// with this library; see the file COPYING3. If not see
18// <http://www.gnu.org/licenses/>.
639b490b 19//
639b490b
PC
20
21#include <map>
22#include <testsuite_hooks.h>
23
24// A few tests for equal_range, in the occasion of libstdc++/29385.
25void test01()
26{
639b490b
PC
27 using namespace std;
28
29 map<int, int> m0;
30 typedef map<int, int>::iterator iterator;
d7b35f22 31 typedef map<int, int>::const_iterator const_iterator;
639b490b
PC
32 typedef pair<iterator, bool> insert_return_type;
33 pair<iterator, iterator> pp0;
34 typedef map<int, int>::value_type value_type;
35
36 pp0 = m0.equal_range(1);
37 VERIFY( m0.count(1) == 0 );
38 VERIFY( pp0.first == m0.end() );
39 VERIFY( pp0.second == m0.end() );
40
41 insert_return_type irt0 = m0.insert(value_type(1, 1));
42 insert_return_type irt1 = m0.insert(value_type(2, 2));
43 insert_return_type irt2 = m0.insert(value_type(3, 3));
44
45 pp0 = m0.equal_range(2);
46 VERIFY( m0.count(2) == 1 );
47 VERIFY( *pp0.first == value_type(2, 2) );
48 VERIFY( *pp0.second == value_type(3, 3) );
49 VERIFY( pp0.first == irt1.first );
d7b35f22 50 VERIFY( --pp0.first == irt0.first );
639b490b
PC
51 VERIFY( pp0.second == irt2.first );
52
53 m0.insert(value_type(3, 4));
54 insert_return_type irt3 = m0.insert(value_type(3, 5));
55 insert_return_type irt4 = m0.insert(value_type(4, 6));
56
57 pp0 = m0.equal_range(3);
58 VERIFY( m0.count(3) == 1 );
59 VERIFY( *pp0.first == value_type(3, 3) );
60 VERIFY( *pp0.second == value_type(4, 6) );
61 VERIFY( pp0.first == irt2.first );
d7b35f22 62 VERIFY( --pp0.first == irt1.first );
639b490b
PC
63 VERIFY( pp0.second == irt4.first );
64
65 insert_return_type irt5 = m0.insert(value_type(0, 7));
66 m0.insert(value_type(1, 8));
67 m0.insert(value_type(1, 9));
68 m0.insert(value_type(1, 10));
69
70 pp0 = m0.equal_range(1);
71 VERIFY( m0.count(1) == 1 );
72 VERIFY( *pp0.first == value_type(1, 1) );
73 VERIFY( *pp0.second == value_type(2, 2) );
74 VERIFY( pp0.first == irt0.first );
d7b35f22 75 VERIFY( --pp0.first == irt5.first );
639b490b
PC
76 VERIFY( pp0.second == irt1.first );
77
78 insert_return_type irt6 = m0.insert(value_type(5, 11));
79 m0.insert(value_type(5, 12));
80 m0.insert(value_type(5, 13));
81
82 pp0 = m0.equal_range(5);
83 VERIFY( m0.count(5) == 1 );
84 VERIFY( *pp0.first == value_type(5, 11) );
85 VERIFY( pp0.first == irt6.first );
d7b35f22 86 VERIFY( --pp0.first == irt4.first );
639b490b
PC
87 VERIFY( pp0.second == m0.end() );
88
89 m0.insert(value_type(4, 14));
90 m0.insert(value_type(4, 15));
91 m0.insert(value_type(4, 16));
92
93 pp0 = m0.equal_range(4);
d7b35f22 94 VERIFY( m0.count(4) == 1 );
639b490b 95 VERIFY( *pp0.first == value_type(4, 6) );
d7b35f22 96 VERIFY( *pp0.second == value_type(5, 11) );
639b490b 97 VERIFY( pp0.first == irt4.first );
d7b35f22 98 VERIFY( --pp0.first == irt3.first );
639b490b
PC
99 VERIFY( pp0.second == irt6.first );
100
101 m0.insert(value_type(0, 17));
102 insert_return_type irt7 = m0.insert(value_type(0, 18));
103 m0.insert(value_type(1, 19));
104
105 pp0 = m0.equal_range(0);
d7b35f22 106 VERIFY( m0.count(0) == 1 );
639b490b 107 VERIFY( *pp0.first == value_type(0, 7) );
d7b35f22 108 VERIFY( *pp0.second == value_type(1, 1) );
639b490b
PC
109 VERIFY( pp0.first == irt5.first );
110 VERIFY( pp0.first == m0.begin() );
111 VERIFY( pp0.second == irt0.first );
112
d7b35f22
FD
113 const map<int, int>& m1 = m0;
114 pair<const_iterator, const_iterator> pp1 = m1.equal_range(1);
115 VERIFY( m1.count(1) == 1 );
116 VERIFY( *pp1.first == value_type(1, 1) );
117 VERIFY( *pp1.second == value_type(2, 2) );
118 VERIFY( pp1.first == irt0.first );
119 VERIFY( --pp1.first == irt7.first);
120 VERIFY( pp1.second == irt1.first );
639b490b
PC
121}
122
7919bb2f 123int
639b490b
PC
124main()
125{
126 test01();
127 return 0;
128}