diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2018-08-02 17:33:33 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2018-08-02 17:33:33 +0000 |
commit | 315d10f09ee888005b1da55e7bbb57d8a79b8447 (patch) | |
tree | 99a16e8c2272e507281e63fac5970e0548df04ea /test/std/containers/unord/unord.multiset | |
parent | f36202620b428c45a1c8d91743727c9313424fb2 (diff) | |
download | src-315d10f09ee888005b1da55e7bbb57d8a79b8447.tar.gz src-315d10f09ee888005b1da55e7bbb57d8a79b8447.zip |
Vendor import of libc++ trunk r338536:vendor/libc++/libc++-trunk-r338536
Notes
Notes:
svn path=/vendor/libc++/dist/; revision=337143
svn path=/vendor/libc++/libc++-trunk-r338536/; revision=337144; tag=vendor/libc++/libc++-trunk-r338536
Diffstat (limited to 'test/std/containers/unord/unord.multiset')
4 files changed, 266 insertions, 0 deletions
diff --git a/test/std/containers/unord/unord.multiset/extract_iterator.pass.cpp b/test/std/containers/unord/unord.multiset/extract_iterator.pass.cpp new file mode 100644 index 000000000000..1595c55a4236 --- /dev/null +++ b/test/std/containers/unord/unord.multiset/extract_iterator.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. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03, c++11, c++14 + +// <unordered_set> + +// class unordered_multiset + +// node_type extract(const_iterator); + +#include <unordered_set> +#include "min_allocator.h" +#include "Counter.h" + +template <class Container> +void test(Container& c) +{ + size_t sz = c.size(); + + for (auto first = c.cbegin(); first != c.cend();) + { + auto key_value = *first; + typename Container::node_type t = c.extract(first++); + --sz; + assert(t.value() == key_value); + assert(t.get_allocator() == c.get_allocator()); + assert(sz == c.size()); + } + + assert(c.size() == 0); +} + +int main() +{ + { + using set_type = std::unordered_multiset<int>; + set_type m = {1, 2, 3, 4, 5, 6}; + test(m); + } + + { + std::unordered_multiset<Counter<int>> m = {1, 2, 3, 4, 5, 6}; + assert(Counter_base::gConstructed == 6); + test(m); + assert(Counter_base::gConstructed == 0); + } + + { + using min_alloc_set = std::unordered_multiset<int, std::hash<int>, std::equal_to<int>, min_allocator<int>>; + min_alloc_set m = {1, 2, 3, 4, 5, 6}; + test(m); + } +} diff --git a/test/std/containers/unord/unord.multiset/extract_key.pass.cpp b/test/std/containers/unord/unord.multiset/extract_key.pass.cpp new file mode 100644 index 000000000000..ffe46fb30f17 --- /dev/null +++ b/test/std/containers/unord/unord.multiset/extract_key.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. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03, c++11, c++14 + +// <unordered_multiset> + +// class unordered_multiset + +// node_type extract(key_type const&); + +#include <unordered_set> +#include "min_allocator.h" +#include "Counter.h" + +template <class Container, class KeyTypeIter> +void test(Container& c, KeyTypeIter first, KeyTypeIter last) +{ + size_t sz = c.size(); + assert((size_t)std::distance(first, last) == sz); + + for (KeyTypeIter copy = first; copy != last; ++copy) + { + typename Container::node_type t = c.extract(*copy); + assert(!t.empty()); + --sz; + assert(t.value() == *copy); + assert(t.get_allocator() == c.get_allocator()); + assert(sz == c.size()); + } + + assert(c.size() == 0); + + for (KeyTypeIter copy = first; copy != last; ++copy) + { + typename Container::node_type t = c.extract(*copy); + assert(t.empty()); + } +} + +int main() +{ + { + std::unordered_multiset<int> m = {1, 2, 3, 4, 5, 6}; + int keys[] = {1, 2, 3, 4, 5, 6}; + test(m, std::begin(keys), std::end(keys)); + } + + { + std::unordered_multiset<Counter<int>> m = {1, 2, 3, 4, 5, 6}; + { + Counter<int> keys[] = {1, 2, 3, 4, 5, 6}; + assert(Counter_base::gConstructed == 6+6); + test(m, std::begin(keys), std::end(keys)); + } + assert(Counter_base::gConstructed == 0); + } + + { + using min_alloc_set = std::unordered_multiset<int, std::hash<int>, std::equal_to<int>, min_allocator<int>>; + min_alloc_set m = {1, 2, 3, 4, 5, 6}; + int keys[] = {1, 2, 3, 4, 5, 6}; + test(m, std::begin(keys), std::end(keys)); + } +} diff --git a/test/std/containers/unord/unord.multiset/insert_node_type.pass.cpp b/test/std/containers/unord/unord.multiset/insert_node_type.pass.cpp new file mode 100644 index 000000000000..c3d4cd2a0e8c --- /dev/null +++ b/test/std/containers/unord/unord.multiset/insert_node_type.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. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03, c++11, c++14 + +// <unordered_set> + +// class unordered_multiset + +// iterator insert(node_type&&); + +#include <unordered_set> +#include <type_traits> +#include "min_allocator.h" + +template <class Container> +typename Container::node_type +node_factory(typename Container::key_type const& key) +{ + static Container c; + auto it = c.insert(key); + return c.extract(it); +} + +template <class Container> +void test(Container& c) +{ + auto* nf = &node_factory<Container>; + + for (int i = 0; i != 10; ++i) + { + typename Container::node_type node = nf(i); + assert(!node.empty()); + typename Container::iterator it = c.insert(std::move(node)); + assert(node.empty()); + assert(it == c.find(i) && it != c.end()); + assert(*it == i); + assert(node.empty()); + } + + assert(c.size() == 10); + + { // Insert empty node. + typename Container::node_type def; + auto it = c.insert(std::move(def)); + assert(def.empty()); + assert(it == c.end()); + } + + { // Insert duplicate node. + typename Container::node_type dupl = nf(0); + auto it = c.insert(std::move(dupl)); + assert(*it == 0); + } + + assert(c.size() == 11); + assert(c.count(0) == 2); + for (int i = 1; i != 10; ++i) + { + assert(c.count(i) == 1); + } +} + +int main() +{ + std::unordered_multiset<int> m; + test(m); + std::unordered_multiset<int, std::hash<int>, std::equal_to<int>, min_allocator<int>> m2; + test(m2); +} diff --git a/test/std/containers/unord/unord.multiset/insert_node_type_hint.pass.cpp b/test/std/containers/unord/unord.multiset/insert_node_type_hint.pass.cpp new file mode 100644 index 000000000000..79712d3ded79 --- /dev/null +++ b/test/std/containers/unord/unord.multiset/insert_node_type_hint.pass.cpp @@ -0,0 +1,59 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03, c++11, c++14 + +// <unordered_set> + +// class unordered_multiset + +// iterator insert(const_iterator hint, node_type&&); + +#include <unordered_set> +#include "min_allocator.h" + +template <class Container> +typename Container::node_type +node_factory(typename Container::key_type const& key) +{ + static Container c; + auto it = c.insert(key); + return c.extract(it); +} + +template <class Container> +void test(Container& c) +{ + auto* nf = &node_factory<Container>; + + for (int i = 0; i != 10; ++i) + { + typename Container::node_type node = nf(i); + assert(!node.empty()); + size_t prev = c.size(); + auto it = c.insert(c.end(), std::move(node)); + assert(prev + 1 == c.size()); + assert(*it == i); + } + + assert(c.size() == 10); + + for (int i = 0; i != 10; ++i) + { + assert(c.count(i) == 1); + } +} + +int main() +{ + std::unordered_multiset<int> m; + test(m); + std::unordered_multiset<int, std::hash<int>, std::equal_to<int>, min_allocator<int>> m2; + test(m2); +} |