diff options
Diffstat (limited to 'test/std/containers/unord/unord.multiset')
75 files changed, 8464 insertions, 0 deletions
diff --git a/test/std/containers/unord/unord.multiset/bucket.pass.cpp b/test/std/containers/unord/unord.multiset/bucket.pass.cpp new file mode 100644 index 000000000000..0293133d494a --- /dev/null +++ b/test/std/containers/unord/unord.multiset/bucket.pass.cpp @@ -0,0 +1,76 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <unordered_set> + +// template <class Value, class Hash = hash<Value>, class Pred = equal_to<Value>, +// class Alloc = allocator<Value>> +// class unordered_multiset + +// size_type bucket(const key_type& __k) const; + +#ifdef _LIBCPP_DEBUG +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) +#endif + +#include <unordered_set> +#include <cassert> + +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_multiset<int> C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + const C c(std::begin(a), std::end(a)); + size_t bc = c.bucket_count(); + assert(bc >= 7); + for (size_t i = 0; i < 13; ++i) + assert(c.bucket(i) == i % bc); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multiset<int, std::hash<int>, + std::equal_to<int>, min_allocator<int>> C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + const C c(std::begin(a), std::end(a)); + size_t bc = c.bucket_count(); + assert(bc >= 7); + for (size_t i = 0; i < 13; ++i) + assert(c.bucket(i) == i % bc); + } +#endif +#if _LIBCPP_DEBUG_LEVEL >= 1 + { + typedef std::unordered_multiset<int> C; + C c; + C::size_type i = c.bucket(3); + assert(false); + } +#endif +} diff --git a/test/std/containers/unord/unord.multiset/bucket_count.pass.cpp b/test/std/containers/unord/unord.multiset/bucket_count.pass.cpp new file mode 100644 index 000000000000..c7842e5c1977 --- /dev/null +++ b/test/std/containers/unord/unord.multiset/bucket_count.pass.cpp @@ -0,0 +1,79 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <unordered_set> + +// template <class Value, class Hash = hash<Value>, class Pred = equal_to<Value>, +// class Alloc = allocator<Value>> +// class unordered_multiset + +// size_type bucket_count() const; + +#include <unordered_set> +#include <cassert> + +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_multiset<int> C; + typedef C::const_iterator I; + typedef int P; + const C c; + assert(c.bucket_count() == 0); + } + { + typedef std::unordered_multiset<int> C; + typedef C::const_iterator I; + typedef int P; + P a[] = + { + P(10), + P(20), + P(30), + P(40), + P(50), + P(60), + P(70), + P(80) + }; + const C c(std::begin(a), std::end(a)); + assert(c.bucket_count() >= 11); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multiset<int, std::hash<int>, + std::equal_to<int>, min_allocator<int>> C; + typedef C::const_iterator I; + typedef int P; + const C c; + assert(c.bucket_count() == 0); + } + { + typedef std::unordered_multiset<int, std::hash<int>, + std::equal_to<int>, min_allocator<int>> C; + typedef C::const_iterator I; + typedef int P; + P a[] = + { + P(10), + P(20), + P(30), + P(40), + P(50), + P(60), + P(70), + P(80) + }; + const C c(std::begin(a), std::end(a)); + assert(c.bucket_count() >= 11); + } +#endif +} diff --git a/test/std/containers/unord/unord.multiset/bucket_size.pass.cpp b/test/std/containers/unord/unord.multiset/bucket_size.pass.cpp new file mode 100644 index 000000000000..639d7ac37965 --- /dev/null +++ b/test/std/containers/unord/unord.multiset/bucket_size.pass.cpp @@ -0,0 +1,84 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <unordered_set> + +// template <class Value, class Hash = hash<Value>, class Pred = equal_to<Value>, +// class Alloc = allocator<Value>> +// class unordered_multiset + +// size_type bucket_size(size_type n) const + +#ifdef _LIBCPP_DEBUG +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) +#endif + +#include <unordered_set> +#include <cassert> + +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_multiset<int> C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + const C c(std::begin(a), std::end(a)); + assert(c.bucket_count() >= 7); + assert(c.bucket_size(0) == 0); + assert(c.bucket_size(1) == 2); + assert(c.bucket_size(2) == 2); + assert(c.bucket_size(3) == 1); + assert(c.bucket_size(4) == 1); + assert(c.bucket_size(5) == 0); + assert(c.bucket_size(6) == 0); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multiset<int, std::hash<int>, + std::equal_to<int>, min_allocator<int>> C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + const C c(std::begin(a), std::end(a)); + assert(c.bucket_count() >= 7); + assert(c.bucket_size(0) == 0); + assert(c.bucket_size(1) == 2); + assert(c.bucket_size(2) == 2); + assert(c.bucket_size(3) == 1); + assert(c.bucket_size(4) == 1); + assert(c.bucket_size(5) == 0); + assert(c.bucket_size(6) == 0); + } +#endif +#if _LIBCPP_DEBUG_LEVEL >= 1 + { + typedef std::unordered_multiset<int> C; + C c; + C::size_type i = c.bucket_size(3); + assert(false); + } +#endif +} diff --git a/test/std/containers/unord/unord.multiset/clear.pass.cpp b/test/std/containers/unord/unord.multiset/clear.pass.cpp new file mode 100644 index 000000000000..61ca847e7c4a --- /dev/null +++ b/test/std/containers/unord/unord.multiset/clear.pass.cpp @@ -0,0 +1,60 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <unordered_set> + +// template <class Value, class Hash = hash<Value>, class Pred = equal_to<Value>, +// class Alloc = allocator<Value>> +// class unordered_multiset + +// void clear() + +#include <unordered_set> +#include <cassert> + +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_multiset<int> C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c(a, a + sizeof(a)/sizeof(a[0])); + c.clear(); + assert(c.size() == 0); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multiset<int, std::hash<int>, + std::equal_to<int>, min_allocator<int>> C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c(a, a + sizeof(a)/sizeof(a[0])); + c.clear(); + assert(c.size() == 0); + } +#endif +} diff --git a/test/std/containers/unord/unord.multiset/count.pass.cpp b/test/std/containers/unord/unord.multiset/count.pass.cpp new file mode 100644 index 000000000000..e548324d9545 --- /dev/null +++ b/test/std/containers/unord/unord.multiset/count.pass.cpp @@ -0,0 +1,70 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <unordered_set> + +// template <class Value, class Hash = hash<Value>, class Pred = equal_to<Value>, +// class Alloc = allocator<Value>> +// class unordered_multiset + +// size_type count(const key_type& k) const; + +#include <unordered_set> +#include <cassert> + +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_multiset<int> C; + typedef int P; + P a[] = + { + P(10), + P(20), + P(30), + P(40), + P(50), + P(50), + P(50), + P(60), + P(70), + P(80) + }; + const C c(std::begin(a), std::end(a)); + assert(c.count(30) == 1); + assert(c.count(50) == 3); + assert(c.count(5) == 0); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multiset<int, std::hash<int>, + std::equal_to<int>, min_allocator<int>> C; + typedef int P; + P a[] = + { + P(10), + P(20), + P(30), + P(40), + P(50), + P(50), + P(50), + P(60), + P(70), + P(80) + }; + const C c(std::begin(a), std::end(a)); + assert(c.count(30) == 1); + assert(c.count(50) == 3); + assert(c.count(5) == 0); + } +#endif +} diff --git a/test/std/containers/unord/unord.multiset/db_iterators_7.pass.cpp b/test/std/containers/unord/unord.multiset/db_iterators_7.pass.cpp new file mode 100644 index 000000000000..c8ef2fbca163 --- /dev/null +++ b/test/std/containers/unord/unord.multiset/db_iterators_7.pass.cpp @@ -0,0 +1,58 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <unordered_set> + +// Increment iterator past end. + +#if _LIBCPP_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include <unordered_set> +#include <cassert> +#include <iterator> +#include <exception> +#include <cstdlib> + +#include "min_allocator.h" + +int main() +{ + { + typedef int T; + typedef std::unordered_multiset<T> C; + C c(1); + C::iterator i = c.begin(); + ++i; + assert(i == c.end()); + ++i; + assert(false); + } +#if __cplusplus >= 201103L + { + typedef int T; + typedef std::unordered_multiset<T, min_allocator<T>> C; + C c(1); + C::iterator i = c.begin(); + ++i; + assert(i == c.end()); + ++i; + assert(false); + } +#endif +} + +#else + +int main() +{ +} + +#endif diff --git a/test/std/containers/unord/unord.multiset/db_iterators_8.pass.cpp b/test/std/containers/unord/unord.multiset/db_iterators_8.pass.cpp new file mode 100644 index 000000000000..eef799787947 --- /dev/null +++ b/test/std/containers/unord/unord.multiset/db_iterators_8.pass.cpp @@ -0,0 +1,54 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <unordered_set> + +// Dereference non-dereferenceable iterator. + +#if _LIBCPP_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include <unordered_set> +#include <cassert> +#include <iterator> +#include <exception> +#include <cstdlib> + +#include "min_allocator.h" + +int main() +{ + { + typedef int T; + typedef std::unordered_multiset<T> C; + C c(1); + C::iterator i = c.end(); + T j = *i; + assert(false); + } +#if __cplusplus >= 201103L + { + typedef int T; + typedef std::unordered_multiset<T, min_allocator<T>> C; + C c(1); + C::iterator i = c.end(); + T j = *i; + assert(false); + } +#endif +} + +#else + +int main() +{ +} + +#endif diff --git a/test/std/containers/unord/unord.multiset/db_local_iterators_7.pass.cpp b/test/std/containers/unord/unord.multiset/db_local_iterators_7.pass.cpp new file mode 100644 index 000000000000..c1de95cace71 --- /dev/null +++ b/test/std/containers/unord/unord.multiset/db_local_iterators_7.pass.cpp @@ -0,0 +1,57 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <unordered_set> + +// Increment local_iterator past end. + +#if _LIBCPP_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include <unordered_set> +#include <cassert> +#include <iterator> +#include <exception> +#include <cstdlib> + +#include "min_allocator.h" + +int main() +{ + { + typedef int T; + typedef std::unordered_multiset<T> C; + C c(1); + C::local_iterator i = c.begin(0); + ++i; + ++i; + assert(false); + } +#if __cplusplus >= 201103L + { + typedef int T; + typedef std::unordered_multiset<T, min_allocator<T>> C; + C c(1); + C::local_iterator i = c.begin(0); + ++i; + ++i; + assert(false); + } +#endif + +} + +#else + +int main() +{ +} + +#endif diff --git a/test/std/containers/unord/unord.multiset/db_local_iterators_8.pass.cpp b/test/std/containers/unord/unord.multiset/db_local_iterators_8.pass.cpp new file mode 100644 index 000000000000..962b85298ae1 --- /dev/null +++ b/test/std/containers/unord/unord.multiset/db_local_iterators_8.pass.cpp @@ -0,0 +1,54 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <unordered_set> + +// Dereference non-dereferenceable iterator. + +#if _LIBCPP_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include <unordered_set> +#include <cassert> +#include <iterator> +#include <exception> +#include <cstdlib> + +#include "min_allocator.h" + +int main() +{ + { + typedef int T; + typedef std::unordered_multiset<T> C; + C c(1); + C::local_iterator i = c.end(0); + T j = *i; + assert(false); + } +#if __cplusplus >= 201103L + { + typedef int T; + typedef std::unordered_multiset<T, min_allocator<T>> C; + C c(1); + C::local_iterator i = c.end(0); + T j = *i; + assert(false); + } +#endif +} + +#else + +int main() +{ +} + +#endif diff --git a/test/std/containers/unord/unord.multiset/emplace.pass.cpp b/test/std/containers/unord/unord.multiset/emplace.pass.cpp new file mode 100644 index 000000000000..13787d9b4037 --- /dev/null +++ b/test/std/containers/unord/unord.multiset/emplace.pass.cpp @@ -0,0 +1,64 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <unordered_set> + +// template <class Value, class Hash = hash<Value>, class Pred = equal_to<Value>, +// class Alloc = allocator<Value>> +// class unordered_multiset + +// template <class... Args> +// iterator emplace(Args&&... args); + +#include <unordered_set> +#include <cassert> + +#include "../../Emplaceable.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + typedef std::unordered_multiset<Emplaceable> C; + typedef C::iterator R; + C c; + R r = c.emplace(); + assert(c.size() == 1); + assert(*r == Emplaceable()); + + r = c.emplace(Emplaceable(5, 6)); + assert(c.size() == 2); + assert(*r == Emplaceable(5, 6)); + + r = c.emplace(5, 6); + assert(c.size() == 3); + assert(*r == Emplaceable(5, 6)); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multiset<Emplaceable, std::hash<Emplaceable>, + std::equal_to<Emplaceable>, min_allocator<Emplaceable>> C; + typedef C::iterator R; + C c; + R r = c.emplace(); + assert(c.size() == 1); + assert(*r == Emplaceable()); + + r = c.emplace(Emplaceable(5, 6)); + assert(c.size() == 2); + assert(*r == Emplaceable(5, 6)); + + r = c.emplace(5, 6); + assert(c.size() == 3); + assert(*r == Emplaceable(5, 6)); + } +#endif +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/test/std/containers/unord/unord.multiset/emplace_hint.pass.cpp b/test/std/containers/unord/unord.multiset/emplace_hint.pass.cpp new file mode 100644 index 000000000000..8885cc03cf03 --- /dev/null +++ b/test/std/containers/unord/unord.multiset/emplace_hint.pass.cpp @@ -0,0 +1,80 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <unordered_set> + +// template <class Value, class Hash = hash<Value>, class Pred = equal_to<Value>, +// class Alloc = allocator<Value>> +// class unordered_multiset + +// template <class... Args> +// iterator emplace_hint(const_iterator p, Args&&... args); + +#if _LIBCPP_DEBUG >= 1 +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) +#endif + +#include <unordered_set> +#include <cassert> + +#include "../../Emplaceable.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + typedef std::unordered_multiset<Emplaceable> C; + typedef C::iterator R; + C c; + C::const_iterator e = c.end(); + R r = c.emplace_hint(e); + assert(c.size() == 1); + assert(*r == Emplaceable()); + + r = c.emplace_hint(c.end(), Emplaceable(5, 6)); + assert(c.size() == 2); + assert(*r == Emplaceable(5, 6)); + + r = c.emplace_hint(r, 5, 6); + assert(c.size() == 3); + assert(*r == Emplaceable(5, 6)); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multiset<Emplaceable, std::hash<Emplaceable>, + std::equal_to<Emplaceable>, min_allocator<Emplaceable>> C; + typedef C::iterator R; + C c; + C::const_iterator e = c.end(); + R r = c.emplace_hint(e); + assert(c.size() == 1); + assert(*r == Emplaceable()); + + r = c.emplace_hint(c.end(), Emplaceable(5, 6)); + assert(c.size() == 2); + assert(*r == Emplaceable(5, 6)); + + r = c.emplace_hint(r, 5, 6); + assert(c.size() == 3); + assert(*r == Emplaceable(5, 6)); + } +#endif +#if _LIBCPP_DEBUG >= 1 + { + typedef std::unordered_multiset<Emplaceable> C; + typedef C::iterator R; + C c1; + C c2; + R r = c1.emplace_hint(c2.begin(), 5, 6); + assert(false); + } +#endif +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/test/std/containers/unord/unord.multiset/eq.pass.cpp b/test/std/containers/unord/unord.multiset/eq.pass.cpp new file mode 100644 index 000000000000..bbedbc905a4b --- /dev/null +++ b/test/std/containers/unord/unord.multiset/eq.pass.cpp @@ -0,0 +1,180 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <unordered_set> + +// template <class Key, class Hash, class Pred, class Alloc> +// bool +// operator==(const unordered_multiset<Key, Hash, Pred, Alloc>& x, +// const unordered_multiset<Key, Hash, Pred, Alloc>& y); +// +// template <class Key, class Hash, class Pred, class Alloc> +// bool +// operator!=(const unordered_multiset<Key, Hash, Pred, Alloc>& x, +// const unordered_multiset<Key, Hash, Pred, Alloc>& y); + +#include <unordered_set> +#include <cassert> + +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_multiset<int> C; + typedef int P; + P a[] = + { + P(10), + P(20), + P(20), + P(30), + P(40), + P(50), + P(50), + P(50), + P(60), + P(70), + P(80) + }; + const C c1(std::begin(a), std::end(a)); + const C c2; + assert(!(c1 == c2)); + assert( (c1 != c2)); + } + { + typedef std::unordered_multiset<int> C; + typedef int P; + P a[] = + { + P(10), + P(20), + P(20), + P(30), + P(40), + P(50), + P(50), + P(50), + P(60), + P(70), + P(80) + }; + const C c1(std::begin(a), std::end(a)); + const C c2 = c1; + assert( (c1 == c2)); + assert(!(c1 != c2)); + } + { + typedef std::unordered_multiset<int> C; + typedef int P; + P a[] = + { + P(10), + P(20), + P(20), + P(30), + P(40), + P(50), + P(50), + P(50), + P(60), + P(70), + P(80) + }; + C c1(std::begin(a), std::end(a)); + C c2 = c1; + c2.rehash(30); + assert( (c1 == c2)); + assert(!(c1 != c2)); + c2.insert(P(90)); + assert(!(c1 == c2)); + assert( (c1 != c2)); + c1.insert(P(90)); + assert( (c1 == c2)); + assert(!(c1 != c2)); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multiset<int, std::hash<int>, + std::equal_to<int>, min_allocator<int>> C; + typedef int P; + P a[] = + { + P(10), + P(20), + P(20), + P(30), + P(40), + P(50), + P(50), + P(50), + P(60), + P(70), + P(80) + }; + const C c1(std::begin(a), std::end(a)); + const C c2; + assert(!(c1 == c2)); + assert( (c1 != c2)); + } + { + typedef std::unordered_multiset<int, std::hash<int>, + std::equal_to<int>, min_allocator<int>> C; + typedef int P; + P a[] = + { + P(10), + P(20), + P(20), + P(30), + P(40), + P(50), + P(50), + P(50), + P(60), + P(70), + P(80) + }; + const C c1(std::begin(a), std::end(a)); + const C c2 = c1; + assert( (c1 == c2)); + assert(!(c1 != c2)); + } + { + typedef std::unordered_multiset<int, std::hash<int>, + std::equal_to<int>, min_allocator<int>> C; + typedef int P; + P a[] = + { + P(10), + P(20), + P(20), + P(30), + P(40), + P(50), + P(50), + P(50), + P(60), + P(70), + P(80) + }; + C c1(std::begin(a), std::end(a)); + C c2 = c1; + c2.rehash(30); + assert( (c1 == c2)); + assert(!(c1 != c2)); + c2.insert(P(90)); + assert(!(c1 == c2)); + assert( (c1 != c2)); + c1.insert(P(90)); + assert( (c1 == c2)); + assert(!(c1 != c2)); + } +#endif +} diff --git a/test/std/containers/unord/unord.multiset/equal_range_const.pass.cpp b/test/std/containers/unord/unord.multiset/equal_range_const.pass.cpp new file mode 100644 index 000000000000..a0aaac2bd868 --- /dev/null +++ b/test/std/containers/unord/unord.multiset/equal_range_const.pass.cpp @@ -0,0 +1,90 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <unordered_set> + +// template <class Value, class Hash = hash<Value>, class Pred = equal_to<Value>, +// class Alloc = allocator<Value>> +// class unordered_multiset + +// pair<const_iterator, const_iterator> equal_range(const key_type& k) const; + +#include <unordered_set> +#include <cassert> + +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_multiset<int> C; + typedef C::const_iterator I; + typedef int P; + P a[] = + { + P(10), + P(20), + P(30), + P(40), + P(50), + P(50), + P(50), + P(60), + P(70), + P(80) + }; + const C c(std::begin(a), std::end(a)); + std::pair<I, I> r = c.equal_range(30); + assert(std::distance(r.first, r.second) == 1); + assert(*r.first == 30); + r = c.equal_range(5); + assert(std::distance(r.first, r.second) == 0); + r = c.equal_range(50); + assert(std::distance(r.first, r.second) == 3); + assert(*r.first == 50); + ++r.first; + assert(*r.first == 50); + ++r.first; + assert(*r.first == 50); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multiset<int, std::hash<int>, + std::equal_to<int>, min_allocator<int>> C; + typedef C::const_iterator I; + typedef int P; + P a[] = + { + P(10), + P(20), + P(30), + P(40), + P(50), + P(50), + P(50), + P(60), + P(70), + P(80) + }; + const C c(std::begin(a), std::end(a)); + std::pair<I, I> r = c.equal_range(30); + assert(std::distance(r.first, r.second) == 1); + assert(*r.first == 30); + r = c.equal_range(5); + assert(std::distance(r.first, r.second) == 0); + r = c.equal_range(50); + assert(std::distance(r.first, r.second) == 3); + assert(*r.first == 50); + ++r.first; + assert(*r.first == 50); + ++r.first; + assert(*r.first == 50); + } +#endif +} diff --git a/test/std/containers/unord/unord.multiset/equal_range_non_const.pass.cpp b/test/std/containers/unord/unord.multiset/equal_range_non_const.pass.cpp new file mode 100644 index 000000000000..73d44f7a56b7 --- /dev/null +++ b/test/std/containers/unord/unord.multiset/equal_range_non_const.pass.cpp @@ -0,0 +1,90 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <unordered_set> + +// template <class Value, class Hash = hash<Value>, class Pred = equal_to<Value>, +// class Alloc = allocator<Value>> +// class unordered_multiset + +// pair<iterator, iterator> equal_range(const key_type& k); + +#include <unordered_set> +#include <cassert> + +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_multiset<int> C; + typedef C::iterator I; + typedef int P; + P a[] = + { + P(10), + P(20), + P(30), + P(40), + P(50), + P(50), + P(50), + P(60), + P(70), + P(80) + }; + C c(std::begin(a), std::end(a)); + std::pair<I, I> r = c.equal_range(30); + assert(std::distance(r.first, r.second) == 1); + assert(*r.first == 30); + r = c.equal_range(5); + assert(std::distance(r.first, r.second) == 0); + r = c.equal_range(50); + assert(std::distance(r.first, r.second) == 3); + assert(*r.first == 50); + ++r.first; + assert(*r.first == 50); + ++r.first; + assert(*r.first == 50); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multiset<int, std::hash<int>, + std::equal_to<int>, min_allocator<int>> C; + typedef C::iterator I; + typedef int P; + P a[] = + { + P(10), + P(20), + P(30), + P(40), + P(50), + P(50), + P(50), + P(60), + P(70), + P(80) + }; + C c(std::begin(a), std::end(a)); + std::pair<I, I> r = c.equal_range(30); + assert(std::distance(r.first, r.second) == 1); + assert(*r.first == 30); + r = c.equal_range(5); + assert(std::distance(r.first, r.second) == 0); + r = c.equal_range(50); + assert(std::distance(r.first, r.second) == 3); + assert(*r.first == 50); + ++r.first; + assert(*r.first == 50); + ++r.first; + assert(*r.first == 50); + } +#endif +} diff --git a/test/std/containers/unord/unord.multiset/erase_const_iter.pass.cpp b/test/std/containers/unord/unord.multiset/erase_const_iter.pass.cpp new file mode 100644 index 000000000000..d3be2b6d6365 --- /dev/null +++ b/test/std/containers/unord/unord.multiset/erase_const_iter.pass.cpp @@ -0,0 +1,93 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <unordered_set> + +// template <class Value, class Hash = hash<Value>, class Pred = equal_to<Value>, +// class Alloc = allocator<Value>> +// class unordered_multiset + +// iterator erase(const_iterator p) + +#include <unordered_set> +#include <cassert> + +#include "min_allocator.h" + +struct TemplateConstructor +{ + template<typename T> + TemplateConstructor (const T&) {} +}; + +bool operator==(const TemplateConstructor&, const TemplateConstructor&) { return false; } +struct Hash { size_t operator() (const TemplateConstructor &) const { return 0; } }; + +int main() +{ + { + typedef std::unordered_multiset<int> C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c(a, a + sizeof(a)/sizeof(a[0])); + C::const_iterator i = c.find(2); + C::iterator j = c.erase(i); + assert(c.size() == 5); + assert(c.count(1) == 2); + assert(c.count(2) == 1); + assert(c.count(3) == 1); + assert(c.count(4) == 1); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multiset<int, std::hash<int>, + std::equal_to<int>, min_allocator<int>> C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c(a, a + sizeof(a)/sizeof(a[0])); + C::const_iterator i = c.find(2); + C::iterator j = c.erase(i); + assert(c.size() == 5); + assert(c.count(1) == 2); + assert(c.count(2) == 1); + assert(c.count(3) == 1); + assert(c.count(4) == 1); + } +#endif +#if __cplusplus >= 201402L + { + // This is LWG #2059 + typedef TemplateConstructor T; + typedef std::unordered_set<T, Hash> C; + typedef C::iterator I; + + C m; + T a{0}; + I it = m.find(a); + if (it != m.end()) + m.erase(it); + } +#endif +} diff --git a/test/std/containers/unord/unord.multiset/erase_iter_db1.pass.cpp b/test/std/containers/unord/unord.multiset/erase_iter_db1.pass.cpp new file mode 100644 index 000000000000..baad3858bd41 --- /dev/null +++ b/test/std/containers/unord/unord.multiset/erase_iter_db1.pass.cpp @@ -0,0 +1,38 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <unordered_set> + +// Call erase(const_iterator position) with end() + +#if _LIBCPP_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include <unordered_set> +#include <cassert> + +int main() +{ + { + int a1[] = {1, 2, 3}; + std::unordered_multiset<int> l1(a1, a1+3); + std::unordered_multiset<int>::const_iterator i = l1.end(); + l1.erase(i); + assert(false); + } +} + +#else + +int main() +{ +} + +#endif diff --git a/test/std/containers/unord/unord.multiset/erase_iter_db2.pass.cpp b/test/std/containers/unord/unord.multiset/erase_iter_db2.pass.cpp new file mode 100644 index 000000000000..a21f29ef7b4a --- /dev/null +++ b/test/std/containers/unord/unord.multiset/erase_iter_db2.pass.cpp @@ -0,0 +1,41 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <unordered_set> + +// Call erase(const_iterator position) with iterator from another container + +#if _LIBCPP_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include <unordered_set> +#include <cassert> +#include <cstdlib> +#include <exception> + +int main() +{ + { + int a1[] = {1, 2, 3}; + std::unordered_multiset<int> l1(a1, a1+3); + std::unordered_multiset<int> l2(a1, a1+3); + std::unordered_multiset<int>::const_iterator i = l2.begin(); + l1.erase(i); + assert(false); + } +} + +#else + +int main() +{ +} + +#endif diff --git a/test/std/containers/unord/unord.multiset/erase_iter_iter_db1.pass.cpp b/test/std/containers/unord/unord.multiset/erase_iter_iter_db1.pass.cpp new file mode 100644 index 000000000000..03c9ec5d048d --- /dev/null +++ b/test/std/containers/unord/unord.multiset/erase_iter_iter_db1.pass.cpp @@ -0,0 +1,40 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <unordered_set> + +// Call erase(const_iterator first, const_iterator last); with first iterator from another container + +#if _LIBCPP_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include <unordered_set> +#include <cassert> +#include <exception> +#include <cstdlib> + +int main() +{ + { + int a1[] = {1, 2, 3}; + std::unordered_multiset<int> l1(a1, a1+3); + std::unordered_multiset<int> l2(a1, a1+3); + std::unordered_multiset<int>::iterator i = l1.erase(l2.cbegin(), next(l1.cbegin())); + assert(false); + } +} + +#else + +int main() +{ +} + +#endif diff --git a/test/std/containers/unord/unord.multiset/erase_iter_iter_db2.pass.cpp b/test/std/containers/unord/unord.multiset/erase_iter_iter_db2.pass.cpp new file mode 100644 index 000000000000..4c6f209f1a44 --- /dev/null +++ b/test/std/containers/unord/unord.multiset/erase_iter_iter_db2.pass.cpp @@ -0,0 +1,40 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <unordered_set> + +// Call erase(const_iterator first, const_iterator last); with second iterator from another container + +#if _LIBCPP_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include <unordered_set> +#include <cassert> +#include <exception> +#include <cstdlib> + +int main() +{ + { + int a1[] = {1, 2, 3}; + std::unordered_multiset<int> l1(a1, a1+3); + std::unordered_multiset<int> l2(a1, a1+3); + std::unordered_multiset<int>::iterator i = l1.erase(l1.cbegin(), next(l2.cbegin())); + assert(false); + } +} + +#else + +int main() +{ +} + +#endif diff --git a/test/std/containers/unord/unord.multiset/erase_iter_iter_db3.pass.cpp b/test/std/containers/unord/unord.multiset/erase_iter_iter_db3.pass.cpp new file mode 100644 index 000000000000..5ce378974c90 --- /dev/null +++ b/test/std/containers/unord/unord.multiset/erase_iter_iter_db3.pass.cpp @@ -0,0 +1,40 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <unordered_set> + +// Call erase(const_iterator first, const_iterator last); with both iterators from another container + +#if _LIBCPP_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include <unordered_set> +#include <cassert> +#include <exception> +#include <cstdlib> + +int main() +{ + { + int a1[] = {1, 2, 3}; + std::unordered_multiset<int> l1(a1, a1+3); + std::unordered_multiset<int> l2(a1, a1+3); + std::unordered_multiset<int>::iterator i = l1.erase(l2.cbegin(), next(l2.cbegin())); + assert(false); + } +} + +#else + +int main() +{ +} + +#endif diff --git a/test/std/containers/unord/unord.multiset/erase_iter_iter_db4.pass.cpp b/test/std/containers/unord/unord.multiset/erase_iter_iter_db4.pass.cpp new file mode 100644 index 000000000000..7c362a2a2b1b --- /dev/null +++ b/test/std/containers/unord/unord.multiset/erase_iter_iter_db4.pass.cpp @@ -0,0 +1,39 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <unordered_set> + +// Call erase(const_iterator first, const_iterator last); with a bad range + +#if _LIBCPP_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include <unordered_set> +#include <cassert> +#include <exception> +#include <cstdlib> + +int main() +{ + { + int a1[] = {1, 2, 3}; + std::unordered_multiset<int> l1(a1, a1+3); + std::unordered_multiset<int>::iterator i = l1.erase(next(l1.cbegin()), l1.cbegin()); + assert(false); + } +} + +#else + +int main() +{ +} + +#endif diff --git a/test/std/containers/unord/unord.multiset/erase_key.pass.cpp b/test/std/containers/unord/unord.multiset/erase_key.pass.cpp new file mode 100644 index 000000000000..7c243973f163 --- /dev/null +++ b/test/std/containers/unord/unord.multiset/erase_key.pass.cpp @@ -0,0 +1,176 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <unordered_set> + +// template <class Value, class Hash = hash<Value>, class Pred = equal_to<Value>, +// class Alloc = allocator<Value>> +// class unordered_multiset + +// size_type erase(const key_type& k); + +#include <unordered_set> +#include <string> +#include <cassert> + +#include "min_allocator.h" + +#if __cplusplus >= 201103L +template <typename Unordered> +bool only_deletions ( const Unordered &whole, const Unordered &part ) { + typename Unordered::const_iterator w = whole.begin(); + typename Unordered::const_iterator p = part.begin(); + + while ( w != whole.end () && p != part.end()) { + if ( *w == *p ) + p++; + w++; + } + + return p == part.end(); +} +#endif + +int main() +{ + { + typedef std::unordered_multiset<int> C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c(a, a + sizeof(a)/sizeof(a[0])); + assert(c.erase(5) == 0); + 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.erase(2) == 2); + assert(c.size() == 4); + assert(c.count(1) == 2); + assert(c.count(3) == 1); + assert(c.count(4) == 1); + + assert(c.erase(2) == 0); + assert(c.size() == 4); + assert(c.count(1) == 2); + assert(c.count(3) == 1); + assert(c.count(4) == 1); + + assert(c.erase(4) == 1); + assert(c.size() == 3); + assert(c.count(1) == 2); + assert(c.count(3) == 1); + + assert(c.erase(4) == 0); + assert(c.size() == 3); + assert(c.count(1) == 2); + assert(c.count(3) == 1); + + assert(c.erase(1) == 2); + assert(c.size() == 1); + assert(c.count(3) == 1); + + assert(c.erase(1) == 0); + assert(c.size() == 1); + assert(c.count(3) == 1); + + assert(c.erase(3) == 1); + assert(c.size() == 0); + + assert(c.erase(3) == 0); + assert(c.size() == 0); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multiset<int, std::hash<int>, + std::equal_to<int>, min_allocator<int>> C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c(a, a + sizeof(a)/sizeof(a[0])); + assert(c.erase(5) == 0); + 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.erase(2) == 2); + assert(c.size() == 4); + assert(c.count(1) == 2); + assert(c.count(3) == 1); + assert(c.count(4) == 1); + + assert(c.erase(2) == 0); + assert(c.size() == 4); + assert(c.count(1) == 2); + assert(c.count(3) == 1); + assert(c.count(4) == 1); + + assert(c.erase(4) == 1); + assert(c.size() == 3); + assert(c.count(1) == 2); + assert(c.count(3) == 1); + + assert(c.erase(4) == 0); + assert(c.size() == 3); + assert(c.count(1) == 2); + assert(c.count(3) == 1); + + assert(c.erase(1) == 2); + assert(c.size() == 1); + assert(c.count(3) == 1); + + assert(c.erase(1) == 0); + assert(c.size() == 1); + assert(c.count(3) == 1); + + assert(c.erase(3) == 1); + assert(c.size() == 0); + + assert(c.erase(3) == 0); + assert(c.size() == 0); + } + { + typedef std::unordered_multiset<int> C; + C m, m2; + for ( int i = 0; i < 10; ++i ) { + m.insert(i); m.insert(i); + m2.insert(i); m2.insert(i); + } + + C::iterator i = m2.begin(); + int ctr = 0; + while (i != m2.end()) { + if (ctr++ % 2 == 0) + m2.erase(i++); + else + ++i; + } + + assert (only_deletions (m, m2)); + } +#endif +} diff --git a/test/std/containers/unord/unord.multiset/erase_range.pass.cpp b/test/std/containers/unord/unord.multiset/erase_range.pass.cpp new file mode 100644 index 000000000000..baac08eddc1e --- /dev/null +++ b/test/std/containers/unord/unord.multiset/erase_range.pass.cpp @@ -0,0 +1,94 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <unordered_set> + +// template <class Value, class Hash = hash<Value>, class Pred = equal_to<Value>, +// class Alloc = allocator<Value>> +// class unordered_multiset + +// iterator erase(const_iterator first, const_iterator last) + +#include <unordered_set> +#include <cassert> + +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_multiset<int> C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c(a, a + sizeof(a)/sizeof(a[0])); + C::const_iterator i = c.find(2); + C::const_iterator j = next(i, 2); + C::iterator k = c.erase(i, i); + assert(k == i); + assert(c.size() == 6); + assert(c.count(1) == 2); + assert(c.count(2) == 2); + assert(c.count(3) == 1); + assert(c.count(4) == 1); + + k = c.erase(i, j); + assert(c.size() == 4); + assert(c.count(1) == 2); + assert(c.count(3) == 1); + assert(c.count(4) == 1); + + k = c.erase(c.cbegin(), c.cend()); + assert(c.size() == 0); + assert(k == c.end()); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multiset<int, std::hash<int>, + std::equal_to<int>, min_allocator<int>> C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c(a, a + sizeof(a)/sizeof(a[0])); + C::const_iterator i = c.find(2); + C::const_iterator j = next(i, 2); + C::iterator k = c.erase(i, i); + assert(k == i); + assert(c.size() == 6); + assert(c.count(1) == 2); + assert(c.count(2) == 2); + assert(c.count(3) == 1); + assert(c.count(4) == 1); + + k = c.erase(i, j); + assert(c.size() == 4); + assert(c.count(1) == 2); + assert(c.count(3) == 1); + assert(c.count(4) == 1); + + k = c.erase(c.cbegin(), c.cend()); + assert(c.size() == 0); + assert(k == c.end()); + } +#endif +} diff --git a/test/std/containers/unord/unord.multiset/find_const.pass.cpp b/test/std/containers/unord/unord.multiset/find_const.pass.cpp new file mode 100644 index 000000000000..5caaf207aaf2 --- /dev/null +++ b/test/std/containers/unord/unord.multiset/find_const.pass.cpp @@ -0,0 +1,68 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <unordered_set> + +// template <class Value, class Hash = hash<Value>, class Pred = equal_to<Value>, +// class Alloc = allocator<Value>> +// class unordered_multiset + +// const_iterator find(const key_type& k) const; + +#include <unordered_set> +#include <cassert> + +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_multiset<int> C; + typedef int P; + P a[] = + { + P(10), + P(20), + P(30), + P(40), + P(50), + P(60), + P(70), + P(80) + }; + const C c(std::begin(a), std::end(a)); + C::const_iterator i = c.find(30); + assert(*i == 30); + i = c.find(5); + assert(i == c.cend()); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multiset<int, std::hash<int>, + std::equal_to<int>, min_allocator<int>> C; + typedef int P; + P a[] = + { + P(10), + P(20), + P(30), + P(40), + P(50), + P(60), + P(70), + P(80) + }; + const C c(std::begin(a), std::end(a)); + C::const_iterator i = c.find(30); + assert(*i == 30); + i = c.find(5); + assert(i == c.cend()); + } +#endif +} diff --git a/test/std/containers/unord/unord.multiset/find_non_const.pass.cpp b/test/std/containers/unord/unord.multiset/find_non_const.pass.cpp new file mode 100644 index 000000000000..030487863f98 --- /dev/null +++ b/test/std/containers/unord/unord.multiset/find_non_const.pass.cpp @@ -0,0 +1,68 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <unordered_set> + +// template <class Value, class Hash = hash<Value>, class Pred = equal_to<Value>, +// class Alloc = allocator<Value>> +// class unordered_multiset + +// iterator find(const key_type& k); + +#include <unordered_set> +#include <cassert> + +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_multiset<int> C; + typedef int P; + P a[] = + { + P(10), + P(20), + P(30), + P(40), + P(50), + P(60), + P(70), + P(80) + }; + C c(std::begin(a), std::end(a)); + C::iterator i = c.find(30); + assert(*i == 30); + i = c.find(5); + assert(i == c.cend()); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multiset<int, std::hash<int>, + std::equal_to<int>, min_allocator<int>> C; + typedef int P; + P a[] = + { + P(10), + P(20), + P(30), + P(40), + P(50), + P(60), + P(70), + P(80) + }; + C c(std::begin(a), std::end(a)); + C::iterator i = c.find(30); + assert(*i == 30); + i = c.find(5); + assert(i == c.cend()); + } +#endif +} diff --git a/test/std/containers/unord/unord.multiset/insert_const_lvalue.pass.cpp b/test/std/containers/unord/unord.multiset/insert_const_lvalue.pass.cpp new file mode 100644 index 000000000000..0051e497fd7a --- /dev/null +++ b/test/std/containers/unord/unord.multiset/insert_const_lvalue.pass.cpp @@ -0,0 +1,70 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <unordered_set> + +// template <class Value, class Hash = hash<Value>, class Pred = equal_to<Value>, +// class Alloc = allocator<Value>> +// class unordered_multiset + +// iterator insert(const value_type& x); + +#include <unordered_set> +#include <cassert> + +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_multiset<double> C; + typedef C::iterator R; + typedef C::value_type P; + C c; + R r = c.insert(P(3.5)); + assert(c.size() == 1); + assert(*r == 3.5); + + r = c.insert(P(3.5)); + assert(c.size() == 2); + assert(*r == 3.5); + + r = c.insert(P(4.5)); + assert(c.size() == 3); + assert(*r == 4.5); + + r = c.insert(P(5.5)); + assert(c.size() == 4); + assert(*r == 5.5); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multiset<double, std::hash<double>, + std::equal_to<double>, min_allocator<double>> C; + typedef C::iterator R; + typedef C::value_type P; + C c; + R r = c.insert(P(3.5)); + assert(c.size() == 1); + assert(*r == 3.5); + + r = c.insert(P(3.5)); + assert(c.size() == 2); + assert(*r == 3.5); + + r = c.insert(P(4.5)); + assert(c.size() == 3); + assert(*r == 4.5); + + r = c.insert(P(5.5)); + assert(c.size() == 4); + assert(*r == 5.5); + } +#endif +} diff --git a/test/std/containers/unord/unord.multiset/insert_hint_const_lvalue.pass.cpp b/test/std/containers/unord/unord.multiset/insert_hint_const_lvalue.pass.cpp new file mode 100644 index 000000000000..25b4bc1aa04a --- /dev/null +++ b/test/std/containers/unord/unord.multiset/insert_hint_const_lvalue.pass.cpp @@ -0,0 +1,89 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <unordered_set> + +// template <class Value, class Hash = hash<Value>, class Pred = equal_to<Value>, +// class Alloc = allocator<Value>> +// class unordered_multiset + +// iterator insert(const_iterator p, const value_type& x); + +#if _LIBCPP_DEBUG >= 1 +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) +#endif + +#include <unordered_set> +#include <cassert> + +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_multiset<double> C; + typedef C::iterator R; + typedef C::value_type P; + C c; + C::const_iterator e = c.end(); + R r = c.insert(e, P(3.5)); + assert(c.size() == 1); + assert(*r == 3.5); + + r = c.insert(c.end(), P(3.5)); + assert(c.size() == 2); + assert(*r == 3.5); + + r = c.insert(c.end(), P(4.5)); + assert(c.size() == 3); + assert(*r == 4.5); + + r = c.insert(c.end(), P(5.5)); + assert(c.size() == 4); + assert(*r == 5.5); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multiset<double, std::hash<double>, + std::equal_to<double>, min_allocator<double>> C; + typedef C::iterator R; + typedef C::value_type P; + C c; + C::const_iterator e = c.end(); + R r = c.insert(e, P(3.5)); + assert(c.size() == 1); + assert(*r == 3.5); + + r = c.insert(c.end(), P(3.5)); + assert(c.size() == 2); + assert(*r == 3.5); + + r = c.insert(c.end(), P(4.5)); + assert(c.size() == 3); + assert(*r == 4.5); + + r = c.insert(c.end(), P(5.5)); + assert(c.size() == 4); + assert(*r == 5.5); + } +#endif +#if _LIBCPP_DEBUG >= 1 + { + typedef std::unordered_multiset<double> C; + typedef C::iterator R; + typedef C::value_type P; + C c; + C c2; + C::const_iterator e = c2.end(); + P v(3.5); + R r = c.insert(e, v); + assert(false); + } +#endif +} diff --git a/test/std/containers/unord/unord.multiset/insert_hint_rvalue.pass.cpp b/test/std/containers/unord/unord.multiset/insert_hint_rvalue.pass.cpp new file mode 100644 index 000000000000..481ec80231c9 --- /dev/null +++ b/test/std/containers/unord/unord.multiset/insert_hint_rvalue.pass.cpp @@ -0,0 +1,138 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <unordered_set> + +// template <class Value, class Hash = hash<Value>, class Pred = equal_to<Value>, +// class Alloc = allocator<Value>> +// class unordered_multiset + +// iterator insert(const_iterator p, value_type&& x); + +#if _LIBCPP_DEBUG >= 1 +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) +#endif + +#include <unordered_set> +#include <cassert> + +#include "MoveOnly.h" +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_multiset<double> C; + typedef C::iterator R; + typedef double P; + C c; + C::const_iterator e = c.end(); + R r = c.insert(e, P(3.5)); + assert(c.size() == 1); + assert(*r == 3.5); + + r = c.insert(r, P(3.5)); + assert(c.size() == 2); + assert(*r == 3.5); + + r = c.insert(c.end(), P(4.5)); + assert(c.size() == 3); + assert(*r == 4.5); + + r = c.insert(c.end(), P(5.5)); + assert(c.size() == 4); + assert(*r == 5.5); + } +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + typedef std::unordered_multiset<MoveOnly> C; + typedef C::iterator R; + typedef MoveOnly P; + C c; + C::const_iterator e = c.end(); + R r = c.insert(e, P(3)); + assert(c.size() == 1); + assert(*r == 3); + + r = c.insert(r, P(3)); + assert(c.size() == 2); + assert(*r == 3); + + r = c.insert(c.end(), P(4)); + assert(c.size() == 3); + assert(*r == 4); + + r = c.insert(c.end(), P(5)); + assert(c.size() == 4); + assert(*r == 5); + } +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#if __cplusplus >= 201103L + { + typedef std::unordered_multiset<double, std::hash<double>, + std::equal_to<double>, min_allocator<double>> C; + typedef C::iterator R; + typedef double P; + C c; + C::const_iterator e = c.end(); + R r = c.insert(e, P(3.5)); + assert(c.size() == 1); + assert(*r == 3.5); + + r = c.insert(r, P(3.5)); + assert(c.size() == 2); + assert(*r == 3.5); + + r = c.insert(c.end(), P(4.5)); + assert(c.size() == 3); + assert(*r == 4.5); + + r = c.insert(c.end(), P(5.5)); + assert(c.size() == 4); + assert(*r == 5.5); + } +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + typedef std::unordered_multiset<MoveOnly, std::hash<MoveOnly>, + std::equal_to<MoveOnly>, min_allocator<MoveOnly>> C; + typedef C::iterator R; + typedef MoveOnly P; + C c; + C::const_iterator e = c.end(); + R r = c.insert(e, P(3)); + assert(c.size() == 1); + assert(*r == 3); + + r = c.insert(r, P(3)); + assert(c.size() == 2); + assert(*r == 3); + + r = c.insert(c.end(), P(4)); + assert(c.size() == 3); + assert(*r == 4); + + r = c.insert(c.end(), P(5)); + assert(c.size() == 4); + assert(*r == 5); + } +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#if _LIBCPP_DEBUG >= 1 + { + typedef std::unordered_multiset<double> C; + typedef C::iterator R; + typedef C::value_type P; + C c; + C c2; + C::const_iterator e = c2.end(); + R r = c.insert(e, P(3.5)); + assert(false); + } +#endif +#endif +} diff --git a/test/std/containers/unord/unord.multiset/insert_init.pass.cpp b/test/std/containers/unord/unord.multiset/insert_init.pass.cpp new file mode 100644 index 000000000000..6941d86f6197 --- /dev/null +++ b/test/std/containers/unord/unord.multiset/insert_init.pass.cpp @@ -0,0 +1,71 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <unordered_set> + +// template <class Value, class Hash = hash<Value>, class Pred = equal_to<Value>, +// class Alloc = allocator<Value>> +// class unordered_multiset + +// void insert(initializer_list<value_type> il); + +#include <unordered_set> +#include <cassert> + +#include "test_iterators.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + typedef std::unordered_multiset<int> C; + typedef int P; + C c; + c.insert( + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + } + ); + assert(c.size() == 6); + assert(c.count(1) == 2); + assert(c.count(2) == 2); + assert(c.count(3) == 1); + assert(c.count(4) == 1); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multiset<int, std::hash<int>, + std::equal_to<int>, min_allocator<int>> C; + typedef int P; + C c; + c.insert( + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + } + ); + assert(c.size() == 6); + assert(c.count(1) == 2); + assert(c.count(2) == 2); + assert(c.count(3) == 1); + assert(c.count(4) == 1); + } +#endif +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/test/std/containers/unord/unord.multiset/insert_range.pass.cpp b/test/std/containers/unord/unord.multiset/insert_range.pass.cpp new file mode 100644 index 000000000000..41c9d8136feb --- /dev/null +++ b/test/std/containers/unord/unord.multiset/insert_range.pass.cpp @@ -0,0 +1,70 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <unordered_set> + +// template <class Value, class Hash = hash<Value>, class Pred = equal_to<Value>, +// class Alloc = allocator<Value>> +// class unordered_multiset + +// template <class InputIterator> +// void insert(InputIterator first, InputIterator last); + +#include <unordered_set> +#include <cassert> + +#include "test_iterators.h" +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_multiset<int> C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c; + c.insert(input_iterator<P*>(a), input_iterator<P*>(a + sizeof(a)/sizeof(a[0]))); + assert(c.size() == 6); + assert(c.count(1) == 2); + assert(c.count(2) == 2); + assert(c.count(3) == 1); + assert(c.count(4) == 1); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multiset<int, std::hash<int>, + std::equal_to<int>, min_allocator<int>> C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c; + c.insert(input_iterator<P*>(a), input_iterator<P*>(a + sizeof(a)/sizeof(a[0]))); + assert(c.size() == 6); + assert(c.count(1) == 2); + assert(c.count(2) == 2); + assert(c.count(3) == 1); + assert(c.count(4) == 1); + } +#endif +} diff --git a/test/std/containers/unord/unord.multiset/insert_rvalue.pass.cpp b/test/std/containers/unord/unord.multiset/insert_rvalue.pass.cpp new file mode 100644 index 000000000000..2718324b4d08 --- /dev/null +++ b/test/std/containers/unord/unord.multiset/insert_rvalue.pass.cpp @@ -0,0 +1,118 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <unordered_set> + +// template <class Value, class Hash = hash<Value>, class Pred = equal_to<Value>, +// class Alloc = allocator<Value>> +// class unordered_multiset + +// iterator insert(value_type&& x); + +#include <unordered_set> +#include <cassert> + +#include "MoveOnly.h" +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_multiset<double> C; + typedef C::iterator R; + typedef double P; + C c; + R r = c.insert(P(3.5)); + assert(c.size() == 1); + assert(*r == 3.5); + + r = c.insert(P(3.5)); + assert(c.size() == 2); + assert(*r == 3.5); + + r = c.insert(P(4.5)); + assert(c.size() == 3); + assert(*r == 4.5); + + r = c.insert(P(5.5)); + assert(c.size() == 4); + assert(*r == 5.5); + } +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + typedef std::unordered_multiset<MoveOnly> C; + typedef C::iterator R; + typedef MoveOnly P; + C c; + R r = c.insert(P(3)); + assert(c.size() == 1); + assert(*r == 3); + + r = c.insert(P(3)); + assert(c.size() == 2); + assert(*r == 3); + + r = c.insert(P(4)); + assert(c.size() == 3); + assert(*r == 4); + + r = c.insert(P(5)); + assert(c.size() == 4); + assert(*r == 5); + } +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#if __cplusplus >= 201103L + { + typedef std::unordered_multiset<double, std::hash<double>, + std::equal_to<double>, min_allocator<double>> C; + typedef C::iterator R; + typedef double P; + C c; + R r = c.insert(P(3.5)); + assert(c.size() == 1); + assert(*r == 3.5); + + r = c.insert(P(3.5)); + assert(c.size() == 2); + assert(*r == 3.5); + + r = c.insert(P(4.5)); + assert(c.size() == 3); + assert(*r == 4.5); + + r = c.insert(P(5.5)); + assert(c.size() == 4); + assert(*r == 5.5); + } +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + typedef std::unordered_multiset<MoveOnly, std::hash<MoveOnly>, + std::equal_to<MoveOnly>, min_allocator<MoveOnly>> C; + typedef C::iterator R; + typedef MoveOnly P; + C c; + R r = c.insert(P(3)); + assert(c.size() == 1); + assert(*r == 3); + + r = c.insert(P(3)); + assert(c.size() == 2); + assert(*r == 3); + + r = c.insert(P(4)); + assert(c.size() == 3); + assert(*r == 4); + + r = c.insert(P(5)); + assert(c.size() == 4); + assert(*r == 5); + } +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#endif +} diff --git a/test/std/containers/unord/unord.multiset/iterators.fail.cpp b/test/std/containers/unord/unord.multiset/iterators.fail.cpp new file mode 100644 index 000000000000..f78bccbd423f --- /dev/null +++ b/test/std/containers/unord/unord.multiset/iterators.fail.cpp @@ -0,0 +1,67 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <unordered_set> + +// template <class Value, class Hash = hash<Value>, class Pred = equal_to<Value>, +// class Alloc = allocator<Value>> +// class unordered_multiset + +// iterator begin() {return __table_.begin();} +// iterator end() {return __table_.end();} +// const_iterator begin() const {return __table_.begin();} +// const_iterator end() const {return __table_.end();} +// const_iterator cbegin() const {return __table_.begin();} +// const_iterator cend() const {return __table_.end();} + +#include <unordered_set> +#include <cassert> + +int main() +{ + { + typedef std::unordered_multiset<int> C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c(a, a + sizeof(a)/sizeof(a[0])); + assert(c.bucket_count() == 7); + assert(c.size() == 6); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + C::iterator i = c.begin(); + assert(*i == 1); + *i = 2; + } + { + typedef std::unordered_multiset<int> C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + const C c(a, a + sizeof(a)/sizeof(a[0])); + assert(c.bucket_count() == 7); + assert(c.size() == 6); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + } +} diff --git a/test/std/containers/unord/unord.multiset/iterators.pass.cpp b/test/std/containers/unord/unord.multiset/iterators.pass.cpp new file mode 100644 index 000000000000..be95b44517fe --- /dev/null +++ b/test/std/containers/unord/unord.multiset/iterators.pass.cpp @@ -0,0 +1,127 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <unordered_set> + +// template <class Value, class Hash = hash<Value>, class Pred = equal_to<Value>, +// class Alloc = allocator<Value>> +// class unordered_multiset + +// iterator begin(); +// iterator end(); +// const_iterator begin() const; +// const_iterator end() const; +// const_iterator cbegin() const; +// const_iterator cend() const; + +#include <unordered_set> +#include <cassert> + +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_multiset<int> C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c(a, a + sizeof(a)/sizeof(a[0])); + assert(c.bucket_count() >= 7); + assert(c.size() == 6); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + C::iterator i; + } + { + typedef std::unordered_multiset<int> C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + const C c(a, a + sizeof(a)/sizeof(a[0])); + assert(c.bucket_count() >= 7); + assert(c.size() == 6); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + C::const_iterator i; + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multiset<int, std::hash<int>, + std::equal_to<int>, min_allocator<int>> C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c(a, a + sizeof(a)/sizeof(a[0])); + assert(c.bucket_count() >= 7); + assert(c.size() == 6); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + C::iterator i; + } + { + typedef std::unordered_multiset<int, std::hash<int>, + std::equal_to<int>, min_allocator<int>> C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + const C c(a, a + sizeof(a)/sizeof(a[0])); + assert(c.bucket_count() >= 7); + assert(c.size() == 6); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + C::const_iterator i; + } +#endif +#if _LIBCPP_STD_VER > 11 + { // N3644 testing + typedef std::unordered_multiset<int> C; + C::iterator ii1{}, ii2{}; + C::iterator ii4 = ii1; + C::const_iterator cii{}; + assert ( ii1 == ii2 ); + assert ( ii1 == ii4 ); + + assert (!(ii1 != ii2 )); + + assert ( (ii1 == cii )); + assert ( (cii == ii1 )); + assert (!(ii1 != cii )); + assert (!(cii != ii1 )); + } +#endif +} diff --git a/test/std/containers/unord/unord.multiset/load_factor.pass.cpp b/test/std/containers/unord/unord.multiset/load_factor.pass.cpp new file mode 100644 index 000000000000..07980c2afc85 --- /dev/null +++ b/test/std/containers/unord/unord.multiset/load_factor.pass.cpp @@ -0,0 +1,76 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <unordered_set> + +// template <class Value, class Hash = hash<Value>, class Pred = equal_to<Value>, +// class Alloc = allocator<Value>> +// class unordered_multiset + +// float load_factor() const + +#include <unordered_set> +#include <cassert> +#include <cfloat> + +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_multiset<int> C; + typedef int P; + P a[] = + { + P(10), + P(20), + P(30), + P(40), + P(50), + P(60), + P(70), + P(80) + }; + const C c(std::begin(a), std::end(a)); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + } + { + typedef std::unordered_multiset<int> C; + typedef int P; + const C c; + assert(c.load_factor() == 0); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multiset<int, std::hash<int>, + std::equal_to<int>, min_allocator<int>> C; + typedef int P; + P a[] = + { + P(10), + P(20), + P(30), + P(40), + P(50), + P(60), + P(70), + P(80) + }; + const C c(std::begin(a), std::end(a)); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + } + { + typedef std::unordered_multiset<int, std::hash<int>, + std::equal_to<int>, min_allocator<int>> C; + typedef int P; + const C c; + assert(c.load_factor() == 0); + } +#endif +} diff --git a/test/std/containers/unord/unord.multiset/local_iterators.fail.cpp b/test/std/containers/unord/unord.multiset/local_iterators.fail.cpp new file mode 100644 index 000000000000..4118987c2ae0 --- /dev/null +++ b/test/std/containers/unord/unord.multiset/local_iterators.fail.cpp @@ -0,0 +1,261 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <unordered_set> + +// template <class Value, class Hash = hash<Value>, class Pred = equal_to<Value>, +// class Alloc = allocator<Value>> +// class unordered_multiset + +// local_iterator begin (size_type n); +// local_iterator end (size_type n); +// const_local_iterator begin (size_type n) const; +// const_local_iterator end (size_type n) const; +// const_local_iterator cbegin(size_type n) const; +// const_local_iterator cend (size_type n) const; + +#include <unordered_set> +#include <cassert> + +int main() +{ + { + typedef std::unordered_multiset<int> C; + typedef int P; + typedef C::local_iterator I; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c(a, a + sizeof(a)/sizeof(a[0])); + assert(c.bucket_count() == 7); + C::size_type b = c.bucket(0); + I i = c.begin(b); + I j = c.end(b); + assert(std::distance(i, j) == 0); + + b = c.bucket(1); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 2); + assert(*i == 1); + ++i; + assert(*i == 1); + *i = 2; + + b = c.bucket(2); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 2); + assert(*i == 2); + ++i; + assert(*i == 2); + + b = c.bucket(3); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 1); + assert(*i == 3); + + b = c.bucket(4); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 1); + assert(*i == 4); + + b = c.bucket(5); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 0); + + b = c.bucket(6); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 0); + } + { + typedef std::unordered_multiset<int> C; + typedef int P; + typedef C::const_local_iterator I; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + const C c(a, a + sizeof(a)/sizeof(a[0])); + assert(c.bucket_count() == 7); + C::size_type b = c.bucket(0); + I i = c.begin(b); + I j = c.end(b); + assert(std::distance(i, j) == 0); + + b = c.bucket(1); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 2); + assert(*i == 1); + ++i; + assert(*i == 1); + + b = c.bucket(2); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 2); + assert(*i == 2); + ++i; + assert(*i == 2); + + b = c.bucket(3); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 1); + assert(*i == 3); + + b = c.bucket(4); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 1); + assert(*i == 4); + + b = c.bucket(5); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 0); + + b = c.bucket(6); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 0); + } + { + typedef std::unordered_multiset<int> C; + typedef int P; + typedef C::const_local_iterator I; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c(a, a + sizeof(a)/sizeof(a[0])); + assert(c.bucket_count() == 7); + C::size_type b = c.bucket(0); + I i = c.cbegin(b); + I j = c.cend(b); + assert(std::distance(i, j) == 0); + + b = c.bucket(1); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 2); + assert(*i == 1); + ++i; + assert(*i == 1); + + b = c.bucket(2); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 2); + assert(*i == 2); + ++i; + assert(*i == 2); + + b = c.bucket(3); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 1); + assert(*i == 3); + + b = c.bucket(4); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 1); + assert(*i == 4); + + b = c.bucket(5); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 0); + + b = c.bucket(6); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 0); + } + { + typedef std::unordered_multiset<int> C; + typedef int P; + typedef C::const_local_iterator I; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + const C c(a, a + sizeof(a)/sizeof(a[0])); + assert(c.bucket_count() == 7); + C::size_type b = c.bucket(0); + I i = c.cbegin(b); + I j = c.cend(b); + assert(std::distance(i, j) == 0); + + b = c.bucket(1); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 2); + assert(*i == 1); + ++i; + assert(*i == 1); + + b = c.bucket(2); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 2); + assert(*i == 2); + ++i; + assert(*i == 2); + + b = c.bucket(3); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 1); + assert(*i == 3); + + b = c.bucket(4); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 1); + assert(*i == 4); + + b = c.bucket(5); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 0); + + b = c.bucket(6); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 0); + } +} diff --git a/test/std/containers/unord/unord.multiset/local_iterators.pass.cpp b/test/std/containers/unord/unord.multiset/local_iterators.pass.cpp new file mode 100644 index 000000000000..3471707e42a1 --- /dev/null +++ b/test/std/containers/unord/unord.multiset/local_iterators.pass.cpp @@ -0,0 +1,500 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <unordered_set> + +// template <class Value, class Hash = hash<Value>, class Pred = equal_to<Value>, +// class Alloc = allocator<Value>> +// class unordered_multiset + +// local_iterator begin (size_type n); +// local_iterator end (size_type n); +// const_local_iterator begin (size_type n) const; +// const_local_iterator end (size_type n) const; +// const_local_iterator cbegin(size_type n) const; +// const_local_iterator cend (size_type n) const; + +#include <unordered_set> +#include <cassert> + +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_multiset<int> C; + typedef int P; + typedef C::local_iterator I; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c(a, a + sizeof(a)/sizeof(a[0])); + assert(c.bucket_count() >= 7); + C::size_type b = c.bucket(0); + I i = c.begin(b); + I j = c.end(b); + assert(std::distance(i, j) == 0); + + b = c.bucket(1); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 2); + assert(*i == 1); + ++i; + assert(*i == 1); + + b = c.bucket(2); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 2); + assert(*i == 2); + ++i; + assert(*i == 2); + + b = c.bucket(3); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 1); + assert(*i == 3); + + b = c.bucket(4); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 1); + assert(*i == 4); + + b = c.bucket(5); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 0); + + b = c.bucket(6); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 0); + } + { + typedef std::unordered_multiset<int> C; + typedef int P; + typedef C::const_local_iterator I; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + const C c(a, a + sizeof(a)/sizeof(a[0])); + assert(c.bucket_count() >= 7); + C::size_type b = c.bucket(0); + I i = c.begin(b); + I j = c.end(b); + assert(std::distance(i, j) == 0); + + b = c.bucket(1); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 2); + assert(*i == 1); + ++i; + assert(*i == 1); + + b = c.bucket(2); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 2); + assert(*i == 2); + ++i; + assert(*i == 2); + + b = c.bucket(3); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 1); + assert(*i == 3); + + b = c.bucket(4); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 1); + assert(*i == 4); + + b = c.bucket(5); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 0); + + b = c.bucket(6); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 0); + } + { + typedef std::unordered_multiset<int> C; + typedef int P; + typedef C::const_local_iterator I; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c(a, a + sizeof(a)/sizeof(a[0])); + assert(c.bucket_count() >= 7); + C::size_type b = c.bucket(0); + I i = c.cbegin(b); + I j = c.cend(b); + assert(std::distance(i, j) == 0); + + b = c.bucket(1); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 2); + assert(*i == 1); + ++i; + assert(*i == 1); + + b = c.bucket(2); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 2); + assert(*i == 2); + ++i; + assert(*i == 2); + + b = c.bucket(3); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 1); + assert(*i == 3); + + b = c.bucket(4); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 1); + assert(*i == 4); + + b = c.bucket(5); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 0); + + b = c.bucket(6); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 0); + } + { + typedef std::unordered_multiset<int> C; + typedef int P; + typedef C::const_local_iterator I; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + const C c(a, a + sizeof(a)/sizeof(a[0])); + assert(c.bucket_count() >= 7); + C::size_type b = c.bucket(0); + I i = c.cbegin(b); + I j = c.cend(b); + assert(std::distance(i, j) == 0); + + b = c.bucket(1); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 2); + assert(*i == 1); + ++i; + assert(*i == 1); + + b = c.bucket(2); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 2); + assert(*i == 2); + ++i; + assert(*i == 2); + + b = c.bucket(3); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 1); + assert(*i == 3); + + b = c.bucket(4); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 1); + assert(*i == 4); + + b = c.bucket(5); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 0); + + b = c.bucket(6); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 0); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multiset<int, std::hash<int>, + std::equal_to<int>, min_allocator<int>> C; + typedef int P; + typedef C::local_iterator I; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c(a, a + sizeof(a)/sizeof(a[0])); + assert(c.bucket_count() >= 7); + C::size_type b = c.bucket(0); + I i = c.begin(b); + I j = c.end(b); + assert(std::distance(i, j) == 0); + + b = c.bucket(1); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 2); + assert(*i == 1); + ++i; + assert(*i == 1); + + b = c.bucket(2); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 2); + assert(*i == 2); + ++i; + assert(*i == 2); + + b = c.bucket(3); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 1); + assert(*i == 3); + + b = c.bucket(4); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 1); + assert(*i == 4); + + b = c.bucket(5); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 0); + + b = c.bucket(6); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 0); + } + { + typedef std::unordered_multiset<int, std::hash<int>, + std::equal_to<int>, min_allocator<int>> C; + typedef int P; + typedef C::const_local_iterator I; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + const C c(a, a + sizeof(a)/sizeof(a[0])); + assert(c.bucket_count() >= 7); + C::size_type b = c.bucket(0); + I i = c.begin(b); + I j = c.end(b); + assert(std::distance(i, j) == 0); + + b = c.bucket(1); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 2); + assert(*i == 1); + ++i; + assert(*i == 1); + + b = c.bucket(2); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 2); + assert(*i == 2); + ++i; + assert(*i == 2); + + b = c.bucket(3); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 1); + assert(*i == 3); + + b = c.bucket(4); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 1); + assert(*i == 4); + + b = c.bucket(5); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 0); + + b = c.bucket(6); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 0); + } + { + typedef std::unordered_multiset<int, std::hash<int>, + std::equal_to<int>, min_allocator<int>> C; + typedef int P; + typedef C::const_local_iterator I; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c(a, a + sizeof(a)/sizeof(a[0])); + assert(c.bucket_count() >= 7); + C::size_type b = c.bucket(0); + I i = c.cbegin(b); + I j = c.cend(b); + assert(std::distance(i, j) == 0); + + b = c.bucket(1); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 2); + assert(*i == 1); + ++i; + assert(*i == 1); + + b = c.bucket(2); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 2); + assert(*i == 2); + ++i; + assert(*i == 2); + + b = c.bucket(3); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 1); + assert(*i == 3); + + b = c.bucket(4); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 1); + assert(*i == 4); + + b = c.bucket(5); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 0); + + b = c.bucket(6); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 0); + } + { + typedef std::unordered_multiset<int, std::hash<int>, + std::equal_to<int>, min_allocator<int>> C; + typedef int P; + typedef C::const_local_iterator I; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + const C c(a, a + sizeof(a)/sizeof(a[0])); + assert(c.bucket_count() >= 7); + C::size_type b = c.bucket(0); + I i = c.cbegin(b); + I j = c.cend(b); + assert(std::distance(i, j) == 0); + + b = c.bucket(1); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 2); + assert(*i == 1); + ++i; + assert(*i == 1); + + b = c.bucket(2); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 2); + assert(*i == 2); + ++i; + assert(*i == 2); + + b = c.bucket(3); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 1); + assert(*i == 3); + + b = c.bucket(4); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 1); + assert(*i == 4); + + b = c.bucket(5); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 0); + + b = c.bucket(6); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 0); + } +#endif +} diff --git a/test/std/containers/unord/unord.multiset/max_bucket_count.pass.cpp b/test/std/containers/unord/unord.multiset/max_bucket_count.pass.cpp new file mode 100644 index 000000000000..619a8cf1266f --- /dev/null +++ b/test/std/containers/unord/unord.multiset/max_bucket_count.pass.cpp @@ -0,0 +1,38 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <unordered_set> + +// template <class Value, class Hash = hash<Value>, class Pred = equal_to<Value>, +// class Alloc = allocator<Value>> +// class unordered_multiset + +// size_type max_bucket_count() const; + +#include <unordered_set> +#include <cassert> + +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_multiset<int> C; + const C c; + assert(c.max_bucket_count() > 0); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multiset<int, std::hash<int>, + std::equal_to<int>, min_allocator<int>> C; + const C c; + assert(c.max_bucket_count() > 0); + } +#endif +} diff --git a/test/std/containers/unord/unord.multiset/max_load_factor.pass.cpp b/test/std/containers/unord/unord.multiset/max_load_factor.pass.cpp new file mode 100644 index 000000000000..08f52bb70840 --- /dev/null +++ b/test/std/containers/unord/unord.multiset/max_load_factor.pass.cpp @@ -0,0 +1,70 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <unordered_set> + +// template <class Value, class Hash = hash<Value>, class Pred = equal_to<Value>, +// class Alloc = allocator<Value>> +// class unordered_multiset + +// float max_load_factor() const; +// void max_load_factor(float mlf); + +#ifdef _LIBCPP_DEBUG +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) +#endif + +#include <unordered_set> +#include <cassert> + +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_multiset<int> C; + typedef int P; + const C c; + assert(c.max_load_factor() == 1); + } + { + typedef std::unordered_multiset<int> C; + typedef int P; + C c; + assert(c.max_load_factor() == 1); + c.max_load_factor(2.5); + assert(c.max_load_factor() == 2.5); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multiset<int, std::hash<int>, + std::equal_to<int>, min_allocator<int>> C; + typedef int P; + const C c; + assert(c.max_load_factor() == 1); + } + { + typedef std::unordered_multiset<int, std::hash<int>, + std::equal_to<int>, min_allocator<int>> C; + typedef int P; + C c; + assert(c.max_load_factor() == 1); + c.max_load_factor(2.5); + assert(c.max_load_factor() == 2.5); + } +#endif +#if _LIBCPP_DEBUG_LEVEL >= 1 + { + typedef std::unordered_multiset<int> C; + C c; + c.max_load_factor(0); + assert(false); + } +#endif +} diff --git a/test/std/containers/unord/unord.multiset/max_size.pass.cpp b/test/std/containers/unord/unord.multiset/max_size.pass.cpp new file mode 100644 index 000000000000..a5d0b5538bce --- /dev/null +++ b/test/std/containers/unord/unord.multiset/max_size.pass.cpp @@ -0,0 +1,36 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <unordered_set> + +// template <class Value, class Hash = hash<Value>, class Pred = equal_to<Value>, +// class Alloc = allocator<Value>> +// class unordered_multiset + +// size_type max_size() const; + +#include <unordered_set> +#include <cassert> + +#include "min_allocator.h" + +int main() +{ + { + std::unordered_multiset<int> u; + assert(u.max_size() > 0); + } +#if __cplusplus >= 201103L + { + std::unordered_multiset<int, std::hash<int>, + std::equal_to<int>, min_allocator<int>> u; + assert(u.max_size() > 0); + } +#endif +} diff --git a/test/std/containers/unord/unord.multiset/rehash.pass.cpp b/test/std/containers/unord/unord.multiset/rehash.pass.cpp new file mode 100644 index 000000000000..bc8d461c60bf --- /dev/null +++ b/test/std/containers/unord/unord.multiset/rehash.pass.cpp @@ -0,0 +1,90 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <unordered_set> + +// template <class Value, class Hash = hash<Value>, class Pred = equal_to<Value>, +// class Alloc = allocator<Value>> +// class unordered_multiset + +// void rehash(size_type n); + +#include <unordered_set> +#include <cassert> + +#include "min_allocator.h" + +template <class C> +void test(const C& c) +{ + assert(c.size() == 6); + assert(c.count(1) == 2); + assert(c.count(2) == 2); + assert(c.count(3) == 1); + assert(c.count(4) == 1); +} + +int main() +{ + { + typedef std::unordered_multiset<int> C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c(a, a + sizeof(a)/sizeof(a[0])); + test(c); + assert(c.bucket_count() >= 7); + c.rehash(3); + assert(c.bucket_count() == 7); + test(c); + c.max_load_factor(2); + c.rehash(3); + assert(c.bucket_count() == 3); + test(c); + c.rehash(31); + assert(c.bucket_count() == 31); + test(c); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multiset<int, std::hash<int>, + std::equal_to<int>, min_allocator<int>> C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c(a, a + sizeof(a)/sizeof(a[0])); + test(c); + assert(c.bucket_count() >= 7); + c.rehash(3); + assert(c.bucket_count() == 7); + test(c); + c.max_load_factor(2); + c.rehash(3); + assert(c.bucket_count() == 3); + test(c); + c.rehash(31); + assert(c.bucket_count() == 31); + test(c); + } +#endif +} diff --git a/test/std/containers/unord/unord.multiset/reserve.pass.cpp b/test/std/containers/unord/unord.multiset/reserve.pass.cpp new file mode 100644 index 000000000000..0c17583d371d --- /dev/null +++ b/test/std/containers/unord/unord.multiset/reserve.pass.cpp @@ -0,0 +1,90 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <unordered_set> + +// template <class Value, class Hash = hash<Value>, class Pred = equal_to<Value>, +// class Alloc = allocator<Value>> +// class unordered_multiset + +// void reserve(size_type n); + +#include <unordered_set> +#include <cassert> + +#include "min_allocator.h" + +template <class C> +void test(const C& c) +{ + assert(c.size() == 6); + assert(c.count(1) == 2); + assert(c.count(2) == 2); + assert(c.count(3) == 1); + assert(c.count(4) == 1); +} + +int main() +{ + { + typedef std::unordered_multiset<int> C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c(a, a + sizeof(a)/sizeof(a[0])); + test(c); + assert(c.bucket_count() >= 7); + c.reserve(3); + assert(c.bucket_count() == 7); + test(c); + c.max_load_factor(2); + c.reserve(3); + assert(c.bucket_count() == 3); + test(c); + c.reserve(31); + assert(c.bucket_count() >= 16); + test(c); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multiset<int, std::hash<int>, + std::equal_to<int>, min_allocator<int>> C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c(a, a + sizeof(a)/sizeof(a[0])); + test(c); + assert(c.bucket_count() >= 7); + c.reserve(3); + assert(c.bucket_count() == 7); + test(c); + c.max_load_factor(2); + c.reserve(3); + assert(c.bucket_count() == 3); + test(c); + c.reserve(31); + assert(c.bucket_count() >= 16); + test(c); + } +#endif +} diff --git a/test/std/containers/unord/unord.multiset/scary.pass.cpp b/test/std/containers/unord/unord.multiset/scary.pass.cpp new file mode 100644 index 000000000000..dfd144bb3170 --- /dev/null +++ b/test/std/containers/unord/unord.multiset/scary.pass.cpp @@ -0,0 +1,24 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <unordered_set> + +// class unordered_set class unordered_multiset + +// Extension: SCARY/N2913 iterator compatibility between unordered_set and unordered_multiset + +#include <unordered_set> + +int main() +{ + typedef std::unordered_set<int> M1; + typedef std::unordered_multiset<int> M2; + M2::iterator i; + M1::iterator j = i; +} diff --git a/test/std/containers/unord/unord.multiset/swap_member.pass.cpp b/test/std/containers/unord/unord.multiset/swap_member.pass.cpp new file mode 100644 index 000000000000..275ff4094e81 --- /dev/null +++ b/test/std/containers/unord/unord.multiset/swap_member.pass.cpp @@ -0,0 +1,571 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <unordered_set> + +// template <class Value, class Hash = hash<Value>, class Pred = equal_to<Value>, +// class Alloc = allocator<Value>> +// class unordered_multiset + +// void swap(unordered_multiset& __u); + +#include <unordered_set> +#include <cassert> + +#include "../../test_compare.h" +#include "../../test_hash.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ + { + typedef test_hash<std::hash<int> > Hash; + typedef test_compare<std::equal_to<int> > Compare; + typedef test_allocator<int> Alloc; + typedef std::unordered_multiset<int, Hash, Compare, Alloc> C; + typedef int P; + C c1(0, Hash(1), Compare(1), Alloc(1)); + C c2(0, Hash(2), Compare(2), Alloc(2)); + c2.max_load_factor(2); + c1.swap(c2); + + assert(c1.bucket_count() == 0); + assert(c1.size() == 0); + assert(c1.hash_function() == Hash(2)); + assert(c1.key_eq() == Compare(2)); + assert(c1.get_allocator() == Alloc(1)); + assert(std::distance(c1.begin(), c1.end()) == c1.size()); + assert(std::distance(c1.cbegin(), c1.cend()) == c1.size()); + assert(c1.max_load_factor() == 2); + + assert(c2.bucket_count() == 0); + assert(c2.size() == 0); + assert(c2.hash_function() == Hash(1)); + assert(c2.key_eq() == Compare(1)); + assert(c2.get_allocator() == Alloc(2)); + assert(std::distance(c2.begin(), c2.end()) == c2.size()); + assert(std::distance(c2.cbegin(), c2.cend()) == c2.size()); + assert(c2.max_load_factor() == 1); + } + { + typedef test_hash<std::hash<int> > Hash; + typedef test_compare<std::equal_to<int> > Compare; + typedef test_allocator<int> Alloc; + typedef std::unordered_multiset<int, Hash, Compare, Alloc> C; + typedef int P; + P a2[] = + { + P(10), + P(20), + P(30), + P(40), + P(50), + P(60), + P(70), + P(80) + }; + C c1(0, Hash(1), Compare(1), Alloc(1)); + C c2(std::begin(a2), std::end(a2), 0, Hash(2), Compare(2), Alloc(2)); + c2.max_load_factor(2); + c1.swap(c2); + + assert(c1.bucket_count() >= 11); + assert(c1.size() == 8); + assert(*c1.find(10) == 10); + assert(*c1.find(20) == 20); + assert(*c1.find(30) == 30); + assert(*c1.find(40) == 40); + assert(*c1.find(50) == 50); + assert(*c1.find(60) == 60); + assert(*c1.find(70) == 70); + assert(*c1.find(80) == 80); + assert(c1.hash_function() == Hash(2)); + assert(c1.key_eq() == Compare(2)); + assert(c1.get_allocator() == Alloc(1)); + assert(std::distance(c1.begin(), c1.end()) == c1.size()); + assert(std::distance(c1.cbegin(), c1.cend()) == c1.size()); + assert(c1.max_load_factor() == 2); + + assert(c2.bucket_count() == 0); + assert(c2.size() == 0); + assert(c2.hash_function() == Hash(1)); + assert(c2.key_eq() == Compare(1)); + assert(c2.get_allocator() == Alloc(2)); + assert(std::distance(c2.begin(), c2.end()) == c2.size()); + assert(std::distance(c2.cbegin(), c2.cend()) == c2.size()); + assert(c2.max_load_factor() == 1); + } + { + typedef test_hash<std::hash<int> > Hash; + typedef test_compare<std::equal_to<int> > Compare; + typedef test_allocator<int> Alloc; + typedef std::unordered_multiset<int, Hash, Compare, Alloc> C; + typedef int P; + P a1[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c1(std::begin(a1), std::end(a1), 0, Hash(1), Compare(1), Alloc(1)); + C c2(0, Hash(2), Compare(2), Alloc(2)); + c2.max_load_factor(2); + c1.swap(c2); + + assert(c1.bucket_count() == 0); + assert(c1.size() == 0); + assert(c1.hash_function() == Hash(2)); + assert(c1.key_eq() == Compare(2)); + assert(c1.get_allocator() == Alloc(1)); + assert(std::distance(c1.begin(), c1.end()) == c1.size()); + assert(std::distance(c1.cbegin(), c1.cend()) == c1.size()); + assert(c1.max_load_factor() == 2); + + assert(c2.bucket_count() >= 7); + assert(c2.size() == 6); + assert(c2.count(1) == 2); + assert(c2.count(2) == 2); + assert(c2.count(3) == 1); + assert(c2.count(4) == 1); + assert(c2.hash_function() == Hash(1)); + assert(c2.key_eq() == Compare(1)); + assert(c2.get_allocator() == Alloc(2)); + assert(std::distance(c2.begin(), c2.end()) == c2.size()); + assert(std::distance(c2.cbegin(), c2.cend()) == c2.size()); + assert(c2.max_load_factor() == 1); + } + { + typedef test_hash<std::hash<int> > Hash; + typedef test_compare<std::equal_to<int> > Compare; + typedef test_allocator<int> Alloc; + typedef std::unordered_multiset<int, Hash, Compare, Alloc> C; + typedef int P; + P a1[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + P a2[] = + { + P(10), + P(20), + P(30), + P(40), + P(50), + P(60), + P(70), + P(80) + }; + C c1(std::begin(a1), std::end(a1), 0, Hash(1), Compare(1), Alloc(1)); + C c2(std::begin(a2), std::end(a2), 0, Hash(2), Compare(2), Alloc(2)); + c2.max_load_factor(2); + c1.swap(c2); + + assert(c1.bucket_count() >= 11); + assert(c1.size() == 8); + assert(*c1.find(10) == 10); + assert(*c1.find(20) == 20); + assert(*c1.find(30) == 30); + assert(*c1.find(40) == 40); + assert(*c1.find(50) == 50); + assert(*c1.find(60) == 60); + assert(*c1.find(70) == 70); + assert(*c1.find(80) == 80); + assert(c1.hash_function() == Hash(2)); + assert(c1.key_eq() == Compare(2)); + assert(c1.get_allocator() == Alloc(1)); + assert(std::distance(c1.begin(), c1.end()) == c1.size()); + assert(std::distance(c1.cbegin(), c1.cend()) == c1.size()); + assert(c1.max_load_factor() == 2); + + assert(c2.bucket_count() >= 7); + assert(c2.size() == 6); + assert(c2.count(1) == 2); + assert(c2.count(2) == 2); + assert(c2.count(3) == 1); + assert(c2.count(4) == 1); + assert(c2.hash_function() == Hash(1)); + assert(c2.key_eq() == Compare(1)); + assert(c2.get_allocator() == Alloc(2)); + assert(std::distance(c2.begin(), c2.end()) == c2.size()); + assert(std::distance(c2.cbegin(), c2.cend()) == c2.size()); + assert(c2.max_load_factor() == 1); + } + + { + typedef test_hash<std::hash<int> > Hash; + typedef test_compare<std::equal_to<int> > Compare; + typedef other_allocator<int> Alloc; + typedef std::unordered_multiset<int, Hash, Compare, Alloc> C; + typedef int P; + C c1(0, Hash(1), Compare(1), Alloc(1)); + C c2(0, Hash(2), Compare(2), Alloc(2)); + c2.max_load_factor(2); + c1.swap(c2); + + assert(c1.bucket_count() == 0); + assert(c1.size() == 0); + assert(c1.hash_function() == Hash(2)); + assert(c1.key_eq() == Compare(2)); + assert(c1.get_allocator() == Alloc(2)); + assert(std::distance(c1.begin(), c1.end()) == c1.size()); + assert(std::distance(c1.cbegin(), c1.cend()) == c1.size()); + assert(c1.max_load_factor() == 2); + + assert(c2.bucket_count() == 0); + assert(c2.size() == 0); + assert(c2.hash_function() == Hash(1)); + assert(c2.key_eq() == Compare(1)); + assert(c2.get_allocator() == Alloc(1)); + assert(std::distance(c2.begin(), c2.end()) == c2.size()); + assert(std::distance(c2.cbegin(), c2.cend()) == c2.size()); + assert(c2.max_load_factor() == 1); + } + { + typedef test_hash<std::hash<int> > Hash; + typedef test_compare<std::equal_to<int> > Compare; + typedef other_allocator<int> Alloc; + typedef std::unordered_multiset<int, Hash, Compare, Alloc> C; + typedef int P; + P a2[] = + { + P(10), + P(20), + P(30), + P(40), + P(50), + P(60), + P(70), + P(80) + }; + C c1(0, Hash(1), Compare(1), Alloc(1)); + C c2(std::begin(a2), std::end(a2), 0, Hash(2), Compare(2), Alloc(2)); + c2.max_load_factor(2); + c1.swap(c2); + + assert(c1.bucket_count() >= 11); + assert(c1.size() == 8); + assert(*c1.find(10) == 10); + assert(*c1.find(20) == 20); + assert(*c1.find(30) == 30); + assert(*c1.find(40) == 40); + assert(*c1.find(50) == 50); + assert(*c1.find(60) == 60); + assert(*c1.find(70) == 70); + assert(*c1.find(80) == 80); + assert(c1.hash_function() == Hash(2)); + assert(c1.key_eq() == Compare(2)); + assert(c1.get_allocator() == Alloc(2)); + assert(std::distance(c1.begin(), c1.end()) == c1.size()); + assert(std::distance(c1.cbegin(), c1.cend()) == c1.size()); + assert(c1.max_load_factor() == 2); + + assert(c2.bucket_count() == 0); + assert(c2.size() == 0); + assert(c2.hash_function() == Hash(1)); + assert(c2.key_eq() == Compare(1)); + assert(c2.get_allocator() == Alloc(1)); + assert(std::distance(c2.begin(), c2.end()) == c2.size()); + assert(std::distance(c2.cbegin(), c2.cend()) == c2.size()); + assert(c2.max_load_factor() == 1); + } + { + typedef test_hash<std::hash<int> > Hash; + typedef test_compare<std::equal_to<int> > Compare; + typedef other_allocator<int> Alloc; + typedef std::unordered_multiset<int, Hash, Compare, Alloc> C; + typedef int P; + P a1[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c1(std::begin(a1), std::end(a1), 0, Hash(1), Compare(1), Alloc(1)); + C c2(0, Hash(2), Compare(2), Alloc(2)); + c2.max_load_factor(2); + c1.swap(c2); + + assert(c1.bucket_count() == 0); + assert(c1.size() == 0); + assert(c1.hash_function() == Hash(2)); + assert(c1.key_eq() == Compare(2)); + assert(c1.get_allocator() == Alloc(2)); + assert(std::distance(c1.begin(), c1.end()) == c1.size()); + assert(std::distance(c1.cbegin(), c1.cend()) == c1.size()); + assert(c1.max_load_factor() == 2); + + assert(c2.bucket_count() >= 7); + assert(c2.size() == 6); + assert(c2.count(1) == 2); + assert(c2.count(2) == 2); + assert(c2.count(3) == 1); + assert(c2.count(4) == 1); + assert(c2.hash_function() == Hash(1)); + assert(c2.key_eq() == Compare(1)); + assert(c2.get_allocator() == Alloc(1)); + assert(std::distance(c2.begin(), c2.end()) == c2.size()); + assert(std::distance(c2.cbegin(), c2.cend()) == c2.size()); + assert(c2.max_load_factor() == 1); + } + { + typedef test_hash<std::hash<int> > Hash; + typedef test_compare<std::equal_to<int> > Compare; + typedef other_allocator<int> Alloc; + typedef std::unordered_multiset<int, Hash, Compare, Alloc> C; + typedef int P; + P a1[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + P a2[] = + { + P(10), + P(20), + P(30), + P(40), + P(50), + P(60), + P(70), + P(80) + }; + C c1(std::begin(a1), std::end(a1), 0, Hash(1), Compare(1), Alloc(1)); + C c2(std::begin(a2), std::end(a2), 0, Hash(2), Compare(2), Alloc(2)); + c2.max_load_factor(2); + c1.swap(c2); + + assert(c1.bucket_count() >= 11); + assert(c1.size() == 8); + assert(*c1.find(10) == 10); + assert(*c1.find(20) == 20); + assert(*c1.find(30) == 30); + assert(*c1.find(40) == 40); + assert(*c1.find(50) == 50); + assert(*c1.find(60) == 60); + assert(*c1.find(70) == 70); + assert(*c1.find(80) == 80); + assert(c1.hash_function() == Hash(2)); + assert(c1.key_eq() == Compare(2)); + assert(c1.get_allocator() == Alloc(2)); + assert(std::distance(c1.begin(), c1.end()) == c1.size()); + assert(std::distance(c1.cbegin(), c1.cend()) == c1.size()); + assert(c1.max_load_factor() == 2); + + assert(c2.bucket_count() >= 7); + assert(c2.size() == 6); + assert(c2.count(1) == 2); + assert(c2.count(2) == 2); + assert(c2.count(3) == 1); + assert(c2.count(4) == 1); + assert(c2.hash_function() == Hash(1)); + assert(c2.key_eq() == Compare(1)); + assert(c2.get_allocator() == Alloc(1)); + assert(std::distance(c2.begin(), c2.end()) == c2.size()); + assert(std::distance(c2.cbegin(), c2.cend()) == c2.size()); + assert(c2.max_load_factor() == 1); + } +#if __cplusplus >= 201103L + { + typedef test_hash<std::hash<int> > Hash; + typedef test_compare<std::equal_to<int> > Compare; + typedef min_allocator<int> Alloc; + typedef std::unordered_multiset<int, Hash, Compare, Alloc> C; + typedef int P; + C c1(0, Hash(1), Compare(1), Alloc()); + C c2(0, Hash(2), Compare(2), Alloc()); + c2.max_load_factor(2); + c1.swap(c2); + + assert(c1.bucket_count() == 0); + assert(c1.size() == 0); + assert(c1.hash_function() == Hash(2)); + assert(c1.key_eq() == Compare(2)); + assert(c1.get_allocator() == Alloc()); + assert(std::distance(c1.begin(), c1.end()) == c1.size()); + assert(std::distance(c1.cbegin(), c1.cend()) == c1.size()); + assert(c1.max_load_factor() == 2); + + assert(c2.bucket_count() == 0); + assert(c2.size() == 0); + assert(c2.hash_function() == Hash(1)); + assert(c2.key_eq() == Compare(1)); + assert(c2.get_allocator() == Alloc()); + assert(std::distance(c2.begin(), c2.end()) == c2.size()); + assert(std::distance(c2.cbegin(), c2.cend()) == c2.size()); + assert(c2.max_load_factor() == 1); + } + { + typedef test_hash<std::hash<int> > Hash; + typedef test_compare<std::equal_to<int> > Compare; + typedef min_allocator<int> Alloc; + typedef std::unordered_multiset<int, Hash, Compare, Alloc> C; + typedef int P; + P a2[] = + { + P(10), + P(20), + P(30), + P(40), + P(50), + P(60), + P(70), + P(80) + }; + C c1(0, Hash(1), Compare(1), Alloc()); + C c2(std::begin(a2), std::end(a2), 0, Hash(2), Compare(2), Alloc()); + c2.max_load_factor(2); + c1.swap(c2); + + assert(c1.bucket_count() >= 11); + assert(c1.size() == 8); + assert(*c1.find(10) == 10); + assert(*c1.find(20) == 20); + assert(*c1.find(30) == 30); + assert(*c1.find(40) == 40); + assert(*c1.find(50) == 50); + assert(*c1.find(60) == 60); + assert(*c1.find(70) == 70); + assert(*c1.find(80) == 80); + assert(c1.hash_function() == Hash(2)); + assert(c1.key_eq() == Compare(2)); + assert(c1.get_allocator() == Alloc()); + assert(std::distance(c1.begin(), c1.end()) == c1.size()); + assert(std::distance(c1.cbegin(), c1.cend()) == c1.size()); + assert(c1.max_load_factor() == 2); + + assert(c2.bucket_count() == 0); + assert(c2.size() == 0); + assert(c2.hash_function() == Hash(1)); + assert(c2.key_eq() == Compare(1)); + assert(c2.get_allocator() == Alloc()); + assert(std::distance(c2.begin(), c2.end()) == c2.size()); + assert(std::distance(c2.cbegin(), c2.cend()) == c2.size()); + assert(c2.max_load_factor() == 1); + } + { + typedef test_hash<std::hash<int> > Hash; + typedef test_compare<std::equal_to<int> > Compare; + typedef min_allocator<int> Alloc; + typedef std::unordered_multiset<int, Hash, Compare, Alloc> C; + typedef int P; + P a1[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c1(std::begin(a1), std::end(a1), 0, Hash(1), Compare(1), Alloc()); + C c2(0, Hash(2), Compare(2), Alloc()); + c2.max_load_factor(2); + c1.swap(c2); + + assert(c1.bucket_count() == 0); + assert(c1.size() == 0); + assert(c1.hash_function() == Hash(2)); + assert(c1.key_eq() == Compare(2)); + assert(c1.get_allocator() == Alloc()); + assert(std::distance(c1.begin(), c1.end()) == c1.size()); + assert(std::distance(c1.cbegin(), c1.cend()) == c1.size()); + assert(c1.max_load_factor() == 2); + + assert(c2.bucket_count() >= 7); + assert(c2.size() == 6); + assert(c2.count(1) == 2); + assert(c2.count(2) == 2); + assert(c2.count(3) == 1); + assert(c2.count(4) == 1); + assert(c2.hash_function() == Hash(1)); + assert(c2.key_eq() == Compare(1)); + assert(c2.get_allocator() == Alloc()); + assert(std::distance(c2.begin(), c2.end()) == c2.size()); + assert(std::distance(c2.cbegin(), c2.cend()) == c2.size()); + assert(c2.max_load_factor() == 1); + } + { + typedef test_hash<std::hash<int> > Hash; + typedef test_compare<std::equal_to<int> > Compare; + typedef min_allocator<int> Alloc; + typedef std::unordered_multiset<int, Hash, Compare, Alloc> C; + typedef int P; + P a1[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + P a2[] = + { + P(10), + P(20), + P(30), + P(40), + P(50), + P(60), + P(70), + P(80) + }; + C c1(std::begin(a1), std::end(a1), 0, Hash(1), Compare(1), Alloc()); + C c2(std::begin(a2), std::end(a2), 0, Hash(2), Compare(2), Alloc()); + c2.max_load_factor(2); + c1.swap(c2); + + assert(c1.bucket_count() >= 11); + assert(c1.size() == 8); + assert(*c1.find(10) == 10); + assert(*c1.find(20) == 20); + assert(*c1.find(30) == 30); + assert(*c1.find(40) == 40); + assert(*c1.find(50) == 50); + assert(*c1.find(60) == 60); + assert(*c1.find(70) == 70); + assert(*c1.find(80) == 80); + assert(c1.hash_function() == Hash(2)); + assert(c1.key_eq() == Compare(2)); + assert(c1.get_allocator() == Alloc()); + assert(std::distance(c1.begin(), c1.end()) == c1.size()); + assert(std::distance(c1.cbegin(), c1.cend()) == c1.size()); + assert(c1.max_load_factor() == 2); + + assert(c2.bucket_count() >= 7); + assert(c2.size() == 6); + assert(c2.count(1) == 2); + assert(c2.count(2) == 2); + assert(c2.count(3) == 1); + assert(c2.count(4) == 1); + assert(c2.hash_function() == Hash(1)); + assert(c2.key_eq() == Compare(1)); + assert(c2.get_allocator() == Alloc()); + assert(std::distance(c2.begin(), c2.end()) == c2.size()); + assert(std::distance(c2.cbegin(), c2.cend()) == c2.size()); + assert(c2.max_load_factor() == 1); + } +#endif +} diff --git a/test/std/containers/unord/unord.multiset/types.pass.cpp b/test/std/containers/unord/unord.multiset/types.pass.cpp new file mode 100644 index 000000000000..5222222d8197 --- /dev/null +++ b/test/std/containers/unord/unord.multiset/types.pass.cpp @@ -0,0 +1,69 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <unordered_set> + +// template <class Value, class Hash = hash<Value>, class Pred = equal_to<Value>, +// class Alloc = allocator<Value>> +// class unordered_multiset +// { +// public: +// // types +// typedef Value value_type; +// typedef value_type key_type; +// typedef Hash hasher; +// typedef Pred key_equal; +// typedef Alloc allocator_type; +// typedef value_type& reference; +// typedef const value_type& const_reference; +// typedef typename allocator_traits<allocator_type>::pointer pointer; +// typedef typename allocator_traits<allocator_type>::const_pointer const_pointer; +// typedef typename allocator_traits<allocator_type>::size_type size_type; +// typedef typename allocator_traits<allocator_type>::difference_type difference_type; + +#include <unordered_set> +#include <type_traits> + +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_multiset<short> C; + static_assert((std::is_same<C::value_type, short>::value), ""); + static_assert((std::is_same<C::key_type, short>::value), ""); + static_assert((std::is_same<C::hasher, std::hash<C::key_type> >::value), ""); + static_assert((std::is_same<C::key_equal, std::equal_to<C::key_type> >::value), ""); + static_assert((std::is_same<C::allocator_type, std::allocator<C::value_type> >::value), ""); + static_assert((std::is_same<C::reference, C::value_type&>::value), ""); + static_assert((std::is_same<C::const_reference, const C::value_type&>::value), ""); + static_assert((std::is_same<C::pointer, C::value_type*>::value), ""); + static_assert((std::is_same<C::const_pointer, const C::value_type*>::value), ""); + static_assert((std::is_same<C::size_type, std::size_t>::value), ""); + static_assert((std::is_same<C::difference_type, std::ptrdiff_t>::value), ""); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multiset<short, std::hash<short>, + std::equal_to<short>, min_allocator<short>> C; + static_assert((std::is_same<C::value_type, short>::value), ""); + static_assert((std::is_same<C::key_type, short>::value), ""); + static_assert((std::is_same<C::hasher, std::hash<C::key_type> >::value), ""); + static_assert((std::is_same<C::key_equal, std::equal_to<C::key_type> >::value), ""); + static_assert((std::is_same<C::allocator_type, min_allocator<C::value_type> >::value), ""); + static_assert((std::is_same<C::reference, C::value_type&>::value), ""); + static_assert((std::is_same<C::const_reference, const C::value_type&>::value), ""); + static_assert((std::is_same<C::pointer, min_pointer<C::value_type>>::value), ""); + static_assert((std::is_same<C::const_pointer, min_pointer<const C::value_type>>::value), ""); + // min_allocator doesn't have a size_type, so one gets synthesized + static_assert((std::is_same<C::size_type, std::make_unsigned<C::difference_type>::type>::value), ""); + static_assert((std::is_same<C::difference_type, std::ptrdiff_t>::value), ""); + } +#endif +} diff --git a/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/allocator.pass.cpp b/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/allocator.pass.cpp new file mode 100644 index 000000000000..ccd21a58b22c --- /dev/null +++ b/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/allocator.pass.cpp @@ -0,0 +1,109 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <unordered_set> + +// template <class Value, class Hash = hash<Value>, class Pred = equal_to<Value>, +// class Alloc = allocator<Value>> +// class unordered_multiset + +// explicit unordered_multiset(const allocator_type& __a); + +#include <unordered_set> +#include <cassert> + +#include "../../../NotConstructible.h" +#include "../../../test_compare.h" +#include "../../../test_hash.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_multiset<NotConstructible, + test_hash<std::hash<NotConstructible> >, + test_compare<std::equal_to<NotConstructible> >, + test_allocator<NotConstructible> + > C; + C c(test_allocator<NotConstructible>(10)); + assert(c.bucket_count() == 0); + assert(c.hash_function() == test_hash<std::hash<NotConstructible> >()); + assert(c.key_eq() == test_compare<std::equal_to<NotConstructible> >()); + assert(c.get_allocator() == test_allocator<NotConstructible>(10)); + 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); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multiset<NotConstructible, + test_hash<std::hash<NotConstructible> >, + test_compare<std::equal_to<NotConstructible> >, + min_allocator<NotConstructible> + > C; + C c(min_allocator<NotConstructible>{}); + assert(c.bucket_count() == 0); + assert(c.hash_function() == test_hash<std::hash<NotConstructible> >()); + assert(c.key_eq() == test_compare<std::equal_to<NotConstructible> >()); + assert(c.get_allocator() == min_allocator<NotConstructible>()); + 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); + } +#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 +} diff --git a/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/assign_copy.pass.cpp b/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/assign_copy.pass.cpp new file mode 100644 index 000000000000..2042f69fd772 --- /dev/null +++ b/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/assign_copy.pass.cpp @@ -0,0 +1,209 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <unordered_set> + +// template <class Value, class Hash = hash<Value>, class Pred = equal_to<Value>, +// class Alloc = allocator<Value>> +// class unordered_multiset + +// unordered_multiset& operator=(const unordered_multiset& u); + +#include <unordered_set> +#include <cassert> +#include <cfloat> + +#include "../../../test_compare.h" +#include "../../../test_hash.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ + { + typedef test_allocator<int> A; + typedef std::unordered_multiset<int, + test_hash<std::hash<int> >, + test_compare<std::equal_to<int> >, + A + > C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c0(a, a + sizeof(a)/sizeof(a[0]), + 7, + test_hash<std::hash<int> >(8), + test_compare<std::equal_to<int> >(9), + A(10) + ); + C c(a, a + 2, + 7, + test_hash<std::hash<int> >(2), + test_compare<std::equal_to<int> >(3), + A(4) + ); + c = c0; + assert(c.bucket_count() == 7); + assert(c.size() == 6); + C::const_iterator i = c.cbegin(); + assert(*i == 1); + ++i; + assert(*i == 1); + ++i; + assert(*i == 2); + ++i; + assert(*i == 2); + ++i; + assert(*i == 3); + ++i; + assert(*i == 4); + assert(c.hash_function() == test_hash<std::hash<int> >(8)); + assert(c.key_eq() == test_compare<std::equal_to<int> >(9)); + assert(c.get_allocator() == A(4)); + 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::unordered_multiset<int> C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c(a, a + sizeof(a)/sizeof(a[0])); + C *p = &c; + c = *p; + + assert(c.size() == 6); + assert(std::is_permutation(c.begin(), c.end(), a)); + } + { + typedef other_allocator<int> A; + typedef std::unordered_multiset<int, + test_hash<std::hash<int> >, + test_compare<std::equal_to<int> >, + A + > C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c0(a, a + sizeof(a)/sizeof(a[0]), + 7, + test_hash<std::hash<int> >(8), + test_compare<std::equal_to<int> >(9), + A(10) + ); + C c(a, a + 2, + 7, + test_hash<std::hash<int> >(2), + test_compare<std::equal_to<int> >(3), + A(4) + ); + c = c0; + assert(c.bucket_count() >= 7); + assert(c.size() == 6); + C::const_iterator i = c.cbegin(); + assert(*i == 1); + ++i; + assert(*i == 1); + ++i; + assert(*i == 2); + ++i; + assert(*i == 2); + ++i; + assert(*i == 3); + ++i; + assert(*i == 4); + assert(c.hash_function() == test_hash<std::hash<int> >(8)); + assert(c.key_eq() == test_compare<std::equal_to<int> >(9)); + assert(c.get_allocator() == A(10)); + 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); + } +#if __cplusplus >= 201103L + { + typedef min_allocator<int> A; + typedef std::unordered_multiset<int, + test_hash<std::hash<int> >, + test_compare<std::equal_to<int> >, + A + > C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c0(a, a + sizeof(a)/sizeof(a[0]), + 7, + test_hash<std::hash<int> >(8), + test_compare<std::equal_to<int> >(9), + A() + ); + C c(a, a + 2, + 7, + test_hash<std::hash<int> >(2), + test_compare<std::equal_to<int> >(3), + A() + ); + c = c0; + assert(c.bucket_count() == 7); + assert(c.size() == 6); + C::const_iterator i = c.cbegin(); + assert(*i == 1); + ++i; + assert(*i == 1); + ++i; + assert(*i == 2); + ++i; + assert(*i == 2); + ++i; + assert(*i == 3); + ++i; + assert(*i == 4); + assert(c.hash_function() == test_hash<std::hash<int> >(8)); + assert(c.key_eq() == test_compare<std::equal_to<int> >(9)); + 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 +} diff --git a/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/assign_init.pass.cpp b/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/assign_init.pass.cpp new file mode 100644 index 000000000000..4eaf2c5779f3 --- /dev/null +++ b/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/assign_init.pass.cpp @@ -0,0 +1,97 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <unordered_set> + +// template <class Value, class Hash = hash<Value>, class Pred = equal_to<Value>, +// class Alloc = allocator<Value>> +// class unordered_multiset + +// unordered_multiset& operator=(initializer_list<value_type> il); + +#include <unordered_set> +#include <cassert> +#include <cfloat> + +#include "../../../test_compare.h" +#include "../../../test_hash.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + typedef test_allocator<int> A; + typedef std::unordered_multiset<int, + test_hash<std::hash<int> >, + test_compare<std::equal_to<int> >, + A + > C; + typedef int P; + C c = { + P(4), + P(1), + P(2) + }; + c = { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + assert(c.bucket_count() >= 7); + 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(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); + } +#if __cplusplus >= 201103L + { + typedef min_allocator<int> A; + typedef std::unordered_multiset<int, + test_hash<std::hash<int> >, + test_compare<std::equal_to<int> >, + A + > C; + typedef int P; + C c = { + P(4), + P(1), + P(2) + }; + c = { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + assert(c.bucket_count() >= 7); + 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(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 // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/assign_move.pass.cpp b/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/assign_move.pass.cpp new file mode 100644 index 000000000000..4b0e52c5930c --- /dev/null +++ b/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/assign_move.pass.cpp @@ -0,0 +1,286 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <unordered_set> + +// template <class Value, class Hash = hash<Value>, class Pred = equal_to<Value>, +// class Alloc = allocator<Value>> +// class unordered_multiset + +// unordered_multiset& operator=(unordered_multiset&& u); + +#include <unordered_set> +#include <cassert> +#include <cfloat> + +#include "../../../test_compare.h" +#include "../../../test_hash.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + typedef test_allocator<int> A; + typedef std::unordered_multiset<int, + test_hash<std::hash<int> >, + test_compare<std::equal_to<int> >, + A + > C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c0(a, a + sizeof(a)/sizeof(a[0]), + 7, + test_hash<std::hash<int> >(8), + test_compare<std::equal_to<int> >(9), + A(10) + ); + C c(a, a + 2, + 7, + test_hash<std::hash<int> >(2), + test_compare<std::equal_to<int> >(3), + A(4) + ); + c = std::move(c0); + assert(c.bucket_count() == 7); + assert(c.size() == 6); + C::const_iterator i = c.cbegin(); + assert(*i == 1); + ++i; + assert(*i == 1); + ++i; + assert(*i == 2); + ++i; + assert(*i == 2); + ++i; + assert(*i == 3); + ++i; + assert(*i == 4); + assert(c.hash_function() == test_hash<std::hash<int> >(8)); + assert(c.key_eq() == test_compare<std::equal_to<int> >(9)); + assert(c.get_allocator() == A(4)); + 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 test_allocator<int> A; + typedef std::unordered_multiset<int, + test_hash<std::hash<int> >, + test_compare<std::equal_to<int> >, + A + > C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c0(a, a + sizeof(a)/sizeof(a[0]), + 7, + test_hash<std::hash<int> >(8), + test_compare<std::equal_to<int> >(9), + A(10) + ); + C c(a, a + 2, + 7, + test_hash<std::hash<int> >(2), + test_compare<std::equal_to<int> >(3), + A(10) + ); + c = std::move(c0); + assert(c.bucket_count() == 7); + 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() == test_hash<std::hash<int> >(8)); + assert(c.key_eq() == test_compare<std::equal_to<int> >(9)); + assert(c.get_allocator() == A(10)); + 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 other_allocator<int> A; + typedef std::unordered_multiset<int, + test_hash<std::hash<int> >, + test_compare<std::equal_to<int> >, + A + > C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c0(a, a + sizeof(a)/sizeof(a[0]), + 7, + test_hash<std::hash<int> >(8), + test_compare<std::equal_to<int> >(9), + A(10) + ); + C c(a, a + 2, + 7, + test_hash<std::hash<int> >(2), + test_compare<std::equal_to<int> >(3), + A(4) + ); + c = std::move(c0); + assert(c.bucket_count() == 7); + 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() == test_hash<std::hash<int> >(8)); + assert(c.key_eq() == test_compare<std::equal_to<int> >(9)); + assert(c.get_allocator() == A(10)); + 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); + } +#if __cplusplus >= 201103L + { + typedef test_allocator<int> A; + typedef std::unordered_multiset<int, + test_hash<std::hash<int> >, + test_compare<std::equal_to<int> >, + A + > C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c0(a, a + sizeof(a)/sizeof(a[0]), + 7, + test_hash<std::hash<int> >(8), + test_compare<std::equal_to<int> >(9), + A() + ); + C c(a, a + 2, + 7, + test_hash<std::hash<int> >(2), + test_compare<std::equal_to<int> >(3), + A() + ); + c = std::move(c0); + assert(c.bucket_count() == 7); + assert(c.size() == 6); + C::const_iterator i = c.cbegin(); + assert(*i == 4); + ++i; + assert(*i == 3); + ++i; + assert(*i == 2); + ++i; + assert(*i == 2); + ++i; + assert(*i == 1); + ++i; + assert(*i == 1); + assert(c.hash_function() == test_hash<std::hash<int> >(8)); + assert(c.key_eq() == test_compare<std::equal_to<int> >(9)); + 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 min_allocator<int> A; + typedef std::unordered_multiset<int, + test_hash<std::hash<int> >, + test_compare<std::equal_to<int> >, + A + > C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c0(a, a + sizeof(a)/sizeof(a[0]), + 7, + test_hash<std::hash<int> >(8), + test_compare<std::equal_to<int> >(9), + A() + ); + C c(a, a + 2, + 7, + test_hash<std::hash<int> >(2), + test_compare<std::equal_to<int> >(3), + A() + ); + c = std::move(c0); + assert(c.bucket_count() == 7); + 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() == test_hash<std::hash<int> >(8)); + assert(c.key_eq() == test_compare<std::equal_to<int> >(9)); + 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 +#if _LIBCPP_DEBUG >= 1 + { + std::unordered_multiset<int> s1 = {1, 2, 3}; + std::unordered_multiset<int>::iterator i = s1.begin(); + int k = *i; + std::unordered_multiset<int> s2; + s2 = std::move(s1); + assert(*i == k); + s2.erase(i); + assert(s2.size() == 2); + } +#endif +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/copy.pass.cpp b/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/copy.pass.cpp new file mode 100644 index 000000000000..94241830a06c --- /dev/null +++ b/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/copy.pass.cpp @@ -0,0 +1,171 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <unordered_set> + +// template <class Value, class Hash = hash<Value>, class Pred = equal_to<Value>, +// class Alloc = allocator<Value>> +// class unordered_multiset + +// unordered_multiset(const unordered_multiset& u); + +#include <unordered_set> +#include <cassert> +#include <cfloat> + +#include "../../../test_compare.h" +#include "../../../test_hash.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_multiset<int, + test_hash<std::hash<int> >, + test_compare<std::equal_to<int> >, + test_allocator<int> + > C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c0(a, a + sizeof(a)/sizeof(a[0]), + 7, + test_hash<std::hash<int> >(8), + test_compare<std::equal_to<int> >(9), + test_allocator<int>(10) + ); + C c = c0; + assert(c.bucket_count() == 7); + assert(c.size() == 6); + C::const_iterator i = c.cbegin(); + assert(*i == 1); + ++i; + assert(*i == 1); + ++i; + assert(*i == 2); + ++i; + assert(*i == 2); + ++i; + assert(*i == 3); + ++i; + assert(*i == 4); + assert(c.hash_function() == test_hash<std::hash<int> >(8)); + assert(c.key_eq() == test_compare<std::equal_to<int> >(9)); + assert(c.get_allocator() == test_allocator<int>(10)); + 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); + } +#ifndef _LIBCPP_HAS_NO_ADVANCED_SFINAE + { + typedef std::unordered_multiset<int, + test_hash<std::hash<int> >, + test_compare<std::equal_to<int> >, + other_allocator<int> + > C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c0(a, a + sizeof(a)/sizeof(a[0]), + 7, + test_hash<std::hash<int> >(8), + test_compare<std::equal_to<int> >(9), + other_allocator<int>(10) + ); + C c = c0; + assert(c.bucket_count() == 7); + assert(c.size() == 6); + C::const_iterator i = c.cbegin(); + assert(*i == 1); + ++i; + assert(*i == 1); + ++i; + assert(*i == 2); + ++i; + assert(*i == 2); + ++i; + assert(*i == 3); + ++i; + assert(*i == 4); + assert(c.hash_function() == test_hash<std::hash<int> >(8)); + assert(c.key_eq() == test_compare<std::equal_to<int> >(9)); + assert(c.get_allocator() == other_allocator<int>(-2)); + 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 // _LIBCPP_HAS_NO_ADVANCED_SFINAE +#if __cplusplus >= 201103L + { + typedef std::unordered_multiset<int, + test_hash<std::hash<int> >, + test_compare<std::equal_to<int> >, + min_allocator<int> + > C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c0(a, a + sizeof(a)/sizeof(a[0]), + 7, + test_hash<std::hash<int> >(8), + test_compare<std::equal_to<int> >(9), + min_allocator<int>() + ); + C c = c0; + assert(c.bucket_count() == 7); + assert(c.size() == 6); + C::const_iterator i = c.cbegin(); + assert(*i == 1); + ++i; + assert(*i == 1); + ++i; + assert(*i == 2); + ++i; + assert(*i == 2); + ++i; + assert(*i == 3); + ++i; + assert(*i == 4); + assert(c.hash_function() == test_hash<std::hash<int> >(8)); + assert(c.key_eq() == test_compare<std::equal_to<int> >(9)); + assert(c.get_allocator() == min_allocator<int>()); + 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 +} diff --git a/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/copy_alloc.pass.cpp b/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/copy_alloc.pass.cpp new file mode 100644 index 000000000000..22e372bb3ad1 --- /dev/null +++ b/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/copy_alloc.pass.cpp @@ -0,0 +1,123 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <unordered_set> + +// template <class Value, class Hash = hash<Value>, class Pred = equal_to<Value>, +// class Alloc = allocator<Value>> +// class unordered_multiset + +// unordered_multiset(const unordered_multiset& u, const allocator_type& a); + +#include <unordered_set> +#include <cassert> +#include <cfloat> + +#include "../../../test_compare.h" +#include "../../../test_hash.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_multiset<int, + test_hash<std::hash<int> >, + test_compare<std::equal_to<int> >, + test_allocator<int> + > C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c0(a, a + sizeof(a)/sizeof(a[0]), + 7, + test_hash<std::hash<int> >(8), + test_compare<std::equal_to<int> >(9), + test_allocator<int>(10) + ); + C c(c0, test_allocator<int>(5)); + assert(c.bucket_count() == 7); + assert(c.size() == 6); + C::const_iterator i = c.cbegin(); + assert(*i == 1); + ++i; + assert(*i == 1); + ++i; + assert(*i == 2); + ++i; + assert(*i == 2); + ++i; + assert(*i == 3); + ++i; + assert(*i == 4); + assert(c.hash_function() == test_hash<std::hash<int> >(8)); + assert(c.key_eq() == test_compare<std::equal_to<int> >(9)); + assert(c.get_allocator() == test_allocator<int>(5)); + 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); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multiset<int, + test_hash<std::hash<int> >, + test_compare<std::equal_to<int> >, + min_allocator<int> + > C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c0(a, a + sizeof(a)/sizeof(a[0]), + 7, + test_hash<std::hash<int> >(8), + test_compare<std::equal_to<int> >(9), + min_allocator<int>() + ); + C c(c0, min_allocator<int>()); + assert(c.bucket_count() == 7); + assert(c.size() == 6); + C::const_iterator i = c.cbegin(); + assert(*i == 1); + ++i; + assert(*i == 1); + ++i; + assert(*i == 2); + ++i; + assert(*i == 2); + ++i; + assert(*i == 3); + ++i; + assert(*i == 4); + assert(c.hash_function() == test_hash<std::hash<int> >(8)); + assert(c.key_eq() == test_compare<std::equal_to<int> >(9)); + assert(c.get_allocator() == min_allocator<int>()); + 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 +} diff --git a/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/default.pass.cpp b/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/default.pass.cpp new file mode 100644 index 000000000000..737ae2dae793 --- /dev/null +++ b/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/default.pass.cpp @@ -0,0 +1,74 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <unordered_set> + +// template <class Value, class Hash = hash<Value>, class Pred = equal_to<Value>, +// class Alloc = allocator<Value>> +// class unordered_multiset + +// unordered_multiset(); + +#include <unordered_set> +#include <cassert> + +#include "../../../NotConstructible.h" +#include "../../../test_compare.h" +#include "../../../test_hash.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_multiset<NotConstructible, + test_hash<std::hash<NotConstructible> >, + test_compare<std::equal_to<NotConstructible> >, + test_allocator<NotConstructible> + > C; + C c; + assert(c.bucket_count() == 0); + assert(c.hash_function() == test_hash<std::hash<NotConstructible> >()); + assert(c.key_eq() == test_compare<std::equal_to<NotConstructible> >()); + assert(c.get_allocator() == (test_allocator<NotConstructible>())); + 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); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multiset<NotConstructible, + test_hash<std::hash<NotConstructible> >, + test_compare<std::equal_to<NotConstructible> >, + min_allocator<NotConstructible> + > C; + C c; + assert(c.bucket_count() == 0); + assert(c.hash_function() == test_hash<std::hash<NotConstructible> >()); + assert(c.key_eq() == test_compare<std::equal_to<NotConstructible> >()); + assert(c.get_allocator() == (min_allocator<NotConstructible>())); + 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); + } + { + std::unordered_multiset<int> c = {}; + assert(c.bucket_count() == 0); + 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 +} diff --git a/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/default_noexcept.pass.cpp b/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/default_noexcept.pass.cpp new file mode 100644 index 000000000000..391609fd144a --- /dev/null +++ b/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/default_noexcept.pass.cpp @@ -0,0 +1,70 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <unordered_set> + +// unordered_multiset() +// noexcept( +// is_nothrow_default_constructible<allocator_type>::value && +// is_nothrow_default_constructible<key_compare>::value && +// is_nothrow_copy_constructible<key_compare>::value); + +// This tests a conforming extension + +#include <unordered_set> +#include <cassert> + +#include "MoveOnly.h" +#include "test_allocator.h" +#include "../../../test_hash.h" + +template <class T> +struct some_comp +{ + typedef T value_type; + some_comp(); + some_comp(const some_comp&); +}; + +template <class T> +struct some_hash +{ + typedef T value_type; + some_hash(); + some_hash(const some_hash&); +}; + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::unordered_multiset<MoveOnly> C; + static_assert(std::is_nothrow_default_constructible<C>::value, ""); + } + { + typedef std::unordered_multiset<MoveOnly, std::hash<MoveOnly>, + std::equal_to<MoveOnly>, test_allocator<MoveOnly>> C; + static_assert(std::is_nothrow_default_constructible<C>::value, ""); + } + { + typedef std::unordered_multiset<MoveOnly, std::hash<MoveOnly>, + std::equal_to<MoveOnly>, other_allocator<MoveOnly>> C; + static_assert(!std::is_nothrow_default_constructible<C>::value, ""); + } + { + typedef std::unordered_multiset<MoveOnly, some_hash<MoveOnly>> C; + static_assert(!std::is_nothrow_default_constructible<C>::value, ""); + } + { + typedef std::unordered_multiset<MoveOnly, std::hash<MoveOnly>, + some_comp<MoveOnly>> C; + static_assert(!std::is_nothrow_default_constructible<C>::value, ""); + } +#endif +} diff --git a/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/dtor_noexcept.pass.cpp b/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/dtor_noexcept.pass.cpp new file mode 100644 index 000000000000..a549288afc14 --- /dev/null +++ b/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/dtor_noexcept.pass.cpp @@ -0,0 +1,67 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <unordered_set> + +// ~unordered_multiset() // implied noexcept; + +#include <unordered_set> +#include <cassert> + +#include "MoveOnly.h" +#include "test_allocator.h" + +#if __has_feature(cxx_noexcept) + +template <class T> +struct some_comp +{ + typedef T value_type; + ~some_comp() noexcept(false); +}; + +template <class T> +struct some_hash +{ + typedef T value_type; + some_hash(); + some_hash(const some_hash&); + ~some_hash() noexcept(false); +}; + +#endif + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::unordered_multiset<MoveOnly> C; + static_assert(std::is_nothrow_destructible<C>::value, ""); + } + { + typedef std::unordered_multiset<MoveOnly, std::hash<MoveOnly>, + std::equal_to<MoveOnly>, test_allocator<MoveOnly>> C; + static_assert(std::is_nothrow_destructible<C>::value, ""); + } + { + typedef std::unordered_multiset<MoveOnly, std::hash<MoveOnly>, + std::equal_to<MoveOnly>, other_allocator<MoveOnly>> C; + static_assert(std::is_nothrow_destructible<C>::value, ""); + } + { + typedef std::unordered_multiset<MoveOnly, some_hash<MoveOnly>> C; + static_assert(!std::is_nothrow_destructible<C>::value, ""); + } + { + typedef std::unordered_multiset<MoveOnly, std::hash<MoveOnly>, + some_comp<MoveOnly>> C; + static_assert(!std::is_nothrow_destructible<C>::value, ""); + } +#endif +} diff --git a/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/init.pass.cpp b/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/init.pass.cpp new file mode 100644 index 000000000000..416c28cf83db --- /dev/null +++ b/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/init.pass.cpp @@ -0,0 +1,163 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <unordered_set> + +// template <class Value, class Hash = hash<Value>, class Pred = equal_to<Value>, +// class Alloc = allocator<Value>> +// class unordered_multiset + +// unordered_multiset(initializer_list<value_type> il); + +#include <unordered_set> +#include <cassert> +#include <cfloat> + +#include "../../../test_compare.h" +#include "../../../test_hash.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + typedef std::unordered_multiset<int, + test_hash<std::hash<int> >, + test_compare<std::equal_to<int> >, + test_allocator<int> + > C; + typedef int P; + C c = { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + assert(c.bucket_count() >= 7); + 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() == test_hash<std::hash<int> >()); + assert(c.key_eq() == test_compare<std::equal_to<int> >()); + assert(c.get_allocator() == test_allocator<int>()); + 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); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multiset<int, + test_hash<std::hash<int> >, + test_compare<std::equal_to<int> >, + min_allocator<int> + > C; + typedef int P; + C c = { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + assert(c.bucket_count() >= 7); + 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() == test_hash<std::hash<int> >()); + assert(c.key_eq() == test_compare<std::equal_to<int> >()); + assert(c.get_allocator() == min_allocator<int>()); + 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); + } +#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 +} diff --git a/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/init_size.pass.cpp b/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/init_size.pass.cpp new file mode 100644 index 000000000000..a6543a0e6f46 --- /dev/null +++ b/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/init_size.pass.cpp @@ -0,0 +1,97 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <unordered_set> + +// template <class Value, class Hash = hash<Value>, class Pred = equal_to<Value>, +// class Alloc = allocator<Value>> +// class unordered_multiset + +// unordered_multiset(initializer_list<value_type> il, size_type n); + +#include <unordered_set> +#include <cassert> +#include <cfloat> + +#include "../../../test_compare.h" +#include "../../../test_hash.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + typedef std::unordered_multiset<int, + test_hash<std::hash<int> >, + test_compare<std::equal_to<int> >, + test_allocator<int> + > C; + typedef int P; + C c({ + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }, + 7 + ); + assert(c.bucket_count() == 7); + 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() == test_hash<std::hash<int> >()); + assert(c.key_eq() == test_compare<std::equal_to<int> >()); + assert(c.get_allocator() == test_allocator<int>()); + 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); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multiset<int, + test_hash<std::hash<int> >, + test_compare<std::equal_to<int> >, + min_allocator<int> + > C; + typedef int P; + C c({ + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }, + 7 + ); + assert(c.bucket_count() == 7); + 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() == test_hash<std::hash<int> >()); + assert(c.key_eq() == test_compare<std::equal_to<int> >()); + assert(c.get_allocator() == min_allocator<int>()); + 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 // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/init_size_hash.pass.cpp b/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/init_size_hash.pass.cpp new file mode 100644 index 000000000000..7d0f37163a1f --- /dev/null +++ b/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/init_size_hash.pass.cpp @@ -0,0 +1,100 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <unordered_set> + +// template <class Value, class Hash = hash<Value>, class Pred = equal_to<Value>, +// class Alloc = allocator<Value>> +// class unordered_multiset + +// unordered_multiset(initializer_list<value_type> il, size_type n, +// const hasher& hf); + +#include <unordered_set> +#include <cassert> +#include <cfloat> + +#include "../../../test_compare.h" +#include "../../../test_hash.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + typedef std::unordered_multiset<int, + test_hash<std::hash<int> >, + test_compare<std::equal_to<int> >, + test_allocator<int> + > C; + typedef int P; + C c({ + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }, + 7, + test_hash<std::hash<int> >(8) + ); + assert(c.bucket_count() == 7); + 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() == test_hash<std::hash<int> >(8)); + assert(c.key_eq() == test_compare<std::equal_to<int> >()); + assert(c.get_allocator() == test_allocator<int>()); + 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); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multiset<int, + test_hash<std::hash<int> >, + test_compare<std::equal_to<int> >, + min_allocator<int> + > C; + typedef int P; + C c({ + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }, + 7, + test_hash<std::hash<int> >(8) + ); + assert(c.bucket_count() == 7); + 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() == test_hash<std::hash<int> >(8)); + assert(c.key_eq() == test_compare<std::equal_to<int> >()); + assert(c.get_allocator() == min_allocator<int>()); + 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 // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/init_size_hash_equal.pass.cpp b/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/init_size_hash_equal.pass.cpp new file mode 100644 index 000000000000..cd013f9554ae --- /dev/null +++ b/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/init_size_hash_equal.pass.cpp @@ -0,0 +1,102 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <unordered_set> + +// template <class Value, class Hash = hash<Value>, class Pred = equal_to<Value>, +// class Alloc = allocator<Value>> +// class unordered_multiset + +// unordered_multiset(initializer_list<value_type> il, size_type n, +// const hasher& hf, const key_equal& eql); + +#include <unordered_set> +#include <cassert> +#include <cfloat> + +#include "../../../test_compare.h" +#include "../../../test_hash.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + typedef std::unordered_multiset<int, + test_hash<std::hash<int> >, + test_compare<std::equal_to<int> >, + test_allocator<int> + > C; + typedef int P; + C c({ + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }, + 7, + test_hash<std::hash<int> >(8), + test_compare<std::equal_to<int> >(9) + ); + assert(c.bucket_count() == 7); + 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() == test_hash<std::hash<int> >(8)); + assert(c.key_eq() == test_compare<std::equal_to<int> >(9)); + assert(c.get_allocator() == test_allocator<int>()); + 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); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multiset<int, + test_hash<std::hash<int> >, + test_compare<std::equal_to<int> >, + min_allocator<int> + > C; + typedef int P; + C c({ + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }, + 7, + test_hash<std::hash<int> >(8), + test_compare<std::equal_to<int> >(9) + ); + assert(c.bucket_count() == 7); + 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() == test_hash<std::hash<int> >(8)); + assert(c.key_eq() == test_compare<std::equal_to<int> >(9)); + assert(c.get_allocator() == min_allocator<int>()); + 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 // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/init_size_hash_equal_allocator.pass.cpp b/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/init_size_hash_equal_allocator.pass.cpp new file mode 100644 index 000000000000..4621c7fbb3ff --- /dev/null +++ b/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/init_size_hash_equal_allocator.pass.cpp @@ -0,0 +1,104 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <unordered_set> + +// template <class Value, class Hash = hash<Value>, class Pred = equal_to<Value>, +// class Alloc = allocator<Value>> +// class unordered_multiset + +// unordered_multiset(initializer_list<value_type> il, size_type n, +// const hasher& hf, const key_equal& eql, const allocator_type& a); + +#include <unordered_set> +#include <cassert> +#include <cfloat> + +#include "../../../test_compare.h" +#include "../../../test_hash.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + typedef std::unordered_multiset<int, + test_hash<std::hash<int> >, + test_compare<std::equal_to<int> >, + test_allocator<int> + > C; + typedef int P; + C c({ + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }, + 7, + test_hash<std::hash<int> >(8), + test_compare<std::equal_to<int> >(9), + test_allocator<int>(10) + ); + assert(c.bucket_count() == 7); + 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() == test_hash<std::hash<int> >(8)); + assert(c.key_eq() == test_compare<std::equal_to<int> >(9)); + assert(c.get_allocator() == test_allocator<int>(10)); + 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); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multiset<int, + test_hash<std::hash<int> >, + test_compare<std::equal_to<int> >, + min_allocator<int> + > C; + typedef int P; + C c({ + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }, + 7, + test_hash<std::hash<int> >(8), + test_compare<std::equal_to<int> >(9), + min_allocator<int>() + ); + assert(c.bucket_count() == 7); + 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() == test_hash<std::hash<int> >(8)); + assert(c.key_eq() == test_compare<std::equal_to<int> >(9)); + assert(c.get_allocator() == min_allocator<int>()); + 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 // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/move.pass.cpp b/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/move.pass.cpp new file mode 100644 index 000000000000..a68cfe8cd3bb --- /dev/null +++ b/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/move.pass.cpp @@ -0,0 +1,194 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <unordered_set> + +// template <class Value, class Hash = hash<Value>, class Pred = equal_to<Value>, +// class Alloc = allocator<Value>> +// class unordered_multiset + +// unordered_multiset(unordered_multiset&& u); + +#include <unordered_set> +#include <cassert> +#include <cfloat> + +#include "../../../test_compare.h" +#include "../../../test_hash.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + typedef std::unordered_multiset<int, + test_hash<std::hash<int> >, + test_compare<std::equal_to<int> >, + test_allocator<int> + > C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c0(7, + test_hash<std::hash<int> >(8), + test_compare<std::equal_to<int> >(9), + test_allocator<int>(10) + ); + C c = std::move(c0); + assert(c.bucket_count() == 7); + assert(c.size() == 0); + assert(c.hash_function() == test_hash<std::hash<int> >(8)); + assert(c.key_eq() == test_compare<std::equal_to<int> >(9)); + assert(c.get_allocator() == test_allocator<int>(10)); + assert(c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(c.load_factor() == 0); + assert(c.max_load_factor() == 1); + + assert(c0.empty()); + } + { + typedef std::unordered_multiset<int, + test_hash<std::hash<int> >, + test_compare<std::equal_to<int> >, + test_allocator<int> + > C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c0(a, a + sizeof(a)/sizeof(a[0]), + 7, + test_hash<std::hash<int> >(8), + test_compare<std::equal_to<int> >(9), + test_allocator<int>(10) + ); + C c = std::move(c0); + assert(c.bucket_count() == 7); + 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() == test_hash<std::hash<int> >(8)); + assert(c.key_eq() == test_compare<std::equal_to<int> >(9)); + assert(c.get_allocator() == test_allocator<int>(10)); + 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); + + assert(c0.empty()); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multiset<int, + test_hash<std::hash<int> >, + test_compare<std::equal_to<int> >, + min_allocator<int> + > C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c0(7, + test_hash<std::hash<int> >(8), + test_compare<std::equal_to<int> >(9), + min_allocator<int>() + ); + C c = std::move(c0); + assert(c.bucket_count() == 7); + assert(c.size() == 0); + assert(c.hash_function() == test_hash<std::hash<int> >(8)); + assert(c.key_eq() == test_compare<std::equal_to<int> >(9)); + assert(c.get_allocator() == min_allocator<int>()); + assert(c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(c.load_factor() == 0); + assert(c.max_load_factor() == 1); + + assert(c0.empty()); + } + { + typedef std::unordered_multiset<int, + test_hash<std::hash<int> >, + test_compare<std::equal_to<int> >, + min_allocator<int> + > C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c0(a, a + sizeof(a)/sizeof(a[0]), + 7, + test_hash<std::hash<int> >(8), + test_compare<std::equal_to<int> >(9), + min_allocator<int>() + ); + C c = std::move(c0); + assert(c.bucket_count() == 7); + 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() == test_hash<std::hash<int> >(8)); + assert(c.key_eq() == test_compare<std::equal_to<int> >(9)); + assert(c.get_allocator() == min_allocator<int>()); + 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); + + assert(c0.empty()); + } +#endif +#if _LIBCPP_DEBUG >= 1 + { + std::unordered_multiset<int> s1 = {1, 2, 3}; + std::unordered_multiset<int>::iterator i = s1.begin(); + int k = *i; + std::unordered_multiset<int> s2 = std::move(s1); + assert(*i == k); + s2.erase(i); + assert(s2.size() == 2); + } +#endif +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/move_alloc.pass.cpp b/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/move_alloc.pass.cpp new file mode 100644 index 000000000000..9eee69a58e5d --- /dev/null +++ b/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/move_alloc.pass.cpp @@ -0,0 +1,213 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <unordered_set> + +// template <class Value, class Hash = hash<Value>, class Pred = equal_to<Value>, +// class Alloc = allocator<Value>> +// class unordered_multiset + +// unordered_multiset(unordered_multiset&& u, const allocator_type& a); + +#include <unordered_set> +#include <cassert> +#include <cfloat> + +#include "../../../test_compare.h" +#include "../../../test_hash.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + typedef int P; + typedef test_allocator<int> A; + typedef std::unordered_multiset<int, + test_hash<std::hash<int> >, + test_compare<std::equal_to<int> >, + A + > C; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c0(a, a + sizeof(a)/sizeof(a[0]), + 7, + test_hash<std::hash<int> >(8), + test_compare<std::equal_to<int> >(9), + A(10) + ); + C c(std::move(c0), A(12)); + assert(c.bucket_count() >= 7); + assert(c.size() == 6); + C::const_iterator i = c.cbegin(); + assert(*i == 1); + ++i; + assert(*i == 1); + ++i; + assert(*i == 2); + ++i; + assert(*i == 2); + ++i; + assert(*i == 3); + ++i; + assert(*i == 4); + assert(c.hash_function() == test_hash<std::hash<int> >(8)); + assert(c.key_eq() == test_compare<std::equal_to<int> >(9)); + assert(c.get_allocator() == A(12)); + 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); + + assert(c0.empty()); + } + { + typedef int P; + typedef test_allocator<int> A; + typedef std::unordered_multiset<int, + test_hash<std::hash<int> >, + test_compare<std::equal_to<int> >, + A + > C; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c0(a, a + sizeof(a)/sizeof(a[0]), + 7, + test_hash<std::hash<int> >(8), + test_compare<std::equal_to<int> >(9), + A(10) + ); + C c(std::move(c0), A(10)); + assert(c.bucket_count() == 7); + 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() == test_hash<std::hash<int> >(8)); + assert(c.key_eq() == test_compare<std::equal_to<int> >(9)); + assert(c.get_allocator() == A(10)); + 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); + + assert(c0.empty()); + } +#if __cplusplus >= 201103L + { + typedef int P; + typedef min_allocator<int> A; + typedef std::unordered_multiset<int, + test_hash<std::hash<int> >, + test_compare<std::equal_to<int> >, + A + > C; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c0(a, a + sizeof(a)/sizeof(a[0]), + 7, + test_hash<std::hash<int> >(8), + test_compare<std::equal_to<int> >(9), + A() + ); + C c(std::move(c0), A()); + assert(c.bucket_count() >= 7); + assert(c.size() == 6); + C::const_iterator i = c.cbegin(); + assert(*i == 4); + ++i; + assert(*i == 3); + ++i; + assert(*i == 2); + ++i; + assert(*i == 2); + ++i; + assert(*i == 1); + ++i; + assert(*i == 1); + assert(c.hash_function() == test_hash<std::hash<int> >(8)); + assert(c.key_eq() == test_compare<std::equal_to<int> >(9)); + 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); + + assert(c0.empty()); + } + { + typedef int P; + typedef min_allocator<int> A; + typedef std::unordered_multiset<int, + test_hash<std::hash<int> >, + test_compare<std::equal_to<int> >, + A + > C; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c0(a, a + sizeof(a)/sizeof(a[0]), + 7, + test_hash<std::hash<int> >(8), + test_compare<std::equal_to<int> >(9), + A() + ); + C c(std::move(c0), A()); + assert(c.bucket_count() == 7); + 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() == test_hash<std::hash<int> >(8)); + assert(c.key_eq() == test_compare<std::equal_to<int> >(9)); + 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); + + assert(c0.empty()); + } +#endif +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/move_assign_noexcept.pass.cpp b/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/move_assign_noexcept.pass.cpp new file mode 100644 index 000000000000..2f86f018d9fe --- /dev/null +++ b/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/move_assign_noexcept.pass.cpp @@ -0,0 +1,69 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <unordered_set> + +// unordered_multiset& operator=(unordered_multiset&& c) +// noexcept( +// allocator_type::propagate_on_container_move_assignment::value && +// is_nothrow_move_assignable<allocator_type>::value && +// is_nothrow_move_assignable<key_compare>::value); + +// This tests a conforming extension + +#include <unordered_set> +#include <cassert> + +#include "MoveOnly.h" +#include "test_allocator.h" + +template <class T> +struct some_comp +{ + typedef T value_type; + some_comp& operator=(const some_comp&); +}; + +template <class T> +struct some_hash +{ + typedef T value_type; + some_hash(); + some_hash(const some_hash&); + some_hash& operator=(const some_hash&); +}; + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::unordered_multiset<MoveOnly> C; + static_assert(std::is_nothrow_move_assignable<C>::value, ""); + } + { + typedef std::unordered_multiset<MoveOnly, std::hash<MoveOnly>, + std::equal_to<MoveOnly>, test_allocator<MoveOnly>> C; + static_assert(!std::is_nothrow_move_assignable<C>::value, ""); + } + { + typedef std::unordered_multiset<MoveOnly, std::hash<MoveOnly>, + std::equal_to<MoveOnly>, other_allocator<MoveOnly>> C; + static_assert(std::is_nothrow_move_assignable<C>::value, ""); + } + { + typedef std::unordered_multiset<MoveOnly, some_hash<MoveOnly>> C; + static_assert(!std::is_nothrow_move_assignable<C>::value, ""); + } + { + typedef std::unordered_multiset<MoveOnly, std::hash<MoveOnly>, + some_comp<MoveOnly>> C; + static_assert(!std::is_nothrow_move_assignable<C>::value, ""); + } +#endif +} diff --git a/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/move_noexcept.pass.cpp b/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/move_noexcept.pass.cpp new file mode 100644 index 000000000000..8a4c3c945364 --- /dev/null +++ b/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/move_noexcept.pass.cpp @@ -0,0 +1,66 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <unordered_set> + +// unordered_multiset(unordered_multiset&&) +// noexcept(is_nothrow_move_constructible<allocator_type>::value && +// is_nothrow_move_constructible<key_compare>::value); + +// This tests a conforming extension + +#include <unordered_set> +#include <cassert> + +#include "MoveOnly.h" +#include "test_allocator.h" + +template <class T> +struct some_comp +{ + typedef T value_type; + some_comp(const some_comp&); +}; + +template <class T> +struct some_hash +{ + typedef T value_type; + some_hash(); + some_hash(const some_hash&); +}; + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::unordered_multiset<MoveOnly> C; + static_assert(std::is_nothrow_move_constructible<C>::value, ""); + } + { + typedef std::unordered_multiset<MoveOnly, std::hash<MoveOnly>, + std::equal_to<MoveOnly>, test_allocator<MoveOnly>> C; + static_assert(std::is_nothrow_move_constructible<C>::value, ""); + } + { + typedef std::unordered_multiset<MoveOnly, std::hash<MoveOnly>, + std::equal_to<MoveOnly>, other_allocator<MoveOnly>> C; + static_assert(std::is_nothrow_move_constructible<C>::value, ""); + } + { + typedef std::unordered_multiset<MoveOnly, some_hash<MoveOnly>> C; + static_assert(!std::is_nothrow_move_constructible<C>::value, ""); + } + { + typedef std::unordered_multiset<MoveOnly, std::hash<MoveOnly>, + some_comp<MoveOnly>> C; + static_assert(!std::is_nothrow_move_constructible<C>::value, ""); + } +#endif +} diff --git a/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/range.pass.cpp b/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/range.pass.cpp new file mode 100644 index 000000000000..cd2bb1e7bbcd --- /dev/null +++ b/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/range.pass.cpp @@ -0,0 +1,167 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <unordered_set> + +// template <class Value, class Hash = hash<Value>, class Pred = equal_to<Value>, +// class Alloc = allocator<Value>> +// class unordered_multiset + +// template <class InputIterator> +// unordered_multiset(InputIterator first, InputIterator last); + +#include <unordered_set> +#include <cassert> +#include <cfloat> + +#include "test_iterators.h" +#include "../../../test_compare.h" +#include "../../../test_hash.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_multiset<int, + test_hash<std::hash<int> >, + test_compare<std::equal_to<int> >, + test_allocator<int> + > C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c(input_iterator<P*>(a), input_iterator<P*>(a + sizeof(a)/sizeof(a[0]))); + assert(c.bucket_count() >= 7); + 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() == test_hash<std::hash<int> >()); + assert(c.key_eq() == test_compare<std::equal_to<int> >()); + assert(c.get_allocator() == test_allocator<int>()); + 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); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multiset<int, + test_hash<std::hash<int> >, + test_compare<std::equal_to<int> >, + min_allocator<int> + > C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c(input_iterator<P*>(a), input_iterator<P*>(a + sizeof(a)/sizeof(a[0]))); + assert(c.bucket_count() >= 7); + 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() == test_hash<std::hash<int> >()); + assert(c.key_eq() == test_compare<std::equal_to<int> >()); + assert(c.get_allocator() == min_allocator<int>()); + 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); + } +#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 +} diff --git a/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/range_size.pass.cpp b/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/range_size.pass.cpp new file mode 100644 index 000000000000..4f5e03e28f4e --- /dev/null +++ b/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/range_size.pass.cpp @@ -0,0 +1,101 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <unordered_set> + +// template <class Value, class Hash = hash<Value>, class Pred = equal_to<Value>, +// class Alloc = allocator<Value>> +// class unordered_multiset + +// template <class InputIterator> +// unordered_multiset(InputIterator first, InputIterator last, size_type n); + +#include <unordered_set> +#include <cassert> +#include <cfloat> + +#include "test_iterators.h" +#include "../../../test_compare.h" +#include "../../../test_hash.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_multiset<int, + test_hash<std::hash<int> >, + test_compare<std::equal_to<int> >, + test_allocator<int> + > C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c(input_iterator<P*>(a), input_iterator<P*>(a + sizeof(a)/sizeof(a[0])), + 7 + ); + assert(c.bucket_count() == 7); + 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() == test_hash<std::hash<int> >()); + assert(c.key_eq() == test_compare<std::equal_to<int> >()); + assert(c.get_allocator() == test_allocator<int>()); + 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); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multiset<int, + test_hash<std::hash<int> >, + test_compare<std::equal_to<int> >, + min_allocator<int> + > C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c(input_iterator<P*>(a), input_iterator<P*>(a + sizeof(a)/sizeof(a[0])), + 7 + ); + assert(c.bucket_count() == 7); + 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() == test_hash<std::hash<int> >()); + assert(c.key_eq() == test_compare<std::equal_to<int> >()); + assert(c.get_allocator() == min_allocator<int>()); + 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 +} diff --git a/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/range_size_hash.pass.cpp b/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/range_size_hash.pass.cpp new file mode 100644 index 000000000000..6b83bde9bc5e --- /dev/null +++ b/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/range_size_hash.pass.cpp @@ -0,0 +1,104 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <unordered_set> + +// template <class Value, class Hash = hash<Value>, class Pred = equal_to<Value>, +// class Alloc = allocator<Value>> +// class unordered_multiset + +// template <class InputIterator> +// unordered_multiset(InputIterator first, InputIterator last, size_type n, +// const hasher& hf); + +#include <unordered_set> +#include <cassert> +#include <cfloat> + +#include "test_iterators.h" +#include "../../../test_compare.h" +#include "../../../test_hash.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_multiset<int, + test_hash<std::hash<int> >, + test_compare<std::equal_to<int> >, + test_allocator<int> + > C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c(input_iterator<P*>(a), input_iterator<P*>(a + sizeof(a)/sizeof(a[0])), + 7, + test_hash<std::hash<int> >(8) + ); + assert(c.bucket_count() == 7); + 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() == test_hash<std::hash<int> >(8)); + assert(c.key_eq() == test_compare<std::equal_to<int> >()); + assert(c.get_allocator() == test_allocator<int>()); + 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); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multiset<int, + test_hash<std::hash<int> >, + test_compare<std::equal_to<int> >, + min_allocator<int> + > C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c(input_iterator<P*>(a), input_iterator<P*>(a + sizeof(a)/sizeof(a[0])), + 7, + test_hash<std::hash<int> >(8) + ); + assert(c.bucket_count() == 7); + 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() == test_hash<std::hash<int> >(8)); + assert(c.key_eq() == test_compare<std::equal_to<int> >()); + assert(c.get_allocator() == min_allocator<int>()); + 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 +} diff --git a/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/range_size_hash_equal.pass.cpp b/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/range_size_hash_equal.pass.cpp new file mode 100644 index 000000000000..89e7c7fa2e3d --- /dev/null +++ b/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/range_size_hash_equal.pass.cpp @@ -0,0 +1,106 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <unordered_set> + +// template <class Value, class Hash = hash<Value>, class Pred = equal_to<Value>, +// class Alloc = allocator<Value>> +// class unordered_multiset + +// template <class InputIterator> +// unordered_multiset(InputIterator first, InputIterator last, size_type n, +// const hasher& hf, const key_equal& eql); + +#include <unordered_set> +#include <cassert> +#include <cfloat> + +#include "test_iterators.h" +#include "../../../test_compare.h" +#include "../../../test_hash.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_multiset<int, + test_hash<std::hash<int> >, + test_compare<std::equal_to<int> >, + test_allocator<int> + > C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c(input_iterator<P*>(a), input_iterator<P*>(a + sizeof(a)/sizeof(a[0])), + 7, + test_hash<std::hash<int> >(8), + test_compare<std::equal_to<int> >(9) + ); + assert(c.bucket_count() == 7); + 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() == test_hash<std::hash<int> >(8)); + assert(c.key_eq() == test_compare<std::equal_to<int> >(9)); + assert(c.get_allocator() == test_allocator<int>()); + 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); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multiset<int, + test_hash<std::hash<int> >, + test_compare<std::equal_to<int> >, + min_allocator<int> + > C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c(input_iterator<P*>(a), input_iterator<P*>(a + sizeof(a)/sizeof(a[0])), + 7, + test_hash<std::hash<int> >(8), + test_compare<std::equal_to<int> >(9) + ); + assert(c.bucket_count() == 7); + 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() == test_hash<std::hash<int> >(8)); + assert(c.key_eq() == test_compare<std::equal_to<int> >(9)); + assert(c.get_allocator() == min_allocator<int>()); + 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 +} diff --git a/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/range_size_hash_equal_allocator.pass.cpp b/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/range_size_hash_equal_allocator.pass.cpp new file mode 100644 index 000000000000..b712a96f05bc --- /dev/null +++ b/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/range_size_hash_equal_allocator.pass.cpp @@ -0,0 +1,109 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <unordered_set> + +// template <class Value, class Hash = hash<Value>, class Pred = equal_to<Value>, +// class Alloc = allocator<Value>> +// class unordered_multiset + +// template <class InputIterator> +// unordered_multiset(InputIterator first, InputIterator last, size_type n, +// const hasher& hf, const key_equal& eql, +// const allocator_type& a); + +#include <unordered_set> +#include <cassert> +#include <cfloat> + +#include "test_iterators.h" +#include "../../../test_compare.h" +#include "../../../test_hash.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_multiset<int, + test_hash<std::hash<int> >, + test_compare<std::equal_to<int> >, + test_allocator<int> + > C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c(input_iterator<P*>(a), input_iterator<P*>(a + sizeof(a)/sizeof(a[0])), + 7, + test_hash<std::hash<int> >(8), + test_compare<std::equal_to<int> >(9), + test_allocator<int>(10) + ); + assert(c.bucket_count() == 7); + 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() == test_hash<std::hash<int> >(8)); + assert(c.key_eq() == test_compare<std::equal_to<int> >(9)); + assert(c.get_allocator() == test_allocator<int>(10)); + 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); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multiset<int, + test_hash<std::hash<int> >, + test_compare<std::equal_to<int> >, + min_allocator<int> + > C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c(input_iterator<P*>(a), input_iterator<P*>(a + sizeof(a)/sizeof(a[0])), + 7, + test_hash<std::hash<int> >(8), + test_compare<std::equal_to<int> >(9), + min_allocator<int>() + ); + assert(c.bucket_count() == 7); + 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() == test_hash<std::hash<int> >(8)); + assert(c.key_eq() == test_compare<std::equal_to<int> >(9)); + assert(c.get_allocator() == min_allocator<int>()); + 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 +} diff --git a/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/size.fail.cpp b/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/size.fail.cpp new file mode 100644 index 000000000000..e55db7ca2aaf --- /dev/null +++ b/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/size.fail.cpp @@ -0,0 +1,65 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <unordered_set> + +// template <class Value, class Hash = hash<Value>, class Pred = equal_to<Value>, +// class Alloc = allocator<Value>> +// class unordered_multiset + +// explicit unordered_multiset(size_type n); + +#include <unordered_set> +#include <cassert> + +#include "../../../NotConstructible.h" +#include "../../../test_compare.h" +#include "../../../test_hash.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_multiset<NotConstructible, + test_hash<std::hash<NotConstructible> >, + test_compare<std::equal_to<NotConstructible> >, + test_allocator<NotConstructible> + > C; + C c = 7; + assert(c.bucket_count() == 7); + assert(c.hash_function() == test_hash<std::hash<NotConstructible> >()); + assert(c.key_eq() == test_compare<std::equal_to<NotConstructible> >()); + assert(c.get_allocator() == (test_allocator<NotConstructible>())); + 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); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multiset<NotConstructible, + test_hash<std::hash<NotConstructible> >, + test_compare<std::equal_to<NotConstructible> >, + min_allocator<NotConstructible> + > C; + C c = 7; + assert(c.bucket_count() == 7); + assert(c.hash_function() == test_hash<std::hash<NotConstructible> >()); + assert(c.key_eq() == test_compare<std::equal_to<NotConstructible> >()); + assert(c.get_allocator() == (min_allocator<NotConstructible>())); + 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 +} diff --git a/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/size.pass.cpp b/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/size.pass.cpp new file mode 100644 index 000000000000..35bfbe331b41 --- /dev/null +++ b/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/size.pass.cpp @@ -0,0 +1,65 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <unordered_set> + +// template <class Value, class Hash = hash<Value>, class Pred = equal_to<Value>, +// class Alloc = allocator<Value>> +// class unordered_multiset + +// explicit unordered_multiset(size_type n); + +#include <unordered_set> +#include <cassert> + +#include "../../../NotConstructible.h" +#include "../../../test_compare.h" +#include "../../../test_hash.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_multiset<NotConstructible, + test_hash<std::hash<NotConstructible> >, + test_compare<std::equal_to<NotConstructible> >, + test_allocator<NotConstructible> + > C; + C c(7); + assert(c.bucket_count() == 7); + assert(c.hash_function() == test_hash<std::hash<NotConstructible> >()); + assert(c.key_eq() == test_compare<std::equal_to<NotConstructible> >()); + assert(c.get_allocator() == (test_allocator<NotConstructible>())); + 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); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multiset<NotConstructible, + test_hash<std::hash<NotConstructible> >, + test_compare<std::equal_to<NotConstructible> >, + min_allocator<NotConstructible> + > C; + C c(7); + assert(c.bucket_count() == 7); + assert(c.hash_function() == test_hash<std::hash<NotConstructible> >()); + assert(c.key_eq() == test_compare<std::equal_to<NotConstructible> >()); + assert(c.get_allocator() == (min_allocator<NotConstructible>())); + 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 +} diff --git a/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/size_hash.pass.cpp b/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/size_hash.pass.cpp new file mode 100644 index 000000000000..0171ea64ebb1 --- /dev/null +++ b/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/size_hash.pass.cpp @@ -0,0 +1,69 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <unordered_set> + +// template <class Value, class Hash = hash<Value>, class Pred = equal_to<Value>, +// class Alloc = allocator<Value>> +// class unordered_multiset + +// unordered_multiset(size_type n, const hasher& hf); + +#include <unordered_set> +#include <cassert> + +#include "../../../NotConstructible.h" +#include "../../../test_compare.h" +#include "../../../test_hash.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_multiset<NotConstructible, + test_hash<std::hash<NotConstructible> >, + test_compare<std::equal_to<NotConstructible> >, + test_allocator<NotConstructible> + > C; + C c(7, + test_hash<std::hash<NotConstructible> >(8) + ); + assert(c.bucket_count() == 7); + assert(c.hash_function() == test_hash<std::hash<NotConstructible> >(8)); + assert(c.key_eq() == test_compare<std::equal_to<NotConstructible> >()); + assert(c.get_allocator() == (test_allocator<NotConstructible>())); + 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); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multiset<NotConstructible, + test_hash<std::hash<NotConstructible> >, + test_compare<std::equal_to<NotConstructible> >, + min_allocator<NotConstructible> + > C; + C c(7, + test_hash<std::hash<NotConstructible> >(8) + ); + assert(c.bucket_count() == 7); + assert(c.hash_function() == test_hash<std::hash<NotConstructible> >(8)); + assert(c.key_eq() == test_compare<std::equal_to<NotConstructible> >()); + assert(c.get_allocator() == (min_allocator<NotConstructible>())); + 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 +} diff --git a/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/size_hash_equal.pass.cpp b/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/size_hash_equal.pass.cpp new file mode 100644 index 000000000000..785cdf246368 --- /dev/null +++ b/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/size_hash_equal.pass.cpp @@ -0,0 +1,71 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <unordered_set> + +// template <class Value, class Hash = hash<Value>, class Pred = equal_to<Value>, +// class Alloc = allocator<Value>> +// class unordered_multiset + +// unordered_multiset(size_type n, const hasher& hf, const key_equal& eql); + +#include <unordered_set> +#include <cassert> + +#include "../../../NotConstructible.h" +#include "../../../test_compare.h" +#include "../../../test_hash.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_multiset<NotConstructible, + test_hash<std::hash<NotConstructible> >, + test_compare<std::equal_to<NotConstructible> >, + test_allocator<NotConstructible> + > C; + C c(7, + test_hash<std::hash<NotConstructible> >(8), + test_compare<std::equal_to<NotConstructible> >(9) + ); + assert(c.bucket_count() == 7); + assert(c.hash_function() == test_hash<std::hash<NotConstructible> >(8)); + assert(c.key_eq() == test_compare<std::equal_to<NotConstructible> >(9)); + assert(c.get_allocator() == (test_allocator<NotConstructible>())); + 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); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multiset<NotConstructible, + test_hash<std::hash<NotConstructible> >, + test_compare<std::equal_to<NotConstructible> >, + min_allocator<NotConstructible> + > C; + C c(7, + test_hash<std::hash<NotConstructible> >(8), + test_compare<std::equal_to<NotConstructible> >(9) + ); + assert(c.bucket_count() == 7); + assert(c.hash_function() == test_hash<std::hash<NotConstructible> >(8)); + assert(c.key_eq() == test_compare<std::equal_to<NotConstructible> >(9)); + assert(c.get_allocator() == (min_allocator<NotConstructible>())); + 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 +} diff --git a/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/size_hash_equal_allocator.pass.cpp b/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/size_hash_equal_allocator.pass.cpp new file mode 100644 index 000000000000..50dd3c95ee52 --- /dev/null +++ b/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/size_hash_equal_allocator.pass.cpp @@ -0,0 +1,73 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <unordered_set> + +// template <class Value, class Hash = hash<Value>, class Pred = equal_to<Value>, +// class Alloc = allocator<Value>> +// class unordered_multiset + +// unordered_multiset(size_type n, const hasher& hf, const key_equal& eql, const allocator_type& a); + +#include <unordered_set> +#include <cassert> + +#include "../../../NotConstructible.h" +#include "../../../test_compare.h" +#include "../../../test_hash.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_multiset<NotConstructible, + test_hash<std::hash<NotConstructible> >, + test_compare<std::equal_to<NotConstructible> >, + test_allocator<NotConstructible> + > C; + C c(7, + test_hash<std::hash<NotConstructible> >(8), + test_compare<std::equal_to<NotConstructible> >(9), + test_allocator<std::pair<const NotConstructible, NotConstructible> >(10) + ); + assert(c.bucket_count() == 7); + assert(c.hash_function() == test_hash<std::hash<NotConstructible> >(8)); + assert(c.key_eq() == test_compare<std::equal_to<NotConstructible> >(9)); + assert(c.get_allocator() == (test_allocator<NotConstructible>(10))); + 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); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multiset<NotConstructible, + test_hash<std::hash<NotConstructible> >, + test_compare<std::equal_to<NotConstructible> >, + min_allocator<NotConstructible> + > C; + C c(7, + test_hash<std::hash<NotConstructible> >(8), + test_compare<std::equal_to<NotConstructible> >(9), + min_allocator<std::pair<const NotConstructible, NotConstructible> >() + ); + assert(c.bucket_count() == 7); + assert(c.hash_function() == test_hash<std::hash<NotConstructible> >(8)); + assert(c.key_eq() == test_compare<std::equal_to<NotConstructible> >(9)); + assert(c.get_allocator() == (min_allocator<NotConstructible>())); + 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 +} diff --git a/test/std/containers/unord/unord.multiset/unord.multiset.swap/db_swap_1.pass.cpp b/test/std/containers/unord/unord.multiset/unord.multiset.swap/db_swap_1.pass.cpp new file mode 100644 index 000000000000..9470b1a6fa88 --- /dev/null +++ b/test/std/containers/unord/unord.multiset/unord.multiset.swap/db_swap_1.pass.cpp @@ -0,0 +1,43 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <unordered_set> + +// template <class Value, class Hash = hash<Value>, class Pred = equal_to<Value>, +// class Alloc = allocator<Value>> +// class unordered_multiset + +// void swap(unordered_multiset& x, unordered_multiset& y); + +#if _LIBCPP_DEBUG >= 1 +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) +#endif + +#include <unordered_set> +#include <cassert> + +int main() +{ +#if _LIBCPP_DEBUG >= 1 + { + int a1[] = {1, 3, 7, 9, 10}; + int a2[] = {0, 2, 4, 5, 6, 8, 11}; + std::unordered_multiset<int> c1(a1, a1+sizeof(a1)/sizeof(a1[0])); + std::unordered_multiset<int> c2(a2, a2+sizeof(a2)/sizeof(a2[0])); + std::unordered_multiset<int>::iterator i1 = c1.begin(); + std::unordered_multiset<int>::iterator i2 = c2.begin(); + swap(c1, c2); + c1.erase(i2); + c2.erase(i1); + std::unordered_multiset<int>::iterator j = i1; + c1.erase(i1); + assert(false); + } +#endif +} diff --git a/test/std/containers/unord/unord.multiset/unord.multiset.swap/swap_noexcept.pass.cpp b/test/std/containers/unord/unord.multiset/unord.multiset.swap/swap_noexcept.pass.cpp new file mode 100644 index 000000000000..63642fcd7cca --- /dev/null +++ b/test/std/containers/unord/unord.multiset/unord.multiset.swap/swap_noexcept.pass.cpp @@ -0,0 +1,198 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <unordered_set> + +// void swap(unordered_multiset& c) +// noexcept( +// (!allocator_type::propagate_on_container_swap::value || +// __is_nothrow_swappable<allocator_type>::value) && +// __is_nothrow_swappable<hasher>::value && +// __is_nothrow_swappable<key_equal>::value); +// +// In C++17, the standard says that swap shall have: +// noexcept(allocator_traits<Allocator>::is_always_equal::value && +// noexcept(swap(declval<Hash&>(), declval<Hash&>())) && +// noexcept(swap(declval<Pred&>(), declval<Pred&>()))); + +// This tests a conforming extension + +#include <unordered_set> +#include <cassert> + +#include "MoveOnly.h" +#include "test_allocator.h" + +template <class T> +struct some_comp +{ + typedef T value_type; + + some_comp() {} + some_comp(const some_comp&) {} +}; + +template <class T> +struct some_comp2 +{ + typedef T value_type; + + some_comp2() {} + some_comp2(const some_comp2&) {} + void deallocate(void*, unsigned) {} + typedef std::true_type propagate_on_container_swap; +}; + +#if TEST_STD_VER >= 14 +template <typename T> +void swap(some_comp2<T>&, some_comp2<T>&) noexcept {} +#endif + +template <class T> +struct some_hash +{ + typedef T value_type; + some_hash() {} + some_hash(const some_hash&); +}; + +template <class T> +struct some_hash2 +{ + typedef T value_type; + some_hash2() {} + some_hash2(const some_hash2&); +}; + +#if TEST_STD_VER >= 14 +template <typename T> +void swap(some_hash2<T>&, some_hash2<T>&) noexcept {} +#endif + +template <class T> +struct some_alloc +{ + typedef T value_type; + + some_alloc() {} + some_alloc(const some_alloc&); + void deallocate(void*, unsigned) {} + + typedef std::true_type propagate_on_container_swap; +}; + +template <class T> +struct some_alloc2 +{ + typedef T value_type; + + some_alloc2() {} + some_alloc2(const some_alloc2&); + void deallocate(void*, unsigned) {} + + typedef std::false_type propagate_on_container_swap; + typedef std::true_type is_always_equal; +}; + +template <class T> +struct some_alloc3 +{ + typedef T value_type; + + some_alloc3() {} + some_alloc3(const some_alloc3&); + void deallocate(void*, unsigned) {} + + typedef std::false_type propagate_on_container_swap; + typedef std::false_type is_always_equal; +}; + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::unordered_multiset<MoveOnly> C; + C c1, c2; + static_assert(noexcept(swap(c1, c2)), ""); + } + { + typedef std::unordered_multiset<MoveOnly, std::hash<MoveOnly>, + std::equal_to<MoveOnly>, test_allocator<MoveOnly>> C; + C c1, c2; + static_assert(noexcept(swap(c1, c2)), ""); + } + { + typedef std::unordered_multiset<MoveOnly, std::hash<MoveOnly>, + std::equal_to<MoveOnly>, other_allocator<MoveOnly>> C; + C c1, c2; + static_assert(noexcept(swap(c1, c2)), ""); + } + { + typedef std::unordered_multiset<MoveOnly, some_hash<MoveOnly>> C; + C c1, c2; + static_assert(!noexcept(swap(c1, c2)), ""); + } + { + typedef std::unordered_multiset<MoveOnly, std::hash<MoveOnly>, + some_comp<MoveOnly>> C; + C c1, c2; + static_assert(!noexcept(swap(c1, c2)), ""); + } + +#if TEST_STD_VER >= 14 + { // POCS allocator, throwable swap for hash, throwable swap for comp + typedef std::unordered_multiset<MoveOnly, some_hash<MoveOnly>, some_comp <MoveOnly>, some_alloc <MoveOnly>> C; + C c1, c2; + static_assert(!noexcept(swap(c1, c2)), ""); + } + { // always equal allocator, throwable swap for hash, throwable swap for comp + typedef std::unordered_multiset<MoveOnly, some_hash<MoveOnly>, some_comp <MoveOnly>, some_alloc2<MoveOnly>> C; + C c1, c2; + static_assert(!noexcept(swap(c1, c2)), ""); + } + { // POCS allocator, throwable swap for hash, nothrow swap for comp + typedef std::unordered_multiset<MoveOnly, some_hash<MoveOnly>, some_comp2<MoveOnly>, some_alloc <MoveOnly>> C; + C c1, c2; + static_assert(!noexcept(swap(c1, c2)), ""); + } + { // always equal allocator, throwable swap for hash, nothrow swap for comp + typedef std::unordered_multiset<MoveOnly, some_hash<MoveOnly>, some_comp2<MoveOnly>, some_alloc2<MoveOnly>> C; + C c1, c2; + static_assert(!noexcept(swap(c1, c2)), ""); + } + { // POCS allocator, nothrow swap for hash, throwable swap for comp + typedef std::unordered_multiset<MoveOnly, some_hash2<MoveOnly>, some_comp <MoveOnly>, some_alloc <MoveOnly>> C; + C c1, c2; + static_assert(!noexcept(swap(c1, c2)), ""); + } + { // always equal allocator, nothrow swap for hash, throwable swap for comp + typedef std::unordered_multiset<MoveOnly, some_hash2<MoveOnly>, some_comp <MoveOnly>, some_alloc2<MoveOnly>> C; + C c1, c2; + static_assert(!noexcept(swap(c1, c2)), ""); + } + { // POCS allocator, nothrow swap for hash, nothrow swap for comp + typedef std::unordered_multiset<MoveOnly, some_hash2<MoveOnly>, some_comp2<MoveOnly>, some_alloc <MoveOnly>> C; + C c1, c2; + static_assert( noexcept(swap(c1, c2)), ""); + } + { // always equal allocator, nothrow swap for hash, nothrow swap for comp + typedef std::unordered_multiset<MoveOnly, some_hash2<MoveOnly>, some_comp2<MoveOnly>, some_alloc2<MoveOnly>> C; + C c1, c2; + static_assert( noexcept(swap(c1, c2)), ""); + } + + { // NOT always equal allocator, nothrow swap for hash, nothrow swap for comp + typedef std::unordered_multiset<MoveOnly, some_hash2<MoveOnly>, some_comp2<MoveOnly>, some_alloc3<MoveOnly>> C; + C c1, c2; + static_assert( noexcept(swap(c1, c2)), ""); + } +#endif + +#endif +} diff --git a/test/std/containers/unord/unord.multiset/unord.multiset.swap/swap_non_member.pass.cpp b/test/std/containers/unord/unord.multiset/unord.multiset.swap/swap_non_member.pass.cpp new file mode 100644 index 000000000000..624b81c5eb3e --- /dev/null +++ b/test/std/containers/unord/unord.multiset/unord.multiset.swap/swap_non_member.pass.cpp @@ -0,0 +1,571 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <unordered_set> + +// template <class Value, class Hash = hash<Value>, class Pred = equal_to<Value>, +// class Alloc = allocator<Value>> +// class unordered_multiset + +// void swap(unordered_multiset& x, unordered_multiset& y); + +#include <unordered_set> +#include <cassert> + +#include "../../../test_compare.h" +#include "../../../test_hash.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ + { + typedef test_hash<std::hash<int> > Hash; + typedef test_compare<std::equal_to<int> > Compare; + typedef test_allocator<int> Alloc; + typedef std::unordered_multiset<int, Hash, Compare, Alloc> C; + typedef int P; + C c1(0, Hash(1), Compare(1), Alloc(1)); + C c2(0, Hash(2), Compare(2), Alloc(2)); + c2.max_load_factor(2); + swap(c1, c2); + + assert(c1.bucket_count() == 0); + assert(c1.size() == 0); + assert(c1.hash_function() == Hash(2)); + assert(c1.key_eq() == Compare(2)); + assert(c1.get_allocator() == Alloc(1)); + assert(std::distance(c1.begin(), c1.end()) == c1.size()); + assert(std::distance(c1.cbegin(), c1.cend()) == c1.size()); + assert(c1.max_load_factor() == 2); + + assert(c2.bucket_count() == 0); + assert(c2.size() == 0); + assert(c2.hash_function() == Hash(1)); + assert(c2.key_eq() == Compare(1)); + assert(c2.get_allocator() == Alloc(2)); + assert(std::distance(c2.begin(), c2.end()) == c2.size()); + assert(std::distance(c2.cbegin(), c2.cend()) == c2.size()); + assert(c2.max_load_factor() == 1); + } + { + typedef test_hash<std::hash<int> > Hash; + typedef test_compare<std::equal_to<int> > Compare; + typedef test_allocator<int> Alloc; + typedef std::unordered_multiset<int, Hash, Compare, Alloc> C; + typedef int P; + P a2[] = + { + P(10), + P(20), + P(30), + P(40), + P(50), + P(60), + P(70), + P(80) + }; + C c1(0, Hash(1), Compare(1), Alloc(1)); + C c2(std::begin(a2), std::end(a2), 0, Hash(2), Compare(2), Alloc(2)); + c2.max_load_factor(2); + swap(c1, c2); + + assert(c1.bucket_count() >= 11); + assert(c1.size() == 8); + assert(*c1.find(10) == 10); + assert(*c1.find(20) == 20); + assert(*c1.find(30) == 30); + assert(*c1.find(40) == 40); + assert(*c1.find(50) == 50); + assert(*c1.find(60) == 60); + assert(*c1.find(70) == 70); + assert(*c1.find(80) == 80); + assert(c1.hash_function() == Hash(2)); + assert(c1.key_eq() == Compare(2)); + assert(c1.get_allocator() == Alloc(1)); + assert(std::distance(c1.begin(), c1.end()) == c1.size()); + assert(std::distance(c1.cbegin(), c1.cend()) == c1.size()); + assert(c1.max_load_factor() == 2); + + assert(c2.bucket_count() == 0); + assert(c2.size() == 0); + assert(c2.hash_function() == Hash(1)); + assert(c2.key_eq() == Compare(1)); + assert(c2.get_allocator() == Alloc(2)); + assert(std::distance(c2.begin(), c2.end()) == c2.size()); + assert(std::distance(c2.cbegin(), c2.cend()) == c2.size()); + assert(c2.max_load_factor() == 1); + } + { + typedef test_hash<std::hash<int> > Hash; + typedef test_compare<std::equal_to<int> > Compare; + typedef test_allocator<int> Alloc; + typedef std::unordered_multiset<int, Hash, Compare, Alloc> C; + typedef int P; + P a1[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c1(std::begin(a1), std::end(a1), 0, Hash(1), Compare(1), Alloc(1)); + C c2(0, Hash(2), Compare(2), Alloc(2)); + c2.max_load_factor(2); + swap(c1, c2); + + assert(c1.bucket_count() == 0); + assert(c1.size() == 0); + assert(c1.hash_function() == Hash(2)); + assert(c1.key_eq() == Compare(2)); + assert(c1.get_allocator() == Alloc(1)); + assert(std::distance(c1.begin(), c1.end()) == c1.size()); + assert(std::distance(c1.cbegin(), c1.cend()) == c1.size()); + assert(c1.max_load_factor() == 2); + + assert(c2.bucket_count() >= 7); + assert(c2.size() == 6); + assert(c2.count(1) == 2); + assert(c2.count(2) == 2); + assert(c2.count(3) == 1); + assert(c2.count(4) == 1); + assert(c2.hash_function() == Hash(1)); + assert(c2.key_eq() == Compare(1)); + assert(c2.get_allocator() == Alloc(2)); + assert(std::distance(c2.begin(), c2.end()) == c2.size()); + assert(std::distance(c2.cbegin(), c2.cend()) == c2.size()); + assert(c2.max_load_factor() == 1); + } + { + typedef test_hash<std::hash<int> > Hash; + typedef test_compare<std::equal_to<int> > Compare; + typedef test_allocator<int> Alloc; + typedef std::unordered_multiset<int, Hash, Compare, Alloc> C; + typedef int P; + P a1[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + P a2[] = + { + P(10), + P(20), + P(30), + P(40), + P(50), + P(60), + P(70), + P(80) + }; + C c1(std::begin(a1), std::end(a1), 0, Hash(1), Compare(1), Alloc(1)); + C c2(std::begin(a2), std::end(a2), 0, Hash(2), Compare(2), Alloc(2)); + c2.max_load_factor(2); + swap(c1, c2); + + assert(c1.bucket_count() >= 11); + assert(c1.size() == 8); + assert(*c1.find(10) == 10); + assert(*c1.find(20) == 20); + assert(*c1.find(30) == 30); + assert(*c1.find(40) == 40); + assert(*c1.find(50) == 50); + assert(*c1.find(60) == 60); + assert(*c1.find(70) == 70); + assert(*c1.find(80) == 80); + assert(c1.hash_function() == Hash(2)); + assert(c1.key_eq() == Compare(2)); + assert(c1.get_allocator() == Alloc(1)); + assert(std::distance(c1.begin(), c1.end()) == c1.size()); + assert(std::distance(c1.cbegin(), c1.cend()) == c1.size()); + assert(c1.max_load_factor() == 2); + + assert(c2.bucket_count() >= 7); + assert(c2.size() == 6); + assert(c2.count(1) == 2); + assert(c2.count(2) == 2); + assert(c2.count(3) == 1); + assert(c2.count(4) == 1); + assert(c2.hash_function() == Hash(1)); + assert(c2.key_eq() == Compare(1)); + assert(c2.get_allocator() == Alloc(2)); + assert(std::distance(c2.begin(), c2.end()) == c2.size()); + assert(std::distance(c2.cbegin(), c2.cend()) == c2.size()); + assert(c2.max_load_factor() == 1); + } + + { + typedef test_hash<std::hash<int> > Hash; + typedef test_compare<std::equal_to<int> > Compare; + typedef other_allocator<int> Alloc; + typedef std::unordered_multiset<int, Hash, Compare, Alloc> C; + typedef int P; + C c1(0, Hash(1), Compare(1), Alloc(1)); + C c2(0, Hash(2), Compare(2), Alloc(2)); + c2.max_load_factor(2); + swap(c1, c2); + + assert(c1.bucket_count() == 0); + assert(c1.size() == 0); + assert(c1.hash_function() == Hash(2)); + assert(c1.key_eq() == Compare(2)); + assert(c1.get_allocator() == Alloc(2)); + assert(std::distance(c1.begin(), c1.end()) == c1.size()); + assert(std::distance(c1.cbegin(), c1.cend()) == c1.size()); + assert(c1.max_load_factor() == 2); + + assert(c2.bucket_count() == 0); + assert(c2.size() == 0); + assert(c2.hash_function() == Hash(1)); + assert(c2.key_eq() == Compare(1)); + assert(c2.get_allocator() == Alloc(1)); + assert(std::distance(c2.begin(), c2.end()) == c2.size()); + assert(std::distance(c2.cbegin(), c2.cend()) == c2.size()); + assert(c2.max_load_factor() == 1); + } + { + typedef test_hash<std::hash<int> > Hash; + typedef test_compare<std::equal_to<int> > Compare; + typedef other_allocator<int> Alloc; + typedef std::unordered_multiset<int, Hash, Compare, Alloc> C; + typedef int P; + P a2[] = + { + P(10), + P(20), + P(30), + P(40), + P(50), + P(60), + P(70), + P(80) + }; + C c1(0, Hash(1), Compare(1), Alloc(1)); + C c2(std::begin(a2), std::end(a2), 0, Hash(2), Compare(2), Alloc(2)); + c2.max_load_factor(2); + swap(c1, c2); + + assert(c1.bucket_count() >= 11); + assert(c1.size() == 8); + assert(*c1.find(10) == 10); + assert(*c1.find(20) == 20); + assert(*c1.find(30) == 30); + assert(*c1.find(40) == 40); + assert(*c1.find(50) == 50); + assert(*c1.find(60) == 60); + assert(*c1.find(70) == 70); + assert(*c1.find(80) == 80); + assert(c1.hash_function() == Hash(2)); + assert(c1.key_eq() == Compare(2)); + assert(c1.get_allocator() == Alloc(2)); + assert(std::distance(c1.begin(), c1.end()) == c1.size()); + assert(std::distance(c1.cbegin(), c1.cend()) == c1.size()); + assert(c1.max_load_factor() == 2); + + assert(c2.bucket_count() == 0); + assert(c2.size() == 0); + assert(c2.hash_function() == Hash(1)); + assert(c2.key_eq() == Compare(1)); + assert(c2.get_allocator() == Alloc(1)); + assert(std::distance(c2.begin(), c2.end()) == c2.size()); + assert(std::distance(c2.cbegin(), c2.cend()) == c2.size()); + assert(c2.max_load_factor() == 1); + } + { + typedef test_hash<std::hash<int> > Hash; + typedef test_compare<std::equal_to<int> > Compare; + typedef other_allocator<int> Alloc; + typedef std::unordered_multiset<int, Hash, Compare, Alloc> C; + typedef int P; + P a1[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c1(std::begin(a1), std::end(a1), 0, Hash(1), Compare(1), Alloc(1)); + C c2(0, Hash(2), Compare(2), Alloc(2)); + c2.max_load_factor(2); + swap(c1, c2); + + assert(c1.bucket_count() == 0); + assert(c1.size() == 0); + assert(c1.hash_function() == Hash(2)); + assert(c1.key_eq() == Compare(2)); + assert(c1.get_allocator() == Alloc(2)); + assert(std::distance(c1.begin(), c1.end()) == c1.size()); + assert(std::distance(c1.cbegin(), c1.cend()) == c1.size()); + assert(c1.max_load_factor() == 2); + + assert(c2.bucket_count() >= 7); + assert(c2.size() == 6); + assert(c2.count(1) == 2); + assert(c2.count(2) == 2); + assert(c2.count(3) == 1); + assert(c2.count(4) == 1); + assert(c2.hash_function() == Hash(1)); + assert(c2.key_eq() == Compare(1)); + assert(c2.get_allocator() == Alloc(1)); + assert(std::distance(c2.begin(), c2.end()) == c2.size()); + assert(std::distance(c2.cbegin(), c2.cend()) == c2.size()); + assert(c2.max_load_factor() == 1); + } + { + typedef test_hash<std::hash<int> > Hash; + typedef test_compare<std::equal_to<int> > Compare; + typedef other_allocator<int> Alloc; + typedef std::unordered_multiset<int, Hash, Compare, Alloc> C; + typedef int P; + P a1[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + P a2[] = + { + P(10), + P(20), + P(30), + P(40), + P(50), + P(60), + P(70), + P(80) + }; + C c1(std::begin(a1), std::end(a1), 0, Hash(1), Compare(1), Alloc(1)); + C c2(std::begin(a2), std::end(a2), 0, Hash(2), Compare(2), Alloc(2)); + c2.max_load_factor(2); + swap(c1, c2); + + assert(c1.bucket_count() >= 11); + assert(c1.size() == 8); + assert(*c1.find(10) == 10); + assert(*c1.find(20) == 20); + assert(*c1.find(30) == 30); + assert(*c1.find(40) == 40); + assert(*c1.find(50) == 50); + assert(*c1.find(60) == 60); + assert(*c1.find(70) == 70); + assert(*c1.find(80) == 80); + assert(c1.hash_function() == Hash(2)); + assert(c1.key_eq() == Compare(2)); + assert(c1.get_allocator() == Alloc(2)); + assert(std::distance(c1.begin(), c1.end()) == c1.size()); + assert(std::distance(c1.cbegin(), c1.cend()) == c1.size()); + assert(c1.max_load_factor() == 2); + + assert(c2.bucket_count() >= 7); + assert(c2.size() == 6); + assert(c2.count(1) == 2); + assert(c2.count(2) == 2); + assert(c2.count(3) == 1); + assert(c2.count(4) == 1); + assert(c2.hash_function() == Hash(1)); + assert(c2.key_eq() == Compare(1)); + assert(c2.get_allocator() == Alloc(1)); + assert(std::distance(c2.begin(), c2.end()) == c2.size()); + assert(std::distance(c2.cbegin(), c2.cend()) == c2.size()); + assert(c2.max_load_factor() == 1); + } +#if __cplusplus >= 201103L + { + typedef test_hash<std::hash<int> > Hash; + typedef test_compare<std::equal_to<int> > Compare; + typedef min_allocator<int> Alloc; + typedef std::unordered_multiset<int, Hash, Compare, Alloc> C; + typedef int P; + C c1(0, Hash(1), Compare(1), Alloc()); + C c2(0, Hash(2), Compare(2), Alloc()); + c2.max_load_factor(2); + swap(c1, c2); + + assert(c1.bucket_count() == 0); + assert(c1.size() == 0); + assert(c1.hash_function() == Hash(2)); + assert(c1.key_eq() == Compare(2)); + assert(c1.get_allocator() == Alloc()); + assert(std::distance(c1.begin(), c1.end()) == c1.size()); + assert(std::distance(c1.cbegin(), c1.cend()) == c1.size()); + assert(c1.max_load_factor() == 2); + + assert(c2.bucket_count() == 0); + assert(c2.size() == 0); + assert(c2.hash_function() == Hash(1)); + assert(c2.key_eq() == Compare(1)); + assert(c2.get_allocator() == Alloc()); + assert(std::distance(c2.begin(), c2.end()) == c2.size()); + assert(std::distance(c2.cbegin(), c2.cend()) == c2.size()); + assert(c2.max_load_factor() == 1); + } + { + typedef test_hash<std::hash<int> > Hash; + typedef test_compare<std::equal_to<int> > Compare; + typedef min_allocator<int> Alloc; + typedef std::unordered_multiset<int, Hash, Compare, Alloc> C; + typedef int P; + P a2[] = + { + P(10), + P(20), + P(30), + P(40), + P(50), + P(60), + P(70), + P(80) + }; + C c1(0, Hash(1), Compare(1), Alloc()); + C c2(std::begin(a2), std::end(a2), 0, Hash(2), Compare(2), Alloc()); + c2.max_load_factor(2); + swap(c1, c2); + + assert(c1.bucket_count() >= 11); + assert(c1.size() == 8); + assert(*c1.find(10) == 10); + assert(*c1.find(20) == 20); + assert(*c1.find(30) == 30); + assert(*c1.find(40) == 40); + assert(*c1.find(50) == 50); + assert(*c1.find(60) == 60); + assert(*c1.find(70) == 70); + assert(*c1.find(80) == 80); + assert(c1.hash_function() == Hash(2)); + assert(c1.key_eq() == Compare(2)); + assert(c1.get_allocator() == Alloc()); + assert(std::distance(c1.begin(), c1.end()) == c1.size()); + assert(std::distance(c1.cbegin(), c1.cend()) == c1.size()); + assert(c1.max_load_factor() == 2); + + assert(c2.bucket_count() == 0); + assert(c2.size() == 0); + assert(c2.hash_function() == Hash(1)); + assert(c2.key_eq() == Compare(1)); + assert(c2.get_allocator() == Alloc()); + assert(std::distance(c2.begin(), c2.end()) == c2.size()); + assert(std::distance(c2.cbegin(), c2.cend()) == c2.size()); + assert(c2.max_load_factor() == 1); + } + { + typedef test_hash<std::hash<int> > Hash; + typedef test_compare<std::equal_to<int> > Compare; + typedef min_allocator<int> Alloc; + typedef std::unordered_multiset<int, Hash, Compare, Alloc> C; + typedef int P; + P a1[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c1(std::begin(a1), std::end(a1), 0, Hash(1), Compare(1), Alloc()); + C c2(0, Hash(2), Compare(2), Alloc()); + c2.max_load_factor(2); + swap(c1, c2); + + assert(c1.bucket_count() == 0); + assert(c1.size() == 0); + assert(c1.hash_function() == Hash(2)); + assert(c1.key_eq() == Compare(2)); + assert(c1.get_allocator() == Alloc()); + assert(std::distance(c1.begin(), c1.end()) == c1.size()); + assert(std::distance(c1.cbegin(), c1.cend()) == c1.size()); + assert(c1.max_load_factor() == 2); + + assert(c2.bucket_count() >= 7); + assert(c2.size() == 6); + assert(c2.count(1) == 2); + assert(c2.count(2) == 2); + assert(c2.count(3) == 1); + assert(c2.count(4) == 1); + assert(c2.hash_function() == Hash(1)); + assert(c2.key_eq() == Compare(1)); + assert(c2.get_allocator() == Alloc()); + assert(std::distance(c2.begin(), c2.end()) == c2.size()); + assert(std::distance(c2.cbegin(), c2.cend()) == c2.size()); + assert(c2.max_load_factor() == 1); + } + { + typedef test_hash<std::hash<int> > Hash; + typedef test_compare<std::equal_to<int> > Compare; + typedef min_allocator<int> Alloc; + typedef std::unordered_multiset<int, Hash, Compare, Alloc> C; + typedef int P; + P a1[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + P a2[] = + { + P(10), + P(20), + P(30), + P(40), + P(50), + P(60), + P(70), + P(80) + }; + C c1(std::begin(a1), std::end(a1), 0, Hash(1), Compare(1), Alloc()); + C c2(std::begin(a2), std::end(a2), 0, Hash(2), Compare(2), Alloc()); + c2.max_load_factor(2); + swap(c1, c2); + + assert(c1.bucket_count() >= 11); + assert(c1.size() == 8); + assert(*c1.find(10) == 10); + assert(*c1.find(20) == 20); + assert(*c1.find(30) == 30); + assert(*c1.find(40) == 40); + assert(*c1.find(50) == 50); + assert(*c1.find(60) == 60); + assert(*c1.find(70) == 70); + assert(*c1.find(80) == 80); + assert(c1.hash_function() == Hash(2)); + assert(c1.key_eq() == Compare(2)); + assert(c1.get_allocator() == Alloc()); + assert(std::distance(c1.begin(), c1.end()) == c1.size()); + assert(std::distance(c1.cbegin(), c1.cend()) == c1.size()); + assert(c1.max_load_factor() == 2); + + assert(c2.bucket_count() >= 7); + assert(c2.size() == 6); + assert(c2.count(1) == 2); + assert(c2.count(2) == 2); + assert(c2.count(3) == 1); + assert(c2.count(4) == 1); + assert(c2.hash_function() == Hash(1)); + assert(c2.key_eq() == Compare(1)); + assert(c2.get_allocator() == Alloc()); + assert(std::distance(c2.begin(), c2.end()) == c2.size()); + assert(std::distance(c2.cbegin(), c2.cend()) == c2.size()); + assert(c2.max_load_factor() == 1); + } +#endif +} |