Debian Codegraph @

libstdc++-v3/testsuite/tr1/6_containers/unordered_multimap/insert/multimap_range.cc

raw
1 // { dg-do run }
2
3 // 2005-2-17 Matt Austern <[email protected]>
4 //
5 // Copyright (C) 2005-2025 Free Software Foundation, Inc.
6 //
7 // This file is part of the GNU ISO C++ Library. This library is free
8 // software; you can redistribute it and/or modify it under the
9 // terms of the GNU General Public License as published by the
10 // Free Software Foundation; either version 3, or (at your option)
11 // any later version.
12 //
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
17 //
18 // You should have received a copy of the GNU General Public License along
19 // with this library; see the file COPYING3. If not see
20 // <http://www.gnu.org/licenses/>.
21
22 // 6.3.4.6 unordered_multimap
23 // range insert
24
25 #include <string>
26 #include <iterator>
27 #include <algorithm>
28 #include <tr1/unordered_map>
29 #include "testsuite_hooks.h"
30
31 void test01()
32 {
33 typedef std::tr1::unordered_multimap<std::string, int> Map;
34 typedef std::pair<const std::string, int> Pair;
35
36 Map m;
37 VERIFY(m.empty());
38
39 Pair A[5] =
40 {
41 Pair("red", 5),
42 Pair("green", 9),
43 Pair("blue", 3),
44 Pair("cyan", 8),
45 Pair("magenta", 7)
46 };
47
48 m.insert(A+0, A+5);
49 VERIFY(m.size() == 5);
50 VERIFY(std::distance(m.begin(), m.end()) == 5);
51
52 for (int i = 0; i < 5; ++i)
53 VERIFY(std::find(m.begin(), m.end(), A[i]) != m.end());
54 }
55
56 void test02()
57 {
58 typedef std::tr1::unordered_multimap<std::string, int> Map;
59 typedef std::pair<const std::string, int> Pair;
60
61 Map m;
62 VERIFY(m.empty());
63
64 Pair A[9] =
65 {
66 Pair("red", 5),
67 Pair("green", 9),
68 Pair("red", 19),
69 Pair("blue", 3),
70 Pair("blue", 60),
71 Pair("cyan", 8),
72 Pair("magenta", 7),
73 Pair("blue", 99),
74 Pair("green", 33)
75 };
76
77 m.insert(A+0, A+9);
78 VERIFY(m.size() == 9);
79 VERIFY(std::distance(m.begin(), m.end()) == 9);
80
81 for (int i = 0; i < 9; ++i)
82 VERIFY(std::find(m.begin(), m.end(), A[i]) != m.end());
83 }
84
85 int main()
86 {
87 test01();
88 test02();
89 return 0;
90 }