]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/tr1/6_containers/unordered_map/insert/map_range.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / tr1 / 6_containers / unordered_map / insert / map_range.cc
CommitLineData
52a7e4c6
MA
1// { dg-do run }
2
3// 2005-2-17 Matt Austern <austern@apple.com>
4//
7adcbafe 5// Copyright (C) 2005-2022 Free Software Foundation, Inc.
52a7e4c6
MA
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
748086b7 10// Free Software Foundation; either version 3, or (at your option)
52a7e4c6
MA
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
748086b7
JJ
19// with this library; see the file COPYING3. If not see
20// <http://www.gnu.org/licenses/>.
52a7e4c6
MA
21
22// 6.3.4.4 unordered_map
23// range insert
24
25#include <string>
26#include <iterator>
27#include <algorithm>
28#include <tr1/unordered_map>
29#include "testsuite_hooks.h"
30
52a7e4c6
MA
31void test01()
32{
33 typedef std::tr1::unordered_map<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 VERIFY(m["red"] == 5);
53 VERIFY(m["green"] == 9);
54 VERIFY(m["blue"] == 3);
55 VERIFY(m["cyan"] == 8);
56 VERIFY(m["magenta"] == 7);
57}
58
59void test02()
60{
61 typedef std::tr1::unordered_map<std::string, int> Map;
62 typedef std::pair<const std::string, int> Pair;
63
64 Map m;
65 VERIFY(m.empty());
66
67 Pair A[9] =
68 {
69 Pair("red", 5),
70 Pair("green", 9),
71 Pair("red", 19),
72 Pair("blue", 3),
73 Pair("blue", 60),
74 Pair("cyan", 8),
75 Pair("magenta", 7),
76 Pair("blue", 99),
77 Pair("green", 33)
78 };
79
80 m.insert(A+0, A+9);
81 VERIFY(m.size() == 5);
82 VERIFY(std::distance(m.begin(), m.end()) == 5);
83
84 VERIFY(m["red"] == 5);
85 VERIFY(m["green"] == 9);
86 VERIFY(m["blue"] == 3);
87 VERIFY(m["cyan"] == 8);
88 VERIFY(m["magenta"] == 7);
89}
90
91int main()
92{
93 test01();
94 test02();
95 return 0;
96}