From bd444af850efeb267e17d1b3aef521c5c4d43cc4 Mon Sep 17 00:00:00 2001 From: Marshall Clow Date: Mon, 30 Sep 2013 21:33:51 +0000 Subject: [PATCH] Part 8 of LWG Issue 2210' unordered_set and unordered multiset; this got missed when I went on vacation git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@191705 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/unordered_set | 77 +++++++++++++++++++ .../unord.multiset.cnstr/allocator.pass.cpp | 44 +++++++++++ .../unord.multiset.cnstr/init.pass.cpp | 70 +++++++++++++++++ .../unord.multiset.cnstr/range.pass.cpp | 70 +++++++++++++++++ .../unord.set.cnstr/allocator.pass.cpp | 44 +++++++++++ .../unord.set/unord.set.cnstr/init.pass.cpp | 70 +++++++++++++++++ .../unord.set/unord.set.cnstr/range.pass.cpp | 71 +++++++++++++++++ 7 files changed, 446 insertions(+) diff --git a/include/unordered_set b/include/unordered_set index b5b73478..fd378fa0 100644 --- a/include/unordered_set +++ b/include/unordered_set @@ -68,6 +68,16 @@ public: unordered_set(initializer_list, size_type n = 0, const hasher& hf = hasher(), const key_equal& eql = key_equal(), const allocator_type& a = allocator_type()); + unordered_set(size_type n, const allocator_type& a); // C++14 + unordered_set(size_type n, const hasher& hf, const allocator_type& a); // C++14 + template + unordered_set(InputIterator f, InputIterator l, size_type n, const allocator_type& a); // C++14 + template + unordered_set(InputIterator f, InputIterator l, size_type n, + const hasher& hf, const allocator_type& a); // C++14 + unordered_set(initializer_list il, size_type n, const allocator_type& a); // C++14 + unordered_set(initializer_list il, size_type n, + const hasher& hf, const allocator_type& a); // C++14 ~unordered_set(); unordered_set& operator=(const unordered_set&); unordered_set& operator=(unordered_set&&) @@ -207,6 +217,16 @@ public: unordered_multiset(initializer_list, size_type n = /see below/, const hasher& hf = hasher(), const key_equal& eql = key_equal(), const allocator_type& a = allocator_type()); + unordered_multiset(size_type n, const allocator_type& a); // C++14 + unordered_multiset(size_type n, const hasher& hf, const allocator_type& a); // C++14 + template + unordered_multiset(InputIterator f, InputIterator l, size_type n, const allocator_type& a); // C++14 + template + unordered_multiset(InputIterator f, InputIterator l, size_type n, + const hasher& hf, const allocator_type& a); // C++14 + unordered_multiset(initializer_list il, size_type n, const allocator_type& a); // C++14 + unordered_multiset(initializer_list il, size_type n, + const hasher& hf, const allocator_type& a); // C++14 ~unordered_multiset(); unordered_multiset& operator=(const unordered_multiset&); unordered_multiset& operator=(unordered_multiset&&) @@ -353,6 +373,14 @@ public: } explicit unordered_set(size_type __n, const hasher& __hf = hasher(), const key_equal& __eql = key_equal()); +#if _LIBCPP_STD_VER > 11 + inline _LIBCPP_INLINE_VISIBILITY + unordered_set(size_type __n, const allocator_type& __a) + : unordered_set(__n, hasher(), key_equal(), __a) {} + inline _LIBCPP_INLINE_VISIBILITY + unordered_set(size_type __n, const hasher& __hf, const allocator_type& __a) + : unordered_set(__n, __hf, key_equal(), __a) {} +#endif unordered_set(size_type __n, const hasher& __hf, const key_equal& __eql, const allocator_type& __a); template @@ -365,6 +393,17 @@ public: unordered_set(_InputIterator __first, _InputIterator __last, size_type __n, const hasher& __hf, const key_equal& __eql, const allocator_type& __a); +#if _LIBCPP_STD_VER > 11 + template + inline _LIBCPP_INLINE_VISIBILITY + unordered_set(_InputIterator __first, _InputIterator __last, + size_type __n, const allocator_type& __a) + : unordered_set(__first, __last, __n, hasher(), key_equal(), __a) {} + template + unordered_set(_InputIterator __first, _InputIterator __last, + size_type __n, const hasher& __hf, const allocator_type& __a) + : unordered_set(__first, __last, __n, __hf, key_equal(), __a) {} +#endif explicit unordered_set(const allocator_type& __a); unordered_set(const unordered_set& __u); unordered_set(const unordered_set& __u, const allocator_type& __a); @@ -381,6 +420,16 @@ public: unordered_set(initializer_list __il, size_type __n, const hasher& __hf, const key_equal& __eql, const allocator_type& __a); +#if _LIBCPP_STD_VER > 11 + inline _LIBCPP_INLINE_VISIBILITY + unordered_set(initializer_list __il, size_type __n, + const allocator_type& __a) + : unordered_set(__il, __n, hasher(), key_equal(), __a) {} + inline _LIBCPP_INLINE_VISIBILITY + unordered_set(initializer_list __il, size_type __n, + const hasher& __hf, const allocator_type& __a) + : unordered_set(__il, __n, __hf, key_equal(), __a) {} +#endif #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS // ~unordered_set() = default; _LIBCPP_INLINE_VISIBILITY @@ -861,6 +910,14 @@ public: const key_equal& __eql = key_equal()); unordered_multiset(size_type __n, const hasher& __hf, const key_equal& __eql, const allocator_type& __a); +#if _LIBCPP_STD_VER > 11 + inline _LIBCPP_INLINE_VISIBILITY + unordered_multiset(size_type __n, const allocator_type& __a) + : unordered_multiset(__n, hasher(), key_equal(), __a) {} + inline _LIBCPP_INLINE_VISIBILITY + unordered_multiset(size_type __n, const hasher& __hf, const allocator_type& __a) + : unordered_multiset(__n, __hf, key_equal(), __a) {} +#endif template unordered_multiset(_InputIterator __first, _InputIterator __last); template @@ -871,6 +928,18 @@ public: unordered_multiset(_InputIterator __first, _InputIterator __last, size_type __n , const hasher& __hf, const key_equal& __eql, const allocator_type& __a); +#if _LIBCPP_STD_VER > 11 + template + inline _LIBCPP_INLINE_VISIBILITY + unordered_multiset(_InputIterator __first, _InputIterator __last, + size_type __n, const allocator_type& __a) + : unordered_multiset(__first, __last, __n, hasher(), key_equal(), __a) {} + template + inline _LIBCPP_INLINE_VISIBILITY + unordered_multiset(_InputIterator __first, _InputIterator __last, + size_type __n, const hasher& __hf, const allocator_type& __a) + : unordered_multiset(__first, __last, __n, __hf, key_equal(), __a) {} +#endif explicit unordered_multiset(const allocator_type& __a); unordered_multiset(const unordered_multiset& __u); unordered_multiset(const unordered_multiset& __u, const allocator_type& __a); @@ -887,6 +956,14 @@ public: unordered_multiset(initializer_list __il, size_type __n, const hasher& __hf, const key_equal& __eql, const allocator_type& __a); +#if _LIBCPP_STD_VER > 11 + inline _LIBCPP_INLINE_VISIBILITY + unordered_multiset(initializer_list __il, size_type __n, const allocator_type& __a) + : unordered_multiset(__il, __n, hasher(), key_equal(), __a) {} + inline _LIBCPP_INLINE_VISIBILITY + unordered_multiset(initializer_list __il, size_type __n, const hasher& __hf, const allocator_type& __a) + : unordered_multiset(__il, __n, __hf, key_equal(), __a) {} +#endif #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS // ~unordered_multiset() = default; _LIBCPP_INLINE_VISIBILITY diff --git a/test/containers/unord/unord.multiset/unord.multiset.cnstr/allocator.pass.cpp b/test/containers/unord/unord.multiset/unord.multiset.cnstr/allocator.pass.cpp index db8ba0e7..af9dd01b 100644 --- a/test/containers/unord/unord.multiset/unord.multiset.cnstr/allocator.pass.cpp +++ b/test/containers/unord/unord.multiset/unord.multiset.cnstr/allocator.pass.cpp @@ -61,5 +61,49 @@ int main() assert(c.load_factor() == 0); assert(c.max_load_factor() == 1); } +#if _LIBCPP_STD_VER > 11 + { + typedef NotConstructible T; + typedef test_hash> HF; + typedef test_compare> Comp; + typedef test_allocator A; + typedef std::unordered_multiset C; + + A a(43); + C c(3, a); + assert(c.bucket_count() == 3); + assert(c.hash_function() == HF()); + assert(c.key_eq() == Comp ()); + assert(c.get_allocator() == a); + 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_hash> HF; + typedef test_compare> Comp; + typedef test_allocator A; + typedef std::unordered_multiset C; + + HF hf(42); + A a(43); + C c(4, hf, a); + assert(c.bucket_count() == 4); + 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())); + 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.multiset/unord.multiset.cnstr/init.pass.cpp b/test/containers/unord/unord.multiset/unord.multiset.cnstr/init.pass.cpp index 29729b5a..3578d35e 100644 --- a/test/containers/unord/unord.multiset/unord.multiset.cnstr/init.pass.cpp +++ b/test/containers/unord/unord.multiset/unord.multiset.cnstr/init.pass.cpp @@ -88,6 +88,76 @@ 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 int T; + typedef test_hash> HF; + typedef test_compare> Comp; + typedef test_allocator A; + typedef std::unordered_multiset C; + + A a(42); + C c({ + T(1), + T(2), + T(3), + T(4), + T(1), + T(2) + }, 12, a); + + assert(c.bucket_count() >= 12); + assert(c.size() == 6); + assert(c.count(1) == 2); + assert(c.count(2) == 2); + assert(c.count(3) == 1); + assert(c.count(4) == 1); + assert(c.hash_function() == HF()); + assert(c.key_eq() == Comp()); + assert(c.get_allocator() == a); + 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 int T; + typedef test_hash> HF; + typedef test_compare> Comp; + typedef test_allocator A; + typedef std::unordered_multiset C; + + A a(42); + HF hf(43); + C c({ + T(1), + T(2), + T(3), + T(4), + T(1), + T(2) + }, 12, hf, a); + + assert(c.bucket_count() >= 12); + assert(c.size() == 6); + assert(c.count(1) == 2); + assert(c.count(2) == 2); + assert(c.count(3) == 1); + assert(c.count(4) == 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())); + 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.multiset/unord.multiset.cnstr/range.pass.cpp b/test/containers/unord/unord.multiset/unord.multiset.cnstr/range.pass.cpp index 8c0828ae..1286eeef 100644 --- a/test/containers/unord/unord.multiset/unord.multiset.cnstr/range.pass.cpp +++ b/test/containers/unord/unord.multiset/unord.multiset.cnstr/range.pass.cpp @@ -93,5 +93,75 @@ 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 int T; + typedef test_hash> HF; + typedef test_compare> Comp; + typedef test_allocator A; + typedef std::unordered_multiset C; + T arr[] = + { + T(1), + T(2), + T(3), + T(4), + T(1), + T(2) + }; + A a(42); + C c(input_iterator(arr), input_iterator(arr + sizeof(arr)/sizeof(arr[0])), 12, a); + assert(c.bucket_count() >= 12); + assert(c.size() == 6); + assert(c.count(1) == 2); + assert(c.count(2) == 2); + assert(c.count(3) == 1); + assert(c.count(4) == 1); + assert(c.hash_function() == HF()); + assert(c.key_eq() == Comp()); + assert(c.get_allocator() == a); + 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 int T; + typedef test_hash> HF; + typedef test_compare> Comp; + typedef test_allocator A; + typedef std::unordered_multiset C; + T arr[] = + { + T(1), + T(2), + T(3), + T(4), + T(1), + T(2) + }; + HF hf(43); + A a(42); + C c(input_iterator(arr), input_iterator(arr + sizeof(arr)/sizeof(arr[0])), 16, hf, a); + assert(c.bucket_count() >= 16); + assert(c.size() == 6); + assert(c.count(1) == 2); + assert(c.count(2) == 2); + assert(c.count(3) == 1); + assert(c.count(4) == 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())); + 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.set/unord.set.cnstr/allocator.pass.cpp b/test/containers/unord/unord.set/unord.set.cnstr/allocator.pass.cpp index 31878362..5d7897b9 100644 --- a/test/containers/unord/unord.set/unord.set.cnstr/allocator.pass.cpp +++ b/test/containers/unord/unord.set/unord.set.cnstr/allocator.pass.cpp @@ -61,5 +61,49 @@ int main() assert(c.load_factor() == 0); assert(c.max_load_factor() == 1); } +#if _LIBCPP_STD_VER > 11 + { + typedef NotConstructible T; + typedef test_hash> HF; + typedef test_compare> Comp; + typedef test_allocator A; + typedef std::unordered_set C; + + A a(43); + C c(3, a); + assert(c.bucket_count() == 3); + assert(c.hash_function() == HF()); + assert(c.key_eq() == Comp ()); + assert(c.get_allocator() == a); + 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_hash> HF; + typedef test_compare> Comp; + typedef test_allocator A; + typedef std::unordered_set C; + + HF hf(42); + A a(43); + C c(4, hf, a); + assert(c.bucket_count() == 4); + 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())); + 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.set/unord.set.cnstr/init.pass.cpp b/test/containers/unord/unord.set/unord.set.cnstr/init.pass.cpp index 8dc37e30..fcee4007 100644 --- a/test/containers/unord/unord.set/unord.set.cnstr/init.pass.cpp +++ b/test/containers/unord/unord.set/unord.set.cnstr/init.pass.cpp @@ -88,6 +88,76 @@ 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 int T; + typedef test_hash> HF; + typedef test_compare> Comp; + typedef test_allocator A; + typedef std::unordered_set C; + + A a(42); + C c({ + T(1), + T(2), + T(3), + T(4), + T(1), + T(2) + }, 12, a); + + assert(c.bucket_count() >= 12); + assert(c.size() == 4); + assert(c.count(1) == 1); + assert(c.count(2) == 1); + assert(c.count(3) == 1); + assert(c.count(4) == 1); + assert(c.hash_function() == HF()); + assert(c.key_eq() == Comp()); + assert(c.get_allocator() == a); + 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 int T; + typedef test_hash> HF; + typedef test_compare> Comp; + typedef test_allocator A; + typedef std::unordered_set C; + + A a(42); + HF hf(43); + C c({ + T(1), + T(2), + T(3), + T(4), + T(1), + T(2) + }, 12, hf, a); + + assert(c.bucket_count() >= 12); + assert(c.size() == 4); + assert(c.count(1) == 1); + assert(c.count(2) == 1); + assert(c.count(3) == 1); + assert(c.count(4) == 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())); + 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.set/unord.set.cnstr/range.pass.cpp b/test/containers/unord/unord.set/unord.set.cnstr/range.pass.cpp index 322fa3ff..d0166fab 100644 --- a/test/containers/unord/unord.set/unord.set.cnstr/range.pass.cpp +++ b/test/containers/unord/unord.set/unord.set.cnstr/range.pass.cpp @@ -93,5 +93,76 @@ 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 int T; + typedef test_hash> HF; + typedef test_compare> Comp; + typedef test_allocator A; + typedef std::unordered_set C; + T arr[] = + { + T(1), + T(2), + T(3), + T(4), + T(1), + T(2) + }; + A a(42); + C c(input_iterator(arr), input_iterator(arr + sizeof(arr)/sizeof(arr[0])), 12, a); + assert(c.bucket_count() >= 12); + assert(c.size() == 4); + assert(c.count(1) == 1); + assert(c.count(2) == 1); + assert(c.count(3) == 1); + assert(c.count(4) == 1); + assert(c.hash_function() == HF()); + assert(c.key_eq() == Comp()); + assert(c.get_allocator() == a); + 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 int T; + typedef test_hash> HF; + typedef test_compare> Comp; + typedef test_allocator A; + typedef std::unordered_set C; + T arr[] = + { + T(1), + T(2), + T(3), + T(4), + T(1), + T(2) + }; + HF hf(43); + A a(42); + C c(input_iterator(arr), input_iterator(arr + sizeof(arr)/sizeof(arr[0])), 16, hf, a); + assert(c.bucket_count() >= 16); + assert(c.size() == 4); + assert(c.count(1) == 1); + assert(c.count(2) == 1); + assert(c.count(3) == 1); + assert(c.count(4) == 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())); + 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 }