summaryrefslogtreecommitdiffstats
path: root/libcxx/test/containers
diff options
context:
space:
mode:
authorMarshall Clow <mclow.lists@gmail.com>2013-09-12 03:00:31 +0000
committerMarshall Clow <mclow.lists@gmail.com>2013-09-12 03:00:31 +0000
commit3cd37e6456516f87ada06192c108d66cdf6a2d93 (patch)
tree7efd3ff9cd98c93aea2e6cb501c9987cc66b9d47 /libcxx/test/containers
parentafcf12f33ae8941db44de57bfd916ac75228b7bf (diff)
downloadbcm5719-llvm-3cd37e6456516f87ada06192c108d66cdf6a2d93.tar.gz
bcm5719-llvm-3cd37e6456516f87ada06192c108d66cdf6a2d93.zip
LWG Issue 2210 (Part #6): unordered_map and unordered_multimap
llvm-svn: 190576
Diffstat (limited to 'libcxx/test/containers')
-rw-r--r--libcxx/test/containers/unord/unord.map/unord.map.cnstr/allocator.pass.cpp42
-rw-r--r--libcxx/test/containers/unord/unord.map/unord.map.cnstr/init.pass.cpp66
-rw-r--r--libcxx/test/containers/unord/unord.map/unord.map.cnstr/range.pass.cpp69
-rw-r--r--libcxx/test/containers/unord/unord.multimap/unord.multimap.cnstr/allocator.pass.cpp42
-rw-r--r--libcxx/test/containers/unord/unord.multimap/unord.multimap.cnstr/init.pass.cpp114
-rw-r--r--libcxx/test/containers/unord/unord.multimap/unord.multimap.cnstr/range.pass.cpp118
6 files changed, 451 insertions, 0 deletions
diff --git a/libcxx/test/containers/unord/unord.map/unord.map.cnstr/allocator.pass.cpp b/libcxx/test/containers/unord/unord.map/unord.map.cnstr/allocator.pass.cpp
index 0f9e4cefb59..b49d6bfe994 100644
--- a/libcxx/test/containers/unord/unord.map/unord.map.cnstr/allocator.pass.cpp
+++ b/libcxx/test/containers/unord/unord.map/unord.map.cnstr/allocator.pass.cpp
@@ -65,5 +65,47 @@ int main()
assert(c.load_factor() == 0);
assert(c.max_load_factor() == 1);
}
+#if _LIBCPP_STD_VER > 11
+ {
+ typedef NotConstructible T;
+ typedef test_allocator<std::pair<const T, T>> A;
+ typedef test_hash<std::hash<T>> HF;
+ typedef test_compare<std::equal_to<T>> Comp;
+ typedef std::unordered_map<T, T, HF, Comp, A> C;
+
+ A a(10);
+ C c(2, a);
+ assert(c.bucket_count() == 2);
+ assert(c.hash_function() == HF());
+ assert(c.key_eq() == Comp());
+ assert(c.get_allocator() == a);
+ assert(c.size() == 0);
+ assert(c.empty());
+ assert(std::distance(c.begin(), c.end()) == 0);
+ assert(c.load_factor() == 0);
+ assert(c.max_load_factor() == 1);
+ }
+ {
+ typedef NotConstructible T;
+ typedef test_allocator<std::pair<const T, T>> A;
+ typedef test_hash<std::hash<T>> HF;
+ typedef test_compare<std::equal_to<T>> Comp;
+ typedef std::unordered_map<T, T, HF, Comp, A> C;
+
+ A a(10);
+ HF hf(12);
+ C c(2, hf, a);
+ assert(c.bucket_count() == 2);
+ assert(c.hash_function() == hf);
+ assert(!(c.hash_function() == HF()));
+ assert(c.key_eq() == Comp());
+ assert(c.get_allocator() == a);
+ assert(c.size() == 0);
+ assert(c.empty());
+ assert(std::distance(c.begin(), c.end()) == 0);
+ assert(c.load_factor() == 0);
+ assert(c.max_load_factor() == 1);
+ }
+#endif
#endif
}
diff --git a/libcxx/test/containers/unord/unord.map/unord.map.cnstr/init.pass.cpp b/libcxx/test/containers/unord/unord.map/unord.map.cnstr/init.pass.cpp
index be5a70fcbf5..594331c3d0d 100644
--- a/libcxx/test/containers/unord/unord.map/unord.map.cnstr/init.pass.cpp
+++ b/libcxx/test/containers/unord/unord.map/unord.map.cnstr/init.pass.cpp
@@ -91,6 +91,72 @@ int main()
assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON);
assert(c.max_load_factor() == 1);
}
+#if _LIBCPP_STD_VER > 11
+ {
+ typedef std::pair<int, std::string> P;
+ typedef test_allocator<std::pair<const int, std::string>> A;
+ typedef test_hash<std::hash<int>> HF;
+ typedef test_compare<std::equal_to<int>> Comp;
+ typedef std::unordered_map<int, std::string, HF, Comp, A> C;
+
+ A a(42);
+ C c ( {
+ P(1, "one"),
+ P(2, "two"),
+ P(3, "three"),
+ P(4, "four"),
+ P(1, "four"),
+ P(2, "four"),
+ }, 12, a);
+ assert(c.bucket_count() >= 12);
+ assert(c.size() == 4);
+ assert(c.at(1) == "one");
+ assert(c.at(2) == "two");
+ assert(c.at(3) == "three");
+ assert(c.at(4) == "four");
+ assert(c.hash_function() == test_hash<std::hash<int> >());
+ assert(c.key_eq() == test_compare<std::equal_to<int> >());
+ assert(c.get_allocator() == a);
+ assert(!c.empty());
+ assert(std::distance(c.begin(), c.end()) == c.size());
+ assert(std::distance(c.cbegin(), c.cend()) == c.size());
+ assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON);
+ assert(c.max_load_factor() == 1);
+ }
+ {
+ typedef std::pair<int, std::string> P;
+ typedef test_allocator<std::pair<const int, std::string>> A;
+ typedef test_hash<std::hash<int>> HF;
+ typedef test_compare<std::equal_to<int>> Comp;
+ typedef std::unordered_map<int, std::string, HF, Comp, A> C;
+
+ HF hf(42);
+ A a(43);
+ C c ( {
+ P(1, "one"),
+ P(2, "two"),
+ P(3, "three"),
+ P(4, "four"),
+ P(1, "four"),
+ P(2, "four"),
+ }, 12, hf, a);
+ assert(c.bucket_count() >= 12);
+ assert(c.size() == 4);
+ assert(c.at(1) == "one");
+ assert(c.at(2) == "two");
+ assert(c.at(3) == "three");
+ assert(c.at(4) == "four");
+ assert(c.hash_function() == hf);
+ assert(!(c.hash_function() == test_hash<std::hash<int> >()));
+ assert(c.key_eq() == test_compare<std::equal_to<int> >());
+ assert(c.get_allocator() == a);
+ assert(!c.empty());
+ assert(std::distance(c.begin(), c.end()) == c.size());
+ assert(std::distance(c.cbegin(), c.cend()) == c.size());
+ assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON);
+ assert(c.max_load_factor() == 1);
+ }
+#endif
#endif
#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
}
diff --git a/libcxx/test/containers/unord/unord.map/unord.map.cnstr/range.pass.cpp b/libcxx/test/containers/unord/unord.map/unord.map.cnstr/range.pass.cpp
index 25e1d8d641d..bc316d325a5 100644
--- a/libcxx/test/containers/unord/unord.map/unord.map.cnstr/range.pass.cpp
+++ b/libcxx/test/containers/unord/unord.map/unord.map.cnstr/range.pass.cpp
@@ -97,5 +97,74 @@ int main()
assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON);
assert(c.max_load_factor() == 1);
}
+#if _LIBCPP_STD_VER > 11
+ {
+ typedef std::pair<int, std::string> P;
+ typedef test_allocator<std::pair<const int, std::string>> A;
+ typedef test_hash<std::hash<int>> HF;
+ typedef test_compare<std::equal_to<int>> Comp;
+ typedef std::unordered_map<int, std::string, HF, Comp, A> C;
+
+ P arr[] =
+ {
+ P(1, "one"),
+ P(2, "two"),
+ P(3, "three"),
+ P(4, "four"),
+ P(1, "four"),
+ P(2, "four"),
+ };
+ C c(input_iterator<P*>(arr), input_iterator<P*>(arr + sizeof(arr)/sizeof(arr[0])), 14);
+ assert(c.bucket_count() >= 14);
+ assert(c.size() == 4);
+ assert(c.at(1) == "one");
+ assert(c.at(2) == "two");
+ assert(c.at(3) == "three");
+ assert(c.at(4) == "four");
+ assert(c.hash_function() == HF());
+ assert(c.key_eq() == Comp());
+ assert(c.get_allocator() == A());
+ assert(!c.empty());
+ assert(std::distance(c.begin(), c.end()) == c.size());
+ assert(std::distance(c.cbegin(), c.cend()) == c.size());
+ assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON);
+ assert(c.max_load_factor() == 1);
+ }
+ {
+ typedef std::pair<int, std::string> P;
+ typedef test_allocator<std::pair<const int, std::string>> A;
+ typedef test_hash<std::hash<int>> HF;
+ typedef test_compare<std::equal_to<int>> Comp;
+ typedef std::unordered_map<int, std::string, HF, Comp, A> C;
+
+ P arr[] =
+ {
+ P(1, "one"),
+ P(2, "two"),
+ P(3, "three"),
+ P(4, "four"),
+ P(1, "four"),
+ P(2, "four"),
+ };
+ HF hf(42);
+ A a(43);
+ C c(input_iterator<P*>(arr), input_iterator<P*>(arr + sizeof(arr)/sizeof(arr[0])), 14, hf, a);
+ assert(c.bucket_count() >= 14);
+ assert(c.size() == 4);
+ assert(c.at(1) == "one");
+ assert(c.at(2) == "two");
+ assert(c.at(3) == "three");
+ assert(c.at(4) == "four");
+ assert(c.hash_function() == hf);
+ assert(!(c.hash_function() == HF()));
+ assert(c.key_eq() == Comp());
+ assert(c.get_allocator() == a);
+ assert(!c.empty());
+ assert(std::distance(c.begin(), c.end()) == c.size());
+ assert(std::distance(c.cbegin(), c.cend()) == c.size());
+ assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON);
+ assert(c.max_load_factor() == 1);
+ }
+#endif
#endif
}
diff --git a/libcxx/test/containers/unord/unord.multimap/unord.multimap.cnstr/allocator.pass.cpp b/libcxx/test/containers/unord/unord.multimap/unord.multimap.cnstr/allocator.pass.cpp
index 1f7f4034057..dbcdca44a6e 100644
--- a/libcxx/test/containers/unord/unord.multimap/unord.multimap.cnstr/allocator.pass.cpp
+++ b/libcxx/test/containers/unord/unord.multimap/unord.multimap.cnstr/allocator.pass.cpp
@@ -65,5 +65,47 @@ int main()
assert(c.load_factor() == 0);
assert(c.max_load_factor() == 1);
}
+#if _LIBCPP_STD_VER > 11
+ {
+ typedef NotConstructible T;
+ typedef test_allocator<std::pair<const T, T>> A;
+ typedef test_hash<std::hash<T>> HF;
+ typedef test_compare<std::equal_to<T>> Comp;
+ typedef std::unordered_multimap<T, T, HF, Comp, A> C;
+
+ A a(10);
+ C c(2, a);
+ assert(c.bucket_count() == 2);
+ assert(c.hash_function() == HF());
+ assert(c.key_eq() == Comp());
+ assert(c.get_allocator() == a);
+ assert(c.size() == 0);
+ assert(c.empty());
+ assert(std::distance(c.begin(), c.end()) == 0);
+ assert(c.load_factor() == 0);
+ assert(c.max_load_factor() == 1);
+ }
+ {
+ typedef NotConstructible T;
+ typedef test_allocator<std::pair<const T, T>> A;
+ typedef test_hash<std::hash<T>> HF;
+ typedef test_compare<std::equal_to<T>> Comp;
+ typedef std::unordered_multimap<T, T, HF, Comp, A> C;
+
+ A a(10);
+ HF hf(12);
+ C c(2, hf, a);
+ assert(c.bucket_count() == 2);
+ assert(c.hash_function() == hf);
+ assert(!(c.hash_function() == HF()));
+ assert(c.key_eq() == Comp());
+ assert(c.get_allocator() == a);
+ assert(c.size() == 0);
+ assert(c.empty());
+ assert(std::distance(c.begin(), c.end()) == 0);
+ assert(c.load_factor() == 0);
+ assert(c.max_load_factor() == 1);
+ }
+#endif
#endif
}
diff --git a/libcxx/test/containers/unord/unord.multimap/unord.multimap.cnstr/init.pass.cpp b/libcxx/test/containers/unord/unord.multimap/unord.multimap.cnstr/init.pass.cpp
index b4b2ac58f1c..bcde6666eb2 100644
--- a/libcxx/test/containers/unord/unord.multimap/unord.multimap.cnstr/init.pass.cpp
+++ b/libcxx/test/containers/unord/unord.multimap/unord.multimap.cnstr/init.pass.cpp
@@ -135,6 +135,120 @@ int main()
assert(c.key_eq() == test_compare<std::equal_to<int> >());
assert((c.get_allocator() == min_allocator<std::pair<const int, std::string> >()));
}
+#if _LIBCPP_STD_VER > 11
+ {
+ typedef std::pair<int, std::string> P;
+ typedef test_allocator<std::pair<const int, std::string>> A;
+ typedef test_hash<std::hash<int>> HF;
+ typedef test_compare<std::equal_to<int>> Comp;
+ typedef std::unordered_multimap<int, std::string, HF, Comp, A> C;
+
+ A a(42);
+ C c ({
+ P(1, "one"),
+ P(2, "two"),
+ P(3, "three"),
+ P(4, "four"),
+ P(1, "four"),
+ P(2, "four"),
+ }, 12, a );
+ assert(c.bucket_count() >= 12);
+ assert(c.size() == 6);
+ typedef std::pair<C::const_iterator, C::const_iterator> Eq;
+ Eq eq = c.equal_range(1);
+ assert(std::distance(eq.first, eq.second) == 2);
+ C::const_iterator i = eq.first;
+ assert(i->first == 1);
+ assert(i->second == "one");
+ ++i;
+ assert(i->first == 1);
+ assert(i->second == "four");
+ eq = c.equal_range(2);
+ assert(std::distance(eq.first, eq.second) == 2);
+ i = eq.first;
+ assert(i->first == 2);
+ assert(i->second == "two");
+ ++i;
+ assert(i->first == 2);
+ assert(i->second == "four");
+
+ eq = c.equal_range(3);
+ assert(std::distance(eq.first, eq.second) == 1);
+ i = eq.first;
+ assert(i->first == 3);
+ assert(i->second == "three");
+ eq = c.equal_range(4);
+ assert(std::distance(eq.first, eq.second) == 1);
+ i = eq.first;
+ assert(i->first == 4);
+ assert(i->second == "four");
+ assert(std::distance(c.begin(), c.end()) == c.size());
+ assert(std::distance(c.cbegin(), c.cend()) == c.size());
+ assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON);
+ assert(c.max_load_factor() == 1);
+ assert(c.hash_function() == HF());
+ assert(c.key_eq() == Comp());
+ assert(c.get_allocator() == a);
+ assert(!(c.get_allocator() == A()));
+ }
+ {
+ typedef std::pair<int, std::string> P;
+ typedef test_allocator<std::pair<const int, std::string>> A;
+ typedef test_hash<std::hash<int>> HF;
+ typedef test_compare<std::equal_to<int>> Comp;
+ typedef std::unordered_multimap<int, std::string, HF, Comp, A> C;
+
+ HF hf(42);
+ A a(43);
+ C c ({
+ P(1, "one"),
+ P(2, "two"),
+ P(3, "three"),
+ P(4, "four"),
+ P(1, "four"),
+ P(2, "four"),
+ }, 12, hf, a );
+ assert(c.bucket_count() >= 12);
+ assert(c.size() == 6);
+ typedef std::pair<C::const_iterator, C::const_iterator> Eq;
+ Eq eq = c.equal_range(1);
+ assert(std::distance(eq.first, eq.second) == 2);
+ C::const_iterator i = eq.first;
+ assert(i->first == 1);
+ assert(i->second == "one");
+ ++i;
+ assert(i->first == 1);
+ assert(i->second == "four");
+ eq = c.equal_range(2);
+ assert(std::distance(eq.first, eq.second) == 2);
+ i = eq.first;
+ assert(i->first == 2);
+ assert(i->second == "two");
+ ++i;
+ assert(i->first == 2);
+ assert(i->second == "four");
+
+ eq = c.equal_range(3);
+ assert(std::distance(eq.first, eq.second) == 1);
+ i = eq.first;
+ assert(i->first == 3);
+ assert(i->second == "three");
+ eq = c.equal_range(4);
+ assert(std::distance(eq.first, eq.second) == 1);
+ i = eq.first;
+ assert(i->first == 4);
+ assert(i->second == "four");
+ assert(std::distance(c.begin(), c.end()) == c.size());
+ assert(std::distance(c.cbegin(), c.cend()) == c.size());
+ assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON);
+ assert(c.max_load_factor() == 1);
+ assert(c.hash_function() == hf);
+ assert(!(c.hash_function() == HF()));
+ assert(c.key_eq() == Comp());
+ assert(c.get_allocator() == a);
+ assert(!(c.get_allocator() == A()));
+ }
+#endif
#endif
#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
}
diff --git a/libcxx/test/containers/unord/unord.multimap/unord.multimap.cnstr/range.pass.cpp b/libcxx/test/containers/unord/unord.multimap/unord.multimap.cnstr/range.pass.cpp
index 74171c71f70..a4314813111 100644
--- a/libcxx/test/containers/unord/unord.multimap/unord.multimap.cnstr/range.pass.cpp
+++ b/libcxx/test/containers/unord/unord.multimap/unord.multimap.cnstr/range.pass.cpp
@@ -141,5 +141,123 @@ int main()
assert(c.key_eq() == test_compare<std::equal_to<int> >());
assert((c.get_allocator() == min_allocator<std::pair<const int, std::string> >()));
}
+#if _LIBCPP_STD_VER > 11
+ {
+ typedef std::pair<int, std::string> P;
+ typedef test_allocator<std::pair<const int, std::string>> A;
+ typedef test_hash<std::hash<int>> HF;
+ typedef test_compare<std::equal_to<int>> Comp;
+ typedef std::unordered_multimap<int, std::string, HF, Comp, A> C;
+
+ P arr[] =
+ {
+ P(1, "one"),
+ P(2, "two"),
+ P(3, "three"),
+ P(4, "four"),
+ P(1, "four"),
+ P(2, "four"),
+ };
+ A a(42);
+ C c(input_iterator<P*>(arr), input_iterator<P*>(arr + sizeof(arr)/sizeof(arr[0])), 14, a);
+ assert(c.bucket_count() >= 14);
+ assert(c.size() == 6);
+ typedef std::pair<C::const_iterator, C::const_iterator> Eq;
+ Eq eq = c.equal_range(1);
+ assert(std::distance(eq.first, eq.second) == 2);
+ C::const_iterator i = eq.first;
+ assert(i->first == 1);
+ assert(i->second == "one");
+ ++i;
+ assert(i->first == 1);
+ assert(i->second == "four");
+ eq = c.equal_range(2);
+ assert(std::distance(eq.first, eq.second) == 2);
+ i = eq.first;
+ assert(i->first == 2);
+ assert(i->second == "two");
+ ++i;
+ assert(i->first == 2);
+ assert(i->second == "four");
+
+ eq = c.equal_range(3);
+ assert(std::distance(eq.first, eq.second) == 1);
+ i = eq.first;
+ assert(i->first == 3);
+ assert(i->second == "three");
+ eq = c.equal_range(4);
+ assert(std::distance(eq.first, eq.second) == 1);
+ i = eq.first;
+ assert(i->first == 4);
+ assert(i->second == "four");
+ assert(std::distance(c.begin(), c.end()) == c.size());
+ assert(std::distance(c.cbegin(), c.cend()) == c.size());
+ assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON);
+ assert(c.max_load_factor() == 1);
+ assert(c.hash_function() == HF());
+ assert(c.key_eq() == Comp());
+ assert(c.get_allocator() == a);
+ assert(!(c.get_allocator() == A()));
+ }
+ {
+ typedef std::pair<int, std::string> P;
+ typedef test_allocator<std::pair<const int, std::string>> A;
+ typedef test_hash<std::hash<int>> HF;
+ typedef test_compare<std::equal_to<int>> Comp;
+ typedef std::unordered_multimap<int, std::string, HF, Comp, A> C;
+
+ P arr[] =
+ {
+ P(1, "one"),
+ P(2, "two"),
+ P(3, "three"),
+ P(4, "four"),
+ P(1, "four"),
+ P(2, "four"),
+ };
+ A a(42);
+ HF hf (43);
+ C c(input_iterator<P*>(arr), input_iterator<P*>(arr + sizeof(arr)/sizeof(arr[0])), 12, hf, a );
+ assert(c.bucket_count() >= 12);
+ assert(c.size() == 6);
+ typedef std::pair<C::const_iterator, C::const_iterator> Eq;
+ Eq eq = c.equal_range(1);
+ assert(std::distance(eq.first, eq.second) == 2);
+ C::const_iterator i = eq.first;
+ assert(i->first == 1);
+ assert(i->second == "one");
+ ++i;
+ assert(i->first == 1);
+ assert(i->second == "four");
+ eq = c.equal_range(2);
+ assert(std::distance(eq.first, eq.second) == 2);
+ i = eq.first;
+ assert(i->first == 2);
+ assert(i->second == "two");
+ ++i;
+ assert(i->first == 2);
+ assert(i->second == "four");
+
+ eq = c.equal_range(3);
+ assert(std::distance(eq.first, eq.second) == 1);
+ i = eq.first;
+ assert(i->first == 3);
+ assert(i->second == "three");
+ eq = c.equal_range(4);
+ assert(std::distance(eq.first, eq.second) == 1);
+ i = eq.first;
+ assert(i->first == 4);
+ assert(i->second == "four");
+ assert(std::distance(c.begin(), c.end()) == c.size());
+ assert(std::distance(c.cbegin(), c.cend()) == c.size());
+ assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON);
+ assert(c.max_load_factor() == 1);
+ assert(c.hash_function() == hf);
+ assert(!(c.hash_function() == HF()));
+ assert(c.key_eq() == Comp());
+ assert(c.get_allocator() == a);
+ assert(!(c.get_allocator() == A()));
+ }
+#endif
#endif
}
OpenPOWER on IntegriCloud