]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/tr1/6_containers/unordered_multimap/find/multimap1.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / tr1 / 6_containers / unordered_multimap / find / multimap1.cc
CommitLineData
6bbd10c7
MA
1// { dg-do run }
2
3// 2005-2-18 Matt Austern <austern@apple.com>
4//
cbe34bb5 5// Copyright (C) 2005-2017 Free Software Foundation, Inc.
6bbd10c7
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)
6bbd10c7
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/>.
6bbd10c7
MA
21
22// 6.3.4.6 unordered_multimap
23// find, equal_range, count
24
25#include <string>
26#include <iterator>
27#include <algorithm>
28#include <utility>
29#include <tr1/unordered_map>
30#include "testsuite_hooks.h"
31
6bbd10c7
MA
32void test01()
33{
34 typedef std::tr1::unordered_multimap<std::string, int> Map;
35 typedef std::pair<const std::string, int> Pair;
36
37 Map m;
38 VERIFY(m.empty());
39
40 m.insert(Pair("grape", 3));
41 m.insert(Pair("durian", 8));
42 m.insert(Pair("grape", 7));
43
44 Map::iterator i1 = m.find("grape");
45 Map::iterator i2 = m.find("durian");
46 Map::iterator i3 = m.find("kiwi");
47
48 VERIFY(i1 != m.end());
49 VERIFY(i1->first == "grape");
50 VERIFY(i1->second == 3 || i2->second == 7);
51 VERIFY(i2 != m.end());
52 VERIFY(i2->first == "durian");
53 VERIFY(i2->second == 8);
54 VERIFY(i3 == m.end());
55
56 std::pair<Map::iterator, Map::iterator> p1 = m.equal_range("grape");
57 VERIFY(std::distance(p1.first, p1.second) == 2);
58 Map::iterator tmp = p1.first;
59 ++tmp;
60 VERIFY(p1.first->first == "grape");
61 VERIFY(tmp->first == "grape");
62 VERIFY((p1.first->second == 3 && tmp->second == 7) ||
63 (p1.first->second == 7 && tmp->second == 3));
64
65 std::pair<Map::iterator, Map::iterator> p2 = m.equal_range("durian");
66 VERIFY(std::distance(p2.first, p2.second) == 1);
67 VERIFY(p2.first->first == "durian");
68 VERIFY(p2.first->second == 8);
69
70 std::pair<Map::iterator, Map::iterator> p3 = m.equal_range("kiwi");
71 VERIFY(p3.first == p3.second);
72
73 VERIFY(m.count("grape") == 2);
74 VERIFY(m.count("durian") == 1);
75 VERIFY(m.count("kiwi") == 0);
76}
77
78int main()
79{
80 test01();
81 return 0;
82}