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
This commit is contained in:
parent
599e60d2f7
commit
6dff618d7d
@ -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)
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user