]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/tr1/6_containers/unordered_multimap/find/multimap1.cc
Licensing changes to GPLv3 resp. GPLv3 with GCC Runtime Exception.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / tr1 / 6_containers / unordered_multimap / find / multimap1.cc
1 // { dg-do run }
2
3 // 2005-2-18 Matt Austern <austern@apple.com>
4 //
5 // Copyright (C) 2005, 2009 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 // 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
32 bool test __attribute__((unused)) = true;
33
34 void test01()
35 {
36 typedef std::tr1::unordered_multimap<std::string, int> Map;
37 typedef std::pair<const std::string, int> Pair;
38
39 Map m;
40 VERIFY(m.empty());
41
42 m.insert(Pair("grape", 3));
43 m.insert(Pair("durian", 8));
44 m.insert(Pair("grape", 7));
45
46 Map::iterator i1 = m.find("grape");
47 Map::iterator i2 = m.find("durian");
48 Map::iterator i3 = m.find("kiwi");
49
50 VERIFY(i1 != m.end());
51 VERIFY(i1->first == "grape");
52 VERIFY(i1->second == 3 || i2->second == 7);
53 VERIFY(i2 != m.end());
54 VERIFY(i2->first == "durian");
55 VERIFY(i2->second == 8);
56 VERIFY(i3 == m.end());
57
58 std::pair<Map::iterator, Map::iterator> p1 = m.equal_range("grape");
59 VERIFY(std::distance(p1.first, p1.second) == 2);
60 Map::iterator tmp = p1.first;
61 ++tmp;
62 VERIFY(p1.first->first == "grape");
63 VERIFY(tmp->first == "grape");
64 VERIFY((p1.first->second == 3 && tmp->second == 7) ||
65 (p1.first->second == 7 && tmp->second == 3));
66
67 std::pair<Map::iterator, Map::iterator> p2 = m.equal_range("durian");
68 VERIFY(std::distance(p2.first, p2.second) == 1);
69 VERIFY(p2.first->first == "durian");
70 VERIFY(p2.first->second == 8);
71
72 std::pair<Map::iterator, Map::iterator> p3 = m.equal_range("kiwi");
73 VERIFY(p3.first == p3.second);
74
75 VERIFY(m.count("grape") == 2);
76 VERIFY(m.count("durian") == 1);
77 VERIFY(m.count("kiwi") == 0);
78 }
79
80 int main()
81 {
82 test01();
83 return 0;
84 }