2009-07-17 Richard Guenther <rguenther@suse.de>
[official-gcc.git] / libstdc++-v3 / testsuite / 23_containers / unordered_multimap / init-list.cc
blobd7ebbf16ddefec282729e5a7094b447a2a9da88d
1 // Copyright (C) 2008, 2009 Free Software Foundation, Inc.
2 //
3 // This file is part of the GNU ISO C++ Library. This library is free
4 // software; you can redistribute it and/or modify it under the
5 // terms of the GNU General Public License as published by the
6 // Free Software Foundation; either version 3, or (at your option)
7 // any later version.
8 //
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License along
15 // with this library; see the file COPYING3. If not see
16 // <http://www.gnu.org/licenses/>.
19 // { dg-options "-std=gnu++0x" }
21 #include <set>
22 #include <unordered_map>
23 #include <testsuite_hooks.h>
25 using namespace std;
27 int test01()
29 bool test __attribute__((unused)) = true;
31 typedef unordered_multimap<int,double> Container;
32 typedef Container::const_iterator iterator;
33 typedef pair<iterator,iterator> itpair;
35 Container m({ { 1, 1.0 }, { 1, 2.0 }, { 1, 237.0 } });
36 VERIFY(m.size() == 3);
37 itpair ip = m.equal_range(1);
38 VERIFY(distance(ip.first, ip.second) == 3);
39 set<double> s = { 1.0, 2.0, 237.0 };
40 for (iterator i = ip.first; i != ip.second; ++i)
41 s.erase (i->second);
42 VERIFY(s.empty());
44 m = { {5, 55.0}, { 5, 66.0 }, { 42, 4242.0 } };
45 VERIFY(m.size() == 3);
46 ip = m.equal_range(5);
47 VERIFY(distance(ip.first, ip.second) == 2);
48 s = { 55.0, 66.0 };
49 for (iterator i = ip.first; i != ip.second; ++i)
50 s.erase (i->second);
51 VERIFY(s.empty());
53 m.insert({ { 7, 77.0 }, { 7, 88.0 } });
54 VERIFY(m.size() == 5);
55 VERIFY(m.count(5) == 2);
56 VERIFY(m.count(42) == 1);
57 VERIFY(m.count(7) == 2);
59 return test;
62 int main()
64 __gnu_test::set_memory_limits();
65 test01();