]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/23_containers/multimap/operations/1.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 23_containers / multimap / operations / 1.cc
CommitLineData
8b8a56ca 1// 2006-11-25 Paolo Carlini <pcarlini@suse.de>
2
f1717362 3// Copyright (C) 2006-2016 Free Software Foundation, Inc.
8b8a56ca 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
6bc9506f 8// Free Software Foundation; either version 3, or (at your option)
8b8a56ca 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
6bc9506f 17// with this library; see the file COPYING3. If not see
18// <http://www.gnu.org/licenses/>.
8b8a56ca 19//
8b8a56ca 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{
27 bool test __attribute__((unused)) = true;
28 using namespace std;
29
30 multimap<int, int> mm0;
31 typedef multimap<int, int>::iterator iterator;
e20e61b2 32 typedef multimap<int, int>::const_iterator const_iterator;
8b8a56ca 33 pair<iterator, iterator> pp0;
34 typedef multimap<int, int>::value_type value_type;
35
36 pp0 = mm0.equal_range(1);
37 VERIFY( mm0.count(1) == 0 );
38 VERIFY( pp0.first == mm0.end() );
39 VERIFY( pp0.second == mm0.end() );
40
41 iterator iter0 = mm0.insert(value_type(1, 1));
42 iterator iter1 = mm0.insert(value_type(2, 2));
43 iterator iter2 = mm0.insert(value_type(3, 3));
44
45 pp0 = mm0.equal_range(2);
46 VERIFY( mm0.count(2) == 1 );
47 VERIFY( *pp0.first == value_type(2, 2) );
48 VERIFY( *pp0.second == value_type(3, 3) );
49 VERIFY( pp0.first == iter1 );
e20e61b2 50 VERIFY( --pp0.first == iter0 );
8b8a56ca 51 VERIFY( pp0.second == iter2 );
52
53 mm0.insert(value_type(3, 4));
54 iterator iter3 = mm0.insert(value_type(3, 5));
55 iterator iter4 = mm0.insert(value_type(4, 6));
56
57 pp0 = mm0.equal_range(3);
58 VERIFY( mm0.count(3) == 3 );
59 VERIFY( *pp0.first == value_type(3, 3) );
60 VERIFY( *pp0.second == value_type(4, 6) );
61 VERIFY( pp0.first == iter2 );
e20e61b2 62 VERIFY( --pp0.first == iter1 );
8b8a56ca 63 VERIFY( pp0.second == iter4 );
64
65 iterator iter5 = mm0.insert(value_type(0, 7));
66 mm0.insert(value_type(1, 8));
67 mm0.insert(value_type(1, 9));
68 mm0.insert(value_type(1, 10));
69
70 pp0 = mm0.equal_range(1);
71 VERIFY( mm0.count(1) == 4 );
72 VERIFY( *pp0.first == value_type(1, 1) );
73 VERIFY( *pp0.second == value_type(2, 2) );
74 VERIFY( pp0.first == iter0 );
e20e61b2 75 VERIFY( --pp0.first == iter5 );
8b8a56ca 76 VERIFY( pp0.second == iter1 );
77
78 iterator iter6 = mm0.insert(value_type(5, 11));
79 mm0.insert(value_type(5, 12));
80 mm0.insert(value_type(5, 13));
81
82 pp0 = mm0.equal_range(5);
83 VERIFY( mm0.count(5) == 3 );
84 VERIFY( *pp0.first == value_type(5, 11) );
85 VERIFY( pp0.first == iter6 );
e20e61b2 86 VERIFY( --pp0.first == iter4 );
8b8a56ca 87 VERIFY( pp0.second == mm0.end() );
88
89 mm0.insert(value_type(4, 14));
90 mm0.insert(value_type(4, 15));
91 mm0.insert(value_type(4, 16));
92
93 pp0 = mm0.equal_range(4);
e20e61b2 94 VERIFY( mm0.count(4) == 4 );
8b8a56ca 95 VERIFY( *pp0.first == value_type(4, 6) );
e20e61b2 96 VERIFY( *pp0.second == value_type(5, 11) );
8b8a56ca 97 VERIFY( pp0.first == iter4 );
e20e61b2 98 VERIFY( --pp0.first == iter3 );
8b8a56ca 99 VERIFY( pp0.second == iter6 );
100
101 mm0.insert(value_type(0, 17));
102 iterator iter7 = mm0.insert(value_type(0, 18));
103 mm0.insert(value_type(1, 19));
104
105 pp0 = mm0.equal_range(0);
e20e61b2 106 VERIFY( mm0.count(0) == 3 );
8b8a56ca 107 VERIFY( *pp0.first == value_type(0, 7) );
e20e61b2 108 VERIFY( *pp0.second == value_type(1, 1) );
8b8a56ca 109 VERIFY( pp0.first == iter5 );
110 VERIFY( pp0.first == mm0.begin() );
111 VERIFY( pp0.second == iter0 );
112
e20e61b2 113 const multimap<int, int>& mm1 = mm0;
114 pair<const_iterator, const_iterator> pp1 = mm1.equal_range(1);
115 VERIFY( mm1.count(1) == 5 );
116 VERIFY( *pp1.first == value_type(1, 1) );
117 VERIFY( *pp1.second == value_type(2, 2) );
118 VERIFY( pp1.first == iter0 );
119 VERIFY( --pp1.first == iter7 );
120 VERIFY( pp1.second == iter1 );
8b8a56ca 121}
122
810d0cce 123int
8b8a56ca 124main()
125{
126 test01();
127 return 0;
128}