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
This commit is contained in:
Marshall Clow 2013-09-30 21:33:51 +00:00
parent ff7546e974
commit bd444af850
7 changed files with 446 additions and 0 deletions

View File

@ -68,6 +68,16 @@ public:
unordered_set(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_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 <class InputIterator>
unordered_set(InputIterator f, InputIterator l, size_type n, const allocator_type& a); // C++14
template <class InputIterator>
unordered_set(InputIterator f, InputIterator l, size_type n,
const hasher& hf, const allocator_type& a); // C++14
unordered_set(initializer_list<value_type> il, size_type n, const allocator_type& a); // C++14
unordered_set(initializer_list<value_type> 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<value_type>, 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 <class InputIterator>
unordered_multiset(InputIterator f, InputIterator l, size_type n, const allocator_type& a); // C++14
template <class InputIterator>
unordered_multiset(InputIterator f, InputIterator l, size_type n,
const hasher& hf, const allocator_type& a); // C++14
unordered_multiset(initializer_list<value_type> il, size_type n, const allocator_type& a); // C++14
unordered_multiset(initializer_list<value_type> 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 <class _InputIterator>
@ -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 <class _InputIterator>
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 <class _InputIterator>
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<value_type> __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<value_type> __il, size_type __n,
const allocator_type& __a)
: unordered_set(__il, __n, hasher(), key_equal(), __a) {}
inline _LIBCPP_INLINE_VISIBILITY
unordered_set(initializer_list<value_type> __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 <class _InputIterator>
unordered_multiset(_InputIterator __first, _InputIterator __last);
template <class _InputIterator>
@ -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 <class _InputIterator>
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 <class _InputIterator>
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<value_type> __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<value_type> __il, size_type __n, const allocator_type& __a)
: unordered_multiset(__il, __n, hasher(), key_equal(), __a) {}
inline _LIBCPP_INLINE_VISIBILITY
unordered_multiset(initializer_list<value_type> __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

View File

@ -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<std::hash<T>> HF;
typedef test_compare<std::equal_to<T>> Comp;
typedef test_allocator<T> A;
typedef std::unordered_multiset<T, HF, Comp, A> 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<std::hash<T>> HF;
typedef test_compare<std::equal_to<T>> Comp;
typedef test_allocator<T> A;
typedef std::unordered_multiset<T, HF, Comp, A> 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
}

View File

@ -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<std::hash<T>> HF;
typedef test_compare<std::equal_to<T>> Comp;
typedef test_allocator<T> A;
typedef std::unordered_multiset<T, HF, Comp, A> 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<std::hash<T>> HF;
typedef test_compare<std::equal_to<T>> Comp;
typedef test_allocator<T> A;
typedef std::unordered_multiset<T, HF, Comp, A> 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
}

View File

@ -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<std::hash<T>> HF;
typedef test_compare<std::equal_to<T>> Comp;
typedef test_allocator<T> A;
typedef std::unordered_multiset<T, HF, Comp, A> C;
T arr[] =
{
T(1),
T(2),
T(3),
T(4),
T(1),
T(2)
};
A a(42);
C c(input_iterator<T*>(arr), input_iterator<T*>(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<std::hash<T>> HF;
typedef test_compare<std::equal_to<T>> Comp;
typedef test_allocator<T> A;
typedef std::unordered_multiset<T, HF, Comp, A> 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<T*>(arr), input_iterator<T*>(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
}

View File

@ -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<std::hash<T>> HF;
typedef test_compare<std::equal_to<T>> Comp;
typedef test_allocator<T> A;
typedef std::unordered_set<T, HF, Comp, A> 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<std::hash<T>> HF;
typedef test_compare<std::equal_to<T>> Comp;
typedef test_allocator<T> A;
typedef std::unordered_set<T, HF, Comp, A> 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
}

View File

@ -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<std::hash<T>> HF;
typedef test_compare<std::equal_to<T>> Comp;
typedef test_allocator<T> A;
typedef std::unordered_set<T, HF, Comp, A> 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<std::hash<T>> HF;
typedef test_compare<std::equal_to<T>> Comp;
typedef test_allocator<T> A;
typedef std::unordered_set<T, HF, Comp, A> 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
}

View File

@ -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<std::hash<T>> HF;
typedef test_compare<std::equal_to<T>> Comp;
typedef test_allocator<T> A;
typedef std::unordered_set<T, HF, Comp, A> C;
T arr[] =
{
T(1),
T(2),
T(3),
T(4),
T(1),
T(2)
};
A a(42);
C c(input_iterator<T*>(arr), input_iterator<T*>(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<std::hash<T>> HF;
typedef test_compare<std::equal_to<T>> Comp;
typedef test_allocator<T> A;
typedef std::unordered_set<T, HF, Comp, A> 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<T*>(arr), input_iterator<T*>(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
}