Merge from trunk @ 138209
[official-gcc.git] / libstdc++-v3 / testsuite / 23_containers / unordered_multimap / init-list.cc
blobba35b38d85b562a3d1e00e6d7e9741d995275a1a
1 // Copyright (C) 2008 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 2, 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 COPYING. If not, write to the Free
16 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
17 // USA.
19 // As a special exception, you may use this file as part of a free software
20 // library without restriction. Specifically, if other files instantiate
21 // templates or use macros or inline functions from this file, or you compile
22 // this file and link it with other files to produce an executable, this
23 // file does not by itself cause the resulting executable to be covered by
24 // the GNU General Public License. This exception does not however
25 // invalidate any other reasons why the executable file might be covered by
26 // the GNU General Public License.
28 // { dg-options "-std=gnu++0x" }
29 // XFAIL this test until debug mode container is fixed.
30 // { dg-excess-errors "" }
32 #include <set>
33 #include <unordered_map>
34 #include <testsuite_hooks.h>
36 using namespace std;
38 int test01()
40 bool test __attribute__((unused)) = true;
42 typedef unordered_multimap<int,double> Container;
43 typedef Container::const_iterator iterator;
44 typedef pair<iterator,iterator> itpair;
46 Container m({ { 1, 1.0 }, { 1, 2.0 }, { 1, 237.0 } });
47 VERIFY(m.size() == 3);
48 itpair ip = m.equal_range(1);
49 VERIFY(distance(ip.first, ip.second) == 3);
50 set<double> s = { 1.0, 2.0, 237.0 };
51 for (iterator i = ip.first; i != ip.second; ++i)
52 s.erase (i->second);
53 VERIFY(s.empty());
55 m = { {5, 55.0}, { 5, 66.0 }, { 42, 4242.0 } };
56 VERIFY(m.size() == 3);
57 ip = m.equal_range(5);
58 VERIFY(distance(ip.first, ip.second) == 2);
59 s = { 55.0, 66.0 };
60 for (iterator i = ip.first; i != ip.second; ++i)
61 s.erase (i->second);
62 VERIFY(s.empty());
64 m.insert({ { 7, 77.0 }, { 7, 88.0 } });
65 VERIFY(m.size() == 5);
66 VERIFY(m.count(5) == 2);
67 VERIFY(m.count(42) == 1);
68 VERIFY(m.count(7) == 2);
70 return test;
73 int main()
75 __gnu_test::set_memory_limits();
76 test01();