]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/23_containers/unordered_map/insert/map_range.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 23_containers / unordered_map / insert / map_range.cc
CommitLineData
52066eae 1// { dg-do run { target c++11 } }
3b2524b1 2
8d9254fc 3// Copyright (C) 2010-2020 Free Software Foundation, Inc.
3b2524b1
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
8// Free Software Foundation; either version 3, or (at your option)
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
17// with this library; see the file COPYING3. If not see
18// <http://www.gnu.org/licenses/>.
19
20// range insert
21
22#include <string>
23#include <iterator>
24#include <algorithm>
25#include <unordered_map>
26#include <testsuite_hooks.h>
27
28void test01()
29{
3b2524b1
PC
30 typedef std::unordered_map<std::string, int> Map;
31 typedef std::pair<const std::string, int> Pair;
32
33 Map m;
34 VERIFY(m.empty());
35
36 Pair A[5] =
37 {
38 Pair("red", 5),
39 Pair("green", 9),
40 Pair("blue", 3),
41 Pair("cyan", 8),
42 Pair("magenta", 7)
43 };
44
45 m.insert(A+0, A+5);
46 VERIFY(m.size() == 5);
47 VERIFY(std::distance(m.begin(), m.end()) == 5);
48
49 VERIFY(m["red"] == 5);
50 VERIFY(m["green"] == 9);
51 VERIFY(m["blue"] == 3);
52 VERIFY(m["cyan"] == 8);
53 VERIFY(m["magenta"] == 7);
54}
55
56void test02()
57{
3b2524b1
PC
58 typedef std::unordered_map<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() == 5);
79 VERIFY(std::distance(m.begin(), m.end()) == 5);
80
81 VERIFY(m["red"] == 5);
82 VERIFY(m["green"] == 9);
83 VERIFY(m["blue"] == 3);
84 VERIFY(m["cyan"] == 8);
85 VERIFY(m["magenta"] == 7);
86}
87
88int main()
89{
90 test01();
91 test02();
92 return 0;
93}