copy.pass.cpp revision f5256e16dfc425c1d466f6308d4026d529ce9e0b
1//===----------------------------------------------------------------------===//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10// <unordered_map>
11
12// template <class Key, class T, class Hash = hash<Key>, class Pred = equal_to<Key>,
13//           class Alloc = allocator<pair<const Key, T>>>
14// class unordered_multimap
15
16// unordered_multimap(const unordered_multimap& u);
17
18#include <unordered_map>
19#include <string>
20#include <cassert>
21
22#include "../../../test_compare.h"
23#include "../../../test_hash.h"
24#include "../../../test_allocator.h"
25
26int main()
27{
28    {
29        typedef std::unordered_multimap<int, std::string,
30                                   test_hash<std::hash<int> >,
31                                   test_compare<std::equal_to<int> >,
32                                   test_allocator<std::pair<const int, std::string> >
33                                   > C;
34        typedef std::pair<int, std::string> P;
35        P a[] =
36        {
37            P(1, "one"),
38            P(2, "two"),
39            P(3, "three"),
40            P(4, "four"),
41            P(1, "four"),
42            P(2, "four"),
43        };
44        C c0(a, a + sizeof(a)/sizeof(a[0]),
45            7,
46            test_hash<std::hash<int> >(8),
47            test_compare<std::equal_to<int> >(9),
48            test_allocator<std::pair<const int, std::string> >(10)
49           );
50        C c = c0;
51        assert(c.bucket_count() == 7);
52        assert(c.size() == 6);
53        C::const_iterator i = c.cbegin();
54        assert(i->first == 1);
55        assert(i->second == "one");
56        ++i;
57        assert(i->first == 1);
58        assert(i->second == "four");
59        ++i;
60        assert(i->first == 2);
61        assert(i->second == "two");
62        ++i;
63        assert(i->first == 2);
64        assert(i->second == "four");
65        ++i;
66        assert(i->first == 3);
67        assert(i->second == "three");
68        ++i;
69        assert(i->first == 4);
70        assert(i->second == "four");
71        assert(c.hash_function() == test_hash<std::hash<int> >(8));
72        assert(c.key_eq() == test_compare<std::equal_to<int> >(9));
73        assert(c.get_allocator() ==
74               (test_allocator<std::pair<const int, std::string> >(10)));
75        assert(!c.empty());
76        assert(std::distance(c.begin(), c.end()) == c.size());
77        assert(std::distance(c.cbegin(), c.cend()) == c.size());
78        assert(c.load_factor() == (float)c.size()/c.bucket_count());
79        assert(c.max_load_factor() == 1);
80    }
81#ifndef _LIBCPP_HAS_NO_ADVANCED_SFINAE
82    {
83        typedef std::unordered_multimap<int, std::string,
84                                   test_hash<std::hash<int> >,
85                                   test_compare<std::equal_to<int> >,
86                                   other_allocator<std::pair<const int, std::string> >
87                                   > C;
88        typedef std::pair<int, std::string> P;
89        P a[] =
90        {
91            P(1, "one"),
92            P(2, "two"),
93            P(3, "three"),
94            P(4, "four"),
95            P(1, "four"),
96            P(2, "four"),
97        };
98        C c0(a, a + sizeof(a)/sizeof(a[0]),
99            7,
100            test_hash<std::hash<int> >(8),
101            test_compare<std::equal_to<int> >(9),
102            other_allocator<std::pair<const int, std::string> >(10)
103           );
104        C c = c0;
105        assert(c.bucket_count() == 7);
106        assert(c.size() == 6);
107        C::const_iterator i = c.cbegin();
108        assert(i->first == 1);
109        assert(i->second == "one");
110        ++i;
111        assert(i->first == 1);
112        assert(i->second == "four");
113        ++i;
114        assert(i->first == 2);
115        assert(i->second == "two");
116        ++i;
117        assert(i->first == 2);
118        assert(i->second == "four");
119        ++i;
120        assert(i->first == 3);
121        assert(i->second == "three");
122        ++i;
123        assert(i->first == 4);
124        assert(i->second == "four");
125        assert(c.hash_function() == test_hash<std::hash<int> >(8));
126        assert(c.key_eq() == test_compare<std::equal_to<int> >(9));
127        assert(c.get_allocator() ==
128               (other_allocator<std::pair<const int, std::string> >(-2)));
129        assert(!c.empty());
130        assert(std::distance(c.begin(), c.end()) == c.size());
131        assert(std::distance(c.cbegin(), c.cend()) == c.size());
132        assert(c.load_factor() == (float)c.size()/c.bucket_count());
133        assert(c.max_load_factor() == 1);
134    }
135#endif
136}
137