diff options
| author | Marshall Clow <mclow.lists@gmail.com> | 2013-09-12 03:00:31 +0000 |
|---|---|---|
| committer | Marshall Clow <mclow.lists@gmail.com> | 2013-09-12 03:00:31 +0000 |
| commit | 3cd37e6456516f87ada06192c108d66cdf6a2d93 (patch) | |
| tree | 7efd3ff9cd98c93aea2e6cb501c9987cc66b9d47 | |
| parent | afcf12f33ae8941db44de57bfd916ac75228b7bf (diff) | |
| download | bcm5719-llvm-3cd37e6456516f87ada06192c108d66cdf6a2d93.tar.gz bcm5719-llvm-3cd37e6456516f87ada06192c108d66cdf6a2d93.zip | |
LWG Issue 2210 (Part #6): unordered_map and unordered_multimap
llvm-svn: 190576
7 files changed, 531 insertions, 0 deletions
diff --git a/libcxx/include/unordered_map b/libcxx/include/unordered_map index fc30c2a5a60..e1a3f641c34 100644 --- a/libcxx/include/unordered_map +++ b/libcxx/include/unordered_map @@ -69,6 +69,22 @@ public: unordered_map(initializer_list<value_type>, 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 <class InputIterator> + 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 <class InputIterator> + 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<value_type> il, size_type n, const allocator_type& a) + : unordered_map(il, n, hasher(), key_equal(), a) {} // C++14 + unordered_map(initializer_list<value_type> 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<value_type>, 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 <class InputIterator> + 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 <class InputIterator> + 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<value_type> il, size_type n, const allocator_type& a) + : unordered_multimap(il, n, hasher(), key_equal(), a) {} // C++14 + unordered_multimap(initializer_list<value_type> 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 <class _InputIterator> + _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 <class _InputIterator> + _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<value_type> __il, size_type __n, const allocator_type& __a) + : unordered_map(__il, __n, hasher(), key_equal(), __a) {} + _LIBCPP_INLINE_VISIBILITY + unordered_map(initializer_list<value_type> __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 <class _InputIterator> + _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 <class _InputIterator> + _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<value_type> __il, size_type __n, const allocator_type& __a) + : unordered_multimap(__il, __n, hasher(), key_equal(), __a) {} + _LIBCPP_INLINE_VISIBILITY + unordered_multimap(initializer_list<value_type> __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/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 } |

