]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/23_containers/multiset/operations/1.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 23_containers / multiset / operations / 1.cc
CommitLineData
8b8a56ca 1// 2006-11-25 Paolo Carlini <pcarlini@suse.de>
2
fbd26352 3// Copyright (C) 2006-2019 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 <set>
22#include <testsuite_hooks.h>
23
24// A few tests for equal_range, in the occasion of libstdc++/29385.
25void test01()
26{
8b8a56ca 27 using namespace std;
28
29 multiset<int> ms0;
30 typedef multiset<int>::iterator iterator;
e20e61b2 31 typedef multiset<int>::const_iterator const_iterator;
8b8a56ca 32 pair<iterator, iterator> pp0;
33
34 pp0 = ms0.equal_range(1);
35 VERIFY( ms0.count(1) == 0 );
36 VERIFY( pp0.first == ms0.end() );
37 VERIFY( pp0.second == ms0.end() );
38
39 iterator iter0 = ms0.insert(1);
40 iterator iter1 = ms0.insert(2);
41 iterator iter2 = ms0.insert(3);
42
43 pp0 = ms0.equal_range(2);
44 VERIFY( ms0.count(2) == 1 );
45 VERIFY( *pp0.first == 2 );
46 VERIFY( *pp0.second == 3 );
47 VERIFY( pp0.first == iter1 );
e20e61b2 48 VERIFY( --pp0.first == iter0 );
8b8a56ca 49 VERIFY( pp0.second == iter2 );
50
51 ms0.insert(3);
52 iterator iter3 = ms0.insert(3);
53 iterator iter4 = ms0.insert(4);
e20e61b2 54
8b8a56ca 55 pp0 = ms0.equal_range(3);
56 VERIFY( ms0.count(3) == 3 );
57 VERIFY( *pp0.first == 3 );
58 VERIFY( *pp0.second == 4 );
59 VERIFY( pp0.first == iter2 );
e20e61b2 60 VERIFY( --pp0.first == iter1 );
8b8a56ca 61 VERIFY( pp0.second == iter4 );
62
63 iterator iter5 = ms0.insert(0);
64 ms0.insert(1);
65 ms0.insert(1);
66 ms0.insert(1);
67
68 pp0 = ms0.equal_range(1);
69 VERIFY( ms0.count(1) == 4 );
70 VERIFY( *pp0.first == 1 );
71 VERIFY( *pp0.second == 2 );
72 VERIFY( pp0.first == iter0 );
e20e61b2 73 VERIFY( --pp0.first == iter5 );
8b8a56ca 74 VERIFY( pp0.second == iter1 );
75
76 iterator iter6 = ms0.insert(5);
77 ms0.insert(5);
78 ms0.insert(5);
79
80 pp0 = ms0.equal_range(5);
81 VERIFY( ms0.count(5) == 3 );
82 VERIFY( *pp0.first == 5 );
83 VERIFY( pp0.first == iter6 );
e20e61b2 84 VERIFY( --pp0.first == iter4 );
8b8a56ca 85 VERIFY( pp0.second == ms0.end() );
86
87 ms0.insert(4);
88 ms0.insert(4);
89 ms0.insert(4);
90
91 pp0 = ms0.equal_range(4);
e20e61b2 92 VERIFY( ms0.count(4) == 4 );
8b8a56ca 93 VERIFY( *pp0.first == 4 );
e20e61b2 94 VERIFY( *pp0.second == 5 );
8b8a56ca 95 VERIFY( pp0.first == iter4 );
e20e61b2 96 VERIFY( --pp0.first == iter3 );
8b8a56ca 97 VERIFY( pp0.second == iter6 );
e20e61b2 98
8b8a56ca 99 ms0.insert(0);
100 iterator iter7 = ms0.insert(0);
101 ms0.insert(1);
102
103 pp0 = ms0.equal_range(0);
e20e61b2 104 VERIFY( ms0.count(0) == 3 );
8b8a56ca 105 VERIFY( *pp0.first == 0 );
e20e61b2 106 VERIFY( *pp0.second == 1 );
8b8a56ca 107 VERIFY( pp0.first == iter5 );
108 VERIFY( pp0.first == ms0.begin() );
109 VERIFY( pp0.second == iter0 );
110
e20e61b2 111 const multiset<int>& ms1 = ms0;
112 pair<const_iterator, const_iterator> pp1 = ms1.equal_range(1);
113 VERIFY( ms1.count(1) == 5 );
114 VERIFY( *pp1.first == 1 );
115 VERIFY( *pp1.second == 2 );
116 VERIFY( pp1.first == iter0 );
117 VERIFY( --pp1.first == iter7 );
118 VERIFY( pp1.second == iter1 );
8b8a56ca 119}
120
810d0cce 121int
8b8a56ca 122main()
123{
124 test01();
125 return 0;
126}