From 6dff618d7db3d0e716638bf8010326b7b128f461 Mon Sep 17 00:00:00 2001 From: Marshall Clow Date: Thu, 12 Sep 2013 03:00:31 +0000 Subject: [PATCH] LWG Issue 2210 (Part #6): unordered_map and unordered_multimap git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@190576 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/unordered_map | 80 ++++++++++++ .../unord.map.cnstr/allocator.pass.cpp | 42 +++++++ .../unord.map/unord.map.cnstr/init.pass.cpp | 66 ++++++++++ .../unord.map/unord.map.cnstr/range.pass.cpp | 69 ++++++++++ .../unord.multimap.cnstr/allocator.pass.cpp | 42 +++++++ .../unord.multimap.cnstr/init.pass.cpp | 114 +++++++++++++++++ .../unord.multimap.cnstr/range.pass.cpp | 118 ++++++++++++++++++ 7 files changed, 531 insertions(+) diff --git a/include/unordered_map b/include/unordered_map index fc30c2a5..e1a3f641 100644 --- a/include/unordered_map +++ b/include/unordered_map @@ -69,6 +69,22 @@ public: unordered_map(initializer_list, size_type n = 0, const hasher& hf = hasher(), const key_equal& eql = key_equal(), const allocator_type& a = allocator_type()); + unordered_map(size_type n, const allocator_type& a) + : unordered_map(n, hasher(), key_equal(), a) {} // C++14 + unordered_map(size_type n, const hasher& hf, const allocator_type& a) + : unordered_map(n, hf, key_equal(), a) {} // C++14 + template + unordered_map(InputIterator f, InputIterator l, size_type n, const allocator_type& a) + : unordered_map(f, l, n, hasher(), key_equal(), a) {} // C++14 + template + unordered_map(InputIterator f, InputIterator l, size_type n, const hasher& hf, + const allocator_type& a) + : unordered_map(f, l, n, hf, key_equal(), a) {} // C++14 + unordered_map(initializer_list il, size_type n, const allocator_type& a) + : unordered_map(il, n, hasher(), key_equal(), a) {} // C++14 + unordered_map(initializer_list il, size_type n, const hasher& hf, + const allocator_type& a) + : unordered_map(il, n, hf, key_equal(), a) {} // C++14 ~unordered_map(); unordered_map& operator=(const unordered_map&); unordered_map& operator=(unordered_map&&) @@ -217,6 +233,22 @@ public: unordered_multimap(initializer_list, size_type n = 0, const hasher& hf = hasher(), const key_equal& eql = key_equal(), const allocator_type& a = allocator_type()); + unordered_multimap(size_type n, const allocator_type& a) + : unordered_multimap(n, hasher(), key_equal(), a) {} // C++14 + unordered_multimap(size_type n, const hasher& hf, const allocator_type& a) + : unordered_multimap(n, hf, key_equal(), a) {} // C++14 + template + unordered_multimap(InputIterator f, InputIterator l, size_type n, const allocator_type& a) + : unordered_multimap(f, l, n, hasher(), key_equal(), a) {} // C++14 + template + unordered_multimap(InputIterator f, InputIterator l, size_type n, const hasher& hf, + const allocator_type& a) + : unordered_multimap(f, l, n, hf, key_equal(), a) {} // C++14 + unordered_multimap(initializer_list il, size_type n, const allocator_type& a) + : unordered_multimap(il, n, hasher(), key_equal(), a) {} // C++14 + unordered_multimap(initializer_list il, size_type n, const hasher& hf, + const allocator_type& a) + : unordered_multimap(il, n, hf, key_equal(), a) {} // C++14 ~unordered_multimap(); unordered_multimap& operator=(const unordered_multimap&); unordered_multimap& operator=(unordered_multimap&&) @@ -745,6 +777,30 @@ public: const hasher& __hf, const key_equal& __eql, const allocator_type& __a); #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +#if _LIBCPP_STD_VER > 11 + _LIBCPP_INLINE_VISIBILITY + unordered_map(size_type __n, const allocator_type& __a) + : unordered_map(__n, hasher(), key_equal(), __a) {} + _LIBCPP_INLINE_VISIBILITY + unordered_map(size_type __n, const hasher& __hf, const allocator_type& __a) + : unordered_map(__n, __hf, key_equal(), __a) {} + template + _LIBCPP_INLINE_VISIBILITY + unordered_map(_InputIterator __first, _InputIterator __last, size_type __n, const allocator_type& __a) + : unordered_map(__first, __last, __n, hasher(), key_equal(), __a) {} + template + _LIBCPP_INLINE_VISIBILITY + unordered_map(_InputIterator __first, _InputIterator __last, size_type __n, const hasher& __hf, + const allocator_type& __a) + : unordered_map(__first, __last, __n, __hf, key_equal(), __a) {} + _LIBCPP_INLINE_VISIBILITY + unordered_map(initializer_list __il, size_type __n, const allocator_type& __a) + : unordered_map(__il, __n, hasher(), key_equal(), __a) {} + _LIBCPP_INLINE_VISIBILITY + unordered_map(initializer_list __il, size_type __n, const hasher& __hf, + const allocator_type& __a) + : unordered_map(__il, __n, __hf, key_equal(), __a) {} +#endif // ~unordered_map() = default; _LIBCPP_INLINE_VISIBILITY unordered_map& operator=(const unordered_map& __u) @@ -1499,6 +1555,30 @@ public: const hasher& __hf, const key_equal& __eql, const allocator_type& __a); #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +#if _LIBCPP_STD_VER > 11 + _LIBCPP_INLINE_VISIBILITY + unordered_multimap(size_type __n, const allocator_type& __a) + : unordered_multimap(__n, hasher(), key_equal(), __a) {} + _LIBCPP_INLINE_VISIBILITY + unordered_multimap(size_type __n, const hasher& __hf, const allocator_type& __a) + : unordered_multimap(__n, __hf, key_equal(), __a) {} + template + _LIBCPP_INLINE_VISIBILITY + unordered_multimap(_InputIterator __first, _InputIterator __last, size_type __n, const allocator_type& __a) + : unordered_multimap(__first, __last, __n, hasher(), key_equal(), __a) {} + template + _LIBCPP_INLINE_VISIBILITY + unordered_multimap(_InputIterator __first, _InputIterator __last, size_type __n, const hasher& __hf, + const allocator_type& __a) + : unordered_multimap(__first, __last, __n, __hf, key_equal(), __a) {} + _LIBCPP_INLINE_VISIBILITY + unordered_multimap(initializer_list __il, size_type __n, const allocator_type& __a) + : unordered_multimap(__il, __n, hasher(), key_equal(), __a) {} + _LIBCPP_INLINE_VISIBILITY + unordered_multimap(initializer_list __il, size_type __n, const hasher& __hf, + const allocator_type& __a) + : unordered_multimap(__il, __n, __hf, key_equal(), __a) {} +#endif // ~unordered_multimap() = default; _LIBCPP_INLINE_VISIBILITY unordered_multimap& operator=(const unordered_multimap& __u) diff --git a/test/containers/unord/unord.map/unord.map.cnstr/allocator.pass.cpp b/test/containers/unord/unord.map/unord.map.cnstr/allocator.pass.cpp index 0f9e4cef..b49d6bfe 100644 --- a/test/containers/unord/unord.map/unord.map.cnstr/allocator.pass.cpp +++ b/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> A; + typedef test_hash> HF; + typedef test_compare> Comp; + typedef std::unordered_map 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> A; + typedef test_hash> HF; + typedef test_compare> Comp; + typedef std::unordered_map 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/test/containers/unord/unord.map/unord.map.cnstr/init.pass.cpp b/test/containers/unord/unord.map/unord.map.cnstr/init.pass.cpp index be5a70fc..594331c3 100644 --- a/test/containers/unord/unord.map/unord.map.cnstr/init.pass.cpp +++ b/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 P; + typedef test_allocator> A; + typedef test_hash> HF; + typedef test_compare> Comp; + typedef std::unordered_map 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 >()); + assert(c.key_eq() == test_compare >()); + 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 P; + typedef test_allocator> A; + typedef test_hash> HF; + typedef test_compare> Comp; + typedef std::unordered_map 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 >())); + assert(c.key_eq() == test_compare >()); + 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/test/containers/unord/unord.map/unord.map.cnstr/range.pass.cpp b/test/containers/unord/unord.map/unord.map.cnstr/range.pass.cpp index 25e1d8d6..bc316d32 100644 --- a/test/containers/unord/unord.map/unord.map.cnstr/range.pass.cpp +++ b/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 P; + typedef test_allocator> A; + typedef test_hash> HF; + typedef test_compare> Comp; + typedef std::unordered_map 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(arr), input_iterator(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 P; + typedef test_allocator> A; + typedef test_hash> HF; + typedef test_compare> Comp; + typedef std::unordered_map 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(arr), input_iterator(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/test/containers/unord/unord.multimap/unord.multimap.cnstr/allocator.pass.cpp b/test/containers/unord/unord.multimap/unord.multimap.cnstr/allocator.pass.cpp index 1f7f4034..dbcdca44 100644 --- a/test/containers/unord/unord.multimap/unord.multimap.cnstr/allocator.pass.cpp +++ b/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> A; + typedef test_hash> HF; + typedef test_compare> Comp; + typedef std::unordered_multimap 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> A; + typedef test_hash> HF; + typedef test_compare> Comp; + typedef std::unordered_multimap 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/test/containers/unord/unord.multimap/unord.multimap.cnstr/init.pass.cpp b/test/containers/unord/unord.multimap/unord.multimap.cnstr/init.pass.cpp index b4b2ac58..bcde6666 100644 --- a/test/containers/unord/unord.multimap/unord.multimap.cnstr/init.pass.cpp +++ b/test/containers/unord/unord.multimap/unord.multimap.cnstr/init.pass.cpp @@ -135,6 +135,120 @@ int main() assert(c.key_eq() == test_compare >()); assert((c.get_allocator() == min_allocator >())); } +#if _LIBCPP_STD_VER > 11 + { + typedef std::pair P; + typedef test_allocator> A; + typedef test_hash> HF; + typedef test_compare> Comp; + typedef std::unordered_multimap 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 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 P; + typedef test_allocator> A; + typedef test_hash> HF; + typedef test_compare> Comp; + typedef std::unordered_multimap 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 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/test/containers/unord/unord.multimap/unord.multimap.cnstr/range.pass.cpp b/test/containers/unord/unord.multimap/unord.multimap.cnstr/range.pass.cpp index 74171c71..a4314813 100644 --- a/test/containers/unord/unord.multimap/unord.multimap.cnstr/range.pass.cpp +++ b/test/containers/unord/unord.multimap/unord.multimap.cnstr/range.pass.cpp @@ -141,5 +141,123 @@ int main() assert(c.key_eq() == test_compare >()); assert((c.get_allocator() == min_allocator >())); } +#if _LIBCPP_STD_VER > 11 + { + typedef std::pair P; + typedef test_allocator> A; + typedef test_hash> HF; + typedef test_compare> Comp; + typedef std::unordered_multimap 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(arr), input_iterator(arr + sizeof(arr)/sizeof(arr[0])), 14, a); + assert(c.bucket_count() >= 14); + assert(c.size() == 6); + typedef std::pair 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 P; + typedef test_allocator> A; + typedef test_hash> HF; + typedef test_compare> Comp; + typedef std::unordered_multimap 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(arr), input_iterator(arr + sizeof(arr)/sizeof(arr[0])), 12, hf, a ); + assert(c.bucket_count() >= 12); + assert(c.size() == 6); + typedef std::pair 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 }