From b0386a515b60c2f43eaaef986bd5b1cdc4448244 Mon Sep 17 00:00:00 2001 From: Erik Pilkington Date: Wed, 1 Aug 2018 01:33:38 +0000 Subject: First half of C++17's splicing maps and sets This commit adds a node handle type, (located in __node_handle), and adds extract() and insert() members to all map and set types, as well as their implementations in __tree and __hash_table. The second half of this feature is adding merge() members, which splice nodes in bulk from one container into another. This will be committed in a follow-up. Differential revision: https://reviews.llvm.org/D46845 llvm-svn: 338472 --- .../map/map.modifiers/extract_iterator.pass.cpp | 67 ++++++++++ .../map/map.modifiers/extract_key.pass.cpp | 76 +++++++++++ .../map/map.modifiers/insert_node_type.pass.cpp | 85 ++++++++++++ .../map.modifiers/insert_node_type_hint.pass.cpp | 64 +++++++++ .../multimap.modifiers/extract_iterator.pass.cpp | 67 ++++++++++ .../multimap.modifiers/extract_key.pass.cpp | 76 +++++++++++ .../multimap.modifiers/insert_node_type.pass.cpp | 78 +++++++++++ .../insert_node_type_hint.pass.cpp | 64 +++++++++ .../associative/multiset/extract_iterator.pass.cpp | 60 +++++++++ .../associative/multiset/extract_key.pass.cpp | 71 ++++++++++ .../associative/multiset/insert_node_type.pass.cpp | 77 +++++++++++ .../multiset/insert_node_type_hint.pass.cpp | 59 +++++++++ .../associative/set/extract_iterator.pass.cpp | 60 +++++++++ .../associative/set/extract_key.pass.cpp | 71 ++++++++++ .../associative/set/insert_node_type.pass.cpp | 83 ++++++++++++ .../associative/set/insert_node_type_hint.pass.cpp | 61 +++++++++ .../containers/container.node/node_handle.pass.cpp | 145 +++++++++++++++++++++ .../unord.map.modifiers/extract_iterator.pass.cpp | 67 ++++++++++ .../unord.map.modifiers/extract_key.pass.cpp | 76 +++++++++++ .../unord.map.modifiers/insert_node_type.pass.cpp | 84 ++++++++++++ .../insert_node_type_hint.pass.cpp | 64 +++++++++ .../extract_iterator.pass.cpp | 67 ++++++++++ .../unord.multimap.modifiers/extract_key.pass.cpp | 77 +++++++++++ .../insert_node_type.pass.cpp | 77 +++++++++++ .../insert_node_type_hint.pass.cpp | 63 +++++++++ .../unord/unord.multiset/extract_iterator.pass.cpp | 60 +++++++++ .../unord/unord.multiset/extract_key.pass.cpp | 71 ++++++++++ .../unord/unord.multiset/insert_node_type.pass.cpp | 76 +++++++++++ .../unord.multiset/insert_node_type_hint.pass.cpp | 59 +++++++++ .../unord/unord.set/extract_iterator.pass.cpp | 60 +++++++++ .../unord/unord.set/extract_key.pass.cpp | 71 ++++++++++ .../unord/unord.set/insert_node_type.pass.cpp | 83 ++++++++++++ .../unord/unord.set/insert_node_type_hint.pass.cpp | 61 +++++++++ libcxx/test/support/Counter.h | 4 +- 34 files changed, 2382 insertions(+), 2 deletions(-) create mode 100644 libcxx/test/std/containers/associative/map/map.modifiers/extract_iterator.pass.cpp create mode 100644 libcxx/test/std/containers/associative/map/map.modifiers/extract_key.pass.cpp create mode 100644 libcxx/test/std/containers/associative/map/map.modifiers/insert_node_type.pass.cpp create mode 100644 libcxx/test/std/containers/associative/map/map.modifiers/insert_node_type_hint.pass.cpp create mode 100644 libcxx/test/std/containers/associative/multimap/multimap.modifiers/extract_iterator.pass.cpp create mode 100644 libcxx/test/std/containers/associative/multimap/multimap.modifiers/extract_key.pass.cpp create mode 100644 libcxx/test/std/containers/associative/multimap/multimap.modifiers/insert_node_type.pass.cpp create mode 100644 libcxx/test/std/containers/associative/multimap/multimap.modifiers/insert_node_type_hint.pass.cpp create mode 100644 libcxx/test/std/containers/associative/multiset/extract_iterator.pass.cpp create mode 100644 libcxx/test/std/containers/associative/multiset/extract_key.pass.cpp create mode 100644 libcxx/test/std/containers/associative/multiset/insert_node_type.pass.cpp create mode 100644 libcxx/test/std/containers/associative/multiset/insert_node_type_hint.pass.cpp create mode 100644 libcxx/test/std/containers/associative/set/extract_iterator.pass.cpp create mode 100644 libcxx/test/std/containers/associative/set/extract_key.pass.cpp create mode 100644 libcxx/test/std/containers/associative/set/insert_node_type.pass.cpp create mode 100644 libcxx/test/std/containers/associative/set/insert_node_type_hint.pass.cpp create mode 100644 libcxx/test/std/containers/container.node/node_handle.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.map/unord.map.modifiers/extract_iterator.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.map/unord.map.modifiers/extract_key.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.map/unord.map.modifiers/insert_node_type.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.map/unord.map.modifiers/insert_node_type_hint.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/extract_iterator.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/extract_key.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/insert_node_type.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/insert_node_type_hint.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multiset/extract_iterator.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multiset/extract_key.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multiset/insert_node_type.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multiset/insert_node_type_hint.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.set/extract_iterator.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.set/extract_key.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.set/insert_node_type.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.set/insert_node_type_hint.pass.cpp (limited to 'libcxx/test') diff --git a/libcxx/test/std/containers/associative/map/map.modifiers/extract_iterator.pass.cpp b/libcxx/test/std/containers/associative/map/map.modifiers/extract_iterator.pass.cpp new file mode 100644 index 00000000000..ea7fd890764 --- /dev/null +++ b/libcxx/test/std/containers/associative/map/map.modifiers/extract_iterator.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. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03, c++11, c++14 + +// + +// class map + +// node_type extract(const_iterator); + +#include +#include "min_allocator.h" +#include "Counter.h" + +template +void test(Container& c) +{ + size_t sz = c.size(); + + auto some_key = c.cbegin()->first; + + for (auto first = c.cbegin(); first != c.cend();) + { + auto key_value = first->first; + typename Container::node_type t = c.extract(first++); + --sz; + assert(t.key() == key_value); + t.key() = some_key; + assert(t.key() == some_key); + assert(t.get_allocator() == c.get_allocator()); + assert(sz == c.size()); + } + + assert(c.size() == 0); +} + +int main() +{ + { + using map_type = std::map; + map_type m = {{1,1}, {2,2}, {3,3}, {4,4}, {5,5}, {6,6}}; + test(m); + } + + { + std::map, Counter> m = + {{1,1}, {2,2}, {3,3}, {4,4}, {5,5}, {6,6}}; + assert(Counter_base::gConstructed == 12); + test(m); + assert(Counter_base::gConstructed == 0); + } + + { + using min_alloc_map = + std::map, + min_allocator>>; + min_alloc_map m = {{1, 1}, {2, 2}, {3, 3}, {4, 4}, {5, 5}, {6, 6}}; + test(m); + } +} diff --git a/libcxx/test/std/containers/associative/map/map.modifiers/extract_key.pass.cpp b/libcxx/test/std/containers/associative/map/map.modifiers/extract_key.pass.cpp new file mode 100644 index 00000000000..41cd09300b2 --- /dev/null +++ b/libcxx/test/std/containers/associative/map/map.modifiers/extract_key.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 + +// + +// class map + +// node_type extract(key_type const&); + +#include +#include "min_allocator.h" +#include "Counter.h" + +template +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.key() == *copy); + t.key() = *first; // We should be able to mutate key. + assert(t.key() == *first); + 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::map m = {{1,1}, {2,2}, {3,3}, {4,4}, {5,5}, {6,6}}; + int keys[] = {1, 2, 3, 4, 5, 6}; + test(m, std::begin(keys), std::end(keys)); + } + + { + std::map, Counter> m = + {{1,1}, {2,2}, {3,3}, {4,4}, {5,5}, {6,6}}; + { + Counter keys[] = {1, 2, 3, 4, 5, 6}; + assert(Counter_base::gConstructed == 12+6); + test(m, std::begin(keys), std::end(keys)); + } + assert(Counter_base::gConstructed == 0); + } + + { + using min_alloc_map = + std::map, + min_allocator>>; + min_alloc_map m = {{1, 1}, {2, 2}, {3, 3}, {4, 4}, {5, 5}, {6, 6}}; + int keys[] = {1, 2, 3, 4, 5, 6}; + test(m, std::begin(keys), std::end(keys)); + } +} diff --git a/libcxx/test/std/containers/associative/map/map.modifiers/insert_node_type.pass.cpp b/libcxx/test/std/containers/associative/map/map.modifiers/insert_node_type.pass.cpp new file mode 100644 index 00000000000..cc1704c3087 --- /dev/null +++ b/libcxx/test/std/containers/associative/map/map.modifiers/insert_node_type.pass.cpp @@ -0,0 +1,85 @@ +//===----------------------------------------------------------------------===// +// +// 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 + +// + +// class map + +// insert_return_type insert(node_type&&); + +#include +#include +#include "min_allocator.h" + +template +typename Container::node_type +node_factory(typename Container::key_type const& key, + typename Container::mapped_type const& mapped) +{ + static Container c; + auto p = c.insert({key, mapped}); + assert(p.second); + return c.extract(p.first); +} + +template +void test(Container& c) +{ + auto* nf = &node_factory; + + for (int i = 0; i != 10; ++i) + { + typename Container::node_type node = nf(i, i + 1); + assert(!node.empty()); + typename Container::insert_return_type irt = c.insert(std::move(node)); + assert(node.empty()); + assert(irt.inserted); + assert(irt.node.empty()); + assert(irt.position->first == i && irt.position->second == i + 1); + } + + assert(c.size() == 10); + + { // Insert empty node. + typename Container::node_type def; + auto irt = c.insert(std::move(def)); + assert(def.empty()); + assert(!irt.inserted); + assert(irt.node.empty()); + assert(irt.position == c.end()); + } + + { // Insert duplicate node. + typename Container::node_type dupl = nf(0, 42); + auto irt = c.insert(std::move(dupl)); + assert(dupl.empty()); + assert(!irt.inserted); + assert(!irt.node.empty()); + assert(irt.position == c.find(0)); + assert(irt.node.key() == 0 && irt.node.mapped() == 42); + } + + assert(c.size() == 10); + + for (int i = 0; i != 10; ++i) + { + assert(c.count(i) == 1); + assert(c[i] == i + 1); + } +} + +int main() +{ + std::map m; + test(m); + std::map, min_allocator>> m2; + test(m2); +} diff --git a/libcxx/test/std/containers/associative/map/map.modifiers/insert_node_type_hint.pass.cpp b/libcxx/test/std/containers/associative/map/map.modifiers/insert_node_type_hint.pass.cpp new file mode 100644 index 00000000000..3c6b3e31af4 --- /dev/null +++ b/libcxx/test/std/containers/associative/map/map.modifiers/insert_node_type_hint.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. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03, c++11, c++14 + +// + +// class map + +// iterator insert(const_iterator hint, node_type&&); + +#include +#include "min_allocator.h" + +template +typename Container::node_type +node_factory(typename Container::key_type const& key, + typename Container::mapped_type const& mapped) +{ + static Container c; + auto p = c.insert({key, mapped}); + assert(p.second); + return c.extract(p.first); +} + +template +void test(Container& c) +{ + auto* nf = &node_factory; + + for (int i = 0; i != 10; ++i) + { + typename Container::node_type node = nf(i, i + 1); + assert(!node.empty()); + size_t prev = c.size(); + auto it = c.insert(c.end(), std::move(node)); + assert(node.empty()); + assert(prev + 1 == c.size()); + assert(it->first == i); + assert(it->second == i + 1); + } + + assert(c.size() == 10); + + for (int i = 0; i != 10; ++i) + { + assert(c.count(i) == 1); + assert(c[i] == i + 1); + } +} + +int main() +{ + std::map m; + test(m); + std::map, min_allocator>> m2; + test(m2); +} diff --git a/libcxx/test/std/containers/associative/multimap/multimap.modifiers/extract_iterator.pass.cpp b/libcxx/test/std/containers/associative/multimap/multimap.modifiers/extract_iterator.pass.cpp new file mode 100644 index 00000000000..3e00d2b98d7 --- /dev/null +++ b/libcxx/test/std/containers/associative/multimap/multimap.modifiers/extract_iterator.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. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03, c++11, c++14 + +// + +// class multimap + +// node_type extract(const_iterator); + +#include +#include "min_allocator.h" +#include "Counter.h" + +template +void test(Container& c) +{ + size_t sz = c.size(); + + auto some_key = c.cbegin()->first; + + for (auto first = c.cbegin(); first != c.cend();) + { + auto key_value = first->first; + typename Container::node_type t = c.extract(first++); + --sz; + assert(t.key() == key_value); + t.key() = some_key; + assert(t.key() == some_key); + assert(t.get_allocator() == c.get_allocator()); + assert(sz == c.size()); + } + + assert(c.size() == 0); +} + +int main() +{ + { + using map_type = std::multimap; + map_type m = {{1,1}, {2,2}, {3,3}, {4,4}, {5,5}, {6,6}}; + test(m); + } + + { + std::multimap, Counter> m = + {{1,1}, {2,2}, {3,3}, {4,4}, {5,5}, {6,6}}; + assert(Counter_base::gConstructed == 12); + test(m); + assert(Counter_base::gConstructed == 0); + } + + { + using min_alloc_map = + std::multimap, + min_allocator>>; + min_alloc_map m = {{1, 1}, {2, 2}, {3, 3}, {4, 4}, {5, 5}, {6, 6}}; + test(m); + } +} diff --git a/libcxx/test/std/containers/associative/multimap/multimap.modifiers/extract_key.pass.cpp b/libcxx/test/std/containers/associative/multimap/multimap.modifiers/extract_key.pass.cpp new file mode 100644 index 00000000000..ca69cca6b0e --- /dev/null +++ b/libcxx/test/std/containers/associative/multimap/multimap.modifiers/extract_key.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 + +// + +// class multimap + +// node_type extract(key_type const&); + +#include +#include "min_allocator.h" +#include "Counter.h" + +template +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.key() == *copy); + t.key() = *first; // We should be able to mutate key. + assert(t.key() == *first); + 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::multimap m = {{1,1}, {2,2}, {3,3}, {4,4}, {5,5}, {6,6}}; + int keys[] = {1, 2, 3, 4, 5, 6}; + test(m, std::begin(keys), std::end(keys)); + } + + { + std::multimap, Counter> m = + {{1,1}, {2,2}, {3,3}, {4,4}, {5,5}, {6,6}}; + { + Counter keys[] = {1, 2, 3, 4, 5, 6}; + assert(Counter_base::gConstructed == 12+6); + test(m, std::begin(keys), std::end(keys)); + } + assert(Counter_base::gConstructed == 0); + } + + { + using min_alloc_map = + std::multimap, + min_allocator>>; + min_alloc_map m = {{1, 1}, {2, 2}, {3, 3}, {4, 4}, {5, 5}, {6, 6}}; + int keys[] = {1, 2, 3, 4, 5, 6}; + test(m, std::begin(keys), std::end(keys)); + } +} diff --git a/libcxx/test/std/containers/associative/multimap/multimap.modifiers/insert_node_type.pass.cpp b/libcxx/test/std/containers/associative/multimap/multimap.modifiers/insert_node_type.pass.cpp new file mode 100644 index 00000000000..90677051419 --- /dev/null +++ b/libcxx/test/std/containers/associative/multimap/multimap.modifiers/insert_node_type.pass.cpp @@ -0,0 +1,78 @@ +//===----------------------------------------------------------------------===// +// +// 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 + +// + +// class multimap + +// iterator insert(node_type&&); + +#include +#include +#include "min_allocator.h" + +template +typename Container::node_type +node_factory(typename Container::key_type const& key, + typename Container::mapped_type const& mapped) +{ + static Container c; + auto it = c.insert({key, mapped}); + return c.extract(it); +} + +template +void test(Container& c) +{ + auto* nf = &node_factory; + + for (int i = 0; i != 10; ++i) + { + typename Container::node_type node = nf(i, i + 1); + assert(!node.empty()); + typename Container::iterator it = c.insert(std::move(node)); + assert(node.empty()); + assert(it == c.find(i) && it != c.end()); + } + + 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, 42); + auto it = c.insert(std::move(dupl)); + assert(dupl.empty()); + assert(it != c.end()); + assert(it->second == 42); + } + + assert(c.size() == 11); + assert(c.count(0) == 2); + for (int i = 1; i != 10; ++i) + { + assert(c.count(i) == 1); + assert(c.find(i)->second == i + 1); + } +} + +int main() +{ + std::multimap m; + test(m); + std::multimap, min_allocator>> m2; + test(m2); +} diff --git a/libcxx/test/std/containers/associative/multimap/multimap.modifiers/insert_node_type_hint.pass.cpp b/libcxx/test/std/containers/associative/multimap/multimap.modifiers/insert_node_type_hint.pass.cpp new file mode 100644 index 00000000000..82e7d80c06e --- /dev/null +++ b/libcxx/test/std/containers/associative/multimap/multimap.modifiers/insert_node_type_hint.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. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03, c++11, c++14 + +// + +// class multimap + +// iterator insert(const_iterator hint, node_type&&); + +#include +#include "min_allocator.h" + +template +typename Container::node_type +node_factory(typename Container::key_type const& key, + typename Container::mapped_type const& mapped) +{ + static Container c; + auto it = c.insert({key, mapped}); + return c.extract(it); +} + +template +void test(Container& c) +{ + auto* nf = &node_factory; + + for (int i = 0; i != 10; ++i) + { + typename Container::node_type node = nf(i, i + 1); + assert(!node.empty()); + size_t prev = c.size(); + auto it = c.insert(c.end(), std::move(node)); + assert(node.empty()); + assert(prev + 1 == c.size()); + assert(it == c.find(i)); + assert(it->first == i); + assert(it->second == i + 1); + } + + assert(c.size() == 10); + + for (int i = 0; i != 10; ++i) + { + assert(c.count(i) == 1); + assert(c.find(i)->second == i + 1); + } +} + +int main() +{ + std::multimap m; + test(m); + std::multimap, min_allocator>> m2; + test(m2); +} diff --git a/libcxx/test/std/containers/associative/multiset/extract_iterator.pass.cpp b/libcxx/test/std/containers/associative/multiset/extract_iterator.pass.cpp new file mode 100644 index 00000000000..0f41169e9fe --- /dev/null +++ b/libcxx/test/std/containers/associative/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 + +// + +// class multiset + +// node_type extract(const_iterator); + +#include +#include "min_allocator.h" +#include "Counter.h" + +template +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::multiset; + set_type m = {1, 2, 3, 4, 5, 6}; + test(m); + } + + { + std::multiset> m = {1, 2, 3, 4, 5, 6}; + assert(Counter_base::gConstructed == 6); + test(m); + assert(Counter_base::gConstructed == 0); + } + + { + using min_alloc_set = std::multiset, min_allocator>; + min_alloc_set m = {1, 2, 3, 4, 5, 6}; + test(m); + } +} diff --git a/libcxx/test/std/containers/associative/multiset/extract_key.pass.cpp b/libcxx/test/std/containers/associative/multiset/extract_key.pass.cpp new file mode 100644 index 00000000000..9ad0184100b --- /dev/null +++ b/libcxx/test/std/containers/associative/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 + +// + +// class multiset + +// node_type extract(key_type const&); + +#include +#include "min_allocator.h" +#include "Counter.h" + +template +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::multiset m = {1, 2, 3, 4, 5, 6}; + int keys[] = {1, 2, 3, 4, 5, 6}; + test(m, std::begin(keys), std::end(keys)); + } + + { + std::multiset> m = {1, 2, 3, 4, 5, 6}; + { + Counter 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::multiset, min_allocator>; + 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/libcxx/test/std/containers/associative/multiset/insert_node_type.pass.cpp b/libcxx/test/std/containers/associative/multiset/insert_node_type.pass.cpp new file mode 100644 index 00000000000..ca51ec9f093 --- /dev/null +++ b/libcxx/test/std/containers/associative/multiset/insert_node_type.pass.cpp @@ -0,0 +1,77 @@ +//===----------------------------------------------------------------------===// +// +// 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 + +// + +// class multiset + +// iterator insert(node_type&&); + +#include +#include +#include "min_allocator.h" + +template +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 +void test(Container& c) +{ + auto* nf = &node_factory; + + 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::multiset m; + test(m); + std::multiset, min_allocator> m2; + test(m2); +} diff --git a/libcxx/test/std/containers/associative/multiset/insert_node_type_hint.pass.cpp b/libcxx/test/std/containers/associative/multiset/insert_node_type_hint.pass.cpp new file mode 100644 index 00000000000..9d0af0653f6 --- /dev/null +++ b/libcxx/test/std/containers/associative/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 + +// + +// class multiset + +// iterator insert(const_iterator hint, node_type&&); + +#include +#include "min_allocator.h" + +template +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 +void test(Container& c) +{ + auto* nf = &node_factory; + + 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::multiset m; + test(m); + std::multiset, min_allocator> m2; + test(m2); +} diff --git a/libcxx/test/std/containers/associative/set/extract_iterator.pass.cpp b/libcxx/test/std/containers/associative/set/extract_iterator.pass.cpp new file mode 100644 index 00000000000..ffcf7148688 --- /dev/null +++ b/libcxx/test/std/containers/associative/set/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 + +// + +// class set + +// node_type extract(const_iterator); + +#include +#include "min_allocator.h" +#include "Counter.h" + +template +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::set; + set_type m = {1, 2, 3, 4, 5, 6}; + test(m); + } + + { + std::set> m = {1, 2, 3, 4, 5, 6}; + assert(Counter_base::gConstructed == 6); + test(m); + assert(Counter_base::gConstructed == 0); + } + + { + using min_alloc_set = std::set, min_allocator>; + min_alloc_set m = {1, 2, 3, 4, 5, 6}; + test(m); + } +} diff --git a/libcxx/test/std/containers/associative/set/extract_key.pass.cpp b/libcxx/test/std/containers/associative/set/extract_key.pass.cpp new file mode 100644 index 00000000000..1fb7ab9116e --- /dev/null +++ b/libcxx/test/std/containers/associative/set/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 + +// + +// class set + +// node_type extract(key_type const&); + +#include +#include "min_allocator.h" +#include "Counter.h" + +template +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::set m = {1, 2, 3, 4, 5, 6}; + int keys[] = {1, 2, 3, 4, 5, 6}; + test(m, std::begin(keys), std::end(keys)); + } + + { + std::set> m = {1, 2, 3, 4, 5, 6}; + { + Counter 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::set, min_allocator>; + 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/libcxx/test/std/containers/associative/set/insert_node_type.pass.cpp b/libcxx/test/std/containers/associative/set/insert_node_type.pass.cpp new file mode 100644 index 00000000000..4186f20e771 --- /dev/null +++ b/libcxx/test/std/containers/associative/set/insert_node_type.pass.cpp @@ -0,0 +1,83 @@ +//===----------------------------------------------------------------------===// +// +// 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 + +// + +// class set + +// insert_return_type insert(node_type&&); + +#include +#include +#include "min_allocator.h" + +template +typename Container::node_type +node_factory(typename Container::key_type const& key) +{ + static Container c; + auto p = c.insert(key); + assert(p.second); + return c.extract(p.first); +} + +template +void test(Container& c) +{ + auto* nf = &node_factory; + + for (int i = 0; i != 10; ++i) + { + typename Container::node_type node = nf(i); + assert(!node.empty()); + typename Container::insert_return_type irt = c.insert(std::move(node)); + assert(node.empty()); + assert(irt.inserted); + assert(irt.node.empty()); + assert(*irt.position == i); + } + + assert(c.size() == 10); + + { // Insert empty node. + typename Container::node_type def; + auto irt = c.insert(std::move(def)); + assert(def.empty()); + assert(!irt.inserted); + assert(irt.node.empty()); + assert(irt.position == c.end()); + } + + { // Insert duplicate node. + typename Container::node_type dupl = nf(0); + auto irt = c.insert(std::move(dupl)); + assert(dupl.empty()); + assert(!irt.inserted); + assert(!irt.node.empty()); + assert(irt.position == c.find(0)); + assert(irt.node.value() == 0); + } + + assert(c.size() == 10); + + for (int i = 0; i != 10; ++i) + { + assert(c.count(i) == 1); + } +} + +int main() +{ + std::set m; + test(m); + std::set, min_allocator> m2; + test(m2); +} diff --git a/libcxx/test/std/containers/associative/set/insert_node_type_hint.pass.cpp b/libcxx/test/std/containers/associative/set/insert_node_type_hint.pass.cpp new file mode 100644 index 00000000000..761ceef6a4a --- /dev/null +++ b/libcxx/test/std/containers/associative/set/insert_node_type_hint.pass.cpp @@ -0,0 +1,61 @@ +//===----------------------------------------------------------------------===// +// +// 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 + +// + +// class set + +// iterator insert(const_iterator hint, node_type&&); + +#include +#include "min_allocator.h" + +template +typename Container::node_type +node_factory(typename Container::key_type const& key) +{ + static Container c; + auto p = c.insert(key); + assert(p.second); + return c.extract(p.first); +} + +template +void test(Container& c) +{ + auto* nf = &node_factory; + + 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(node.empty()); + 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::set m; + test(m); + std::set, min_allocator> m2; + test(m2); +} diff --git a/libcxx/test/std/containers/container.node/node_handle.pass.cpp b/libcxx/test/std/containers/container.node/node_handle.pass.cpp new file mode 100644 index 00000000000..6314ec1fb77 --- /dev/null +++ b/libcxx/test/std/containers/container.node/node_handle.pass.cpp @@ -0,0 +1,145 @@ +//===----------------------------------------------------------------------===// +// +// 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 + +#include +#include +#include +#include +#include "min_allocator.h" + +using namespace std; + +// [container.node.overview] Table 83. +template +struct node_compatibility_table +{ + static constexpr bool value = + is_same_v::node_type, typename map::node_type> && + is_same_v::node_type, typename multimap::node_type> && + is_same_v::node_type, typename set::node_type> && + is_same_v::node_type, typename multiset::node_type> && + is_same_v::node_type, typename unordered_map::node_type> && + is_same_v::node_type, typename unordered_multimap::node_type> && + is_same_v::node_type, typename unordered_set::node_type> && + is_same_v::node_type, typename unordered_multiset::node_type>; +}; + +template struct my_hash +{ + using argument_type = T; + using result_type = size_t; + my_hash() = default; + size_t operator()(const T&) const {return 0;} +}; + +template struct my_compare +{ + my_compare() = default; + bool operator()(const T&, const T&) const {return true;} +}; + +template struct my_equal +{ + my_equal() = default; + bool operator()(const T&, const T&) const {return true;} +}; + +struct Static +{ + Static() = default; + Static(const Static&) = delete; + Static(Static&&) = delete; + Static& operator=(const Static&) = delete; + Static& operator=(Static&&) = delete; +}; + +namespace std +{ +template <> struct hash +{ + using argument_type = Static; + using result_type = size_t; + hash() = default; + size_t operator()(const Static&) const; +}; +} + +static_assert(node_compatibility_table< + int, int, std::less, std::less, std::hash, + std::hash, std::equal_to, std::equal_to, + std::allocator, + std::allocator>>::value, + ""); + +static_assert( + node_compatibility_table, my_compare, + std::hash, my_hash, std::equal_to, + my_equal, allocator, + allocator>>::value, + ""); + +static_assert(node_compatibility_table< + Static, int, my_compare, std::less, + my_hash, std::hash, my_equal, + std::equal_to, min_allocator, + min_allocator>>::value, + ""); + +template +void test_node_handle_operations() +{ + Container c; + + typename Container::node_type nt1, nt2 = c.extract(c.emplace().first); + assert(nt2.get_allocator() == c.get_allocator()); + assert(!nt2.empty()); + assert(nt1.empty()); + std::swap(nt1, nt2); + assert(nt1.get_allocator() == c.get_allocator()); + assert(nt2.empty()); +} + +template +void test_node_handle_operations_multi() +{ + Container c; + + typename Container::node_type nt1, nt2 = c.extract(c.emplace()); + assert(nt2.get_allocator() == c.get_allocator()); + assert(!nt2.empty()); + assert(nt1.empty()); + std::swap(nt1, nt2); + assert(nt1.get_allocator() == c.get_allocator()); + assert(nt2.empty()); +} + +template +void test_insert_return_type() +{ + using irt_type = typename Container::insert_return_type; +} + +int main() +{ + test_node_handle_operations>(); + test_node_handle_operations_multi>(); + test_node_handle_operations>(); + test_node_handle_operations_multi>(); + test_node_handle_operations>(); + test_node_handle_operations_multi>(); + test_node_handle_operations>(); + test_node_handle_operations_multi>(); + + test_insert_return_type>(); + test_insert_return_type>(); + test_insert_return_type>(); + test_insert_return_type>(); +} diff --git a/libcxx/test/std/containers/unord/unord.map/unord.map.modifiers/extract_iterator.pass.cpp b/libcxx/test/std/containers/unord/unord.map/unord.map.modifiers/extract_iterator.pass.cpp new file mode 100644 index 00000000000..4cc13ded23f --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.map/unord.map.modifiers/extract_iterator.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. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03, c++11, c++14 + +// + +// class unordered_map + +// node_type extract(const_iterator); + +#include +#include "min_allocator.h" +#include "Counter.h" + +template +void test(Container& c) +{ + size_t sz = c.size(); + + auto some_key = c.cbegin()->first; + + for (auto first = c.cbegin(); first != c.cend();) + { + auto key_value = first->first; + typename Container::node_type t = c.extract(first++); + --sz; + assert(t.key() == key_value); + t.key() = some_key; + assert(t.key() == some_key); + assert(t.get_allocator() == c.get_allocator()); + assert(sz == c.size()); + } + + assert(c.size() == 0); +} + +int main() +{ + { + using map_type = std::unordered_map; + map_type m = {{1,1}, {2,2}, {3,3}, {4,4}, {5,5}, {6,6}}; + test(m); + } + + { + std::unordered_map, Counter> m = + {{1,1}, {2,2}, {3,3}, {4,4}, {5,5}, {6,6}}; + assert(Counter_base::gConstructed == 12); + test(m); + assert(Counter_base::gConstructed == 0); + } + + { + using min_alloc_map = + std::unordered_map, std::equal_to, + min_allocator>>; + min_alloc_map m = {{1, 1}, {2, 2}, {3, 3}, {4, 4}, {5, 5}, {6, 6}}; + test(m); + } +} diff --git a/libcxx/test/std/containers/unord/unord.map/unord.map.modifiers/extract_key.pass.cpp b/libcxx/test/std/containers/unord/unord.map/unord.map.modifiers/extract_key.pass.cpp new file mode 100644 index 00000000000..25aa2488886 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.map/unord.map.modifiers/extract_key.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 + +// + +// class unordered_map + +// node_type extract(key_type const&); + +#include +#include "min_allocator.h" +#include "Counter.h" + +template +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.key() == *copy); + t.key() = *first; // We should be able to mutate key. + assert(t.key() == *first); + 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_map m = {{1,1}, {2,2}, {3,3}, {4,4}, {5,5}, {6,6}}; + int keys[] = {1, 2, 3, 4, 5, 6}; + test(m, std::begin(keys), std::end(keys)); + } + + { + std::unordered_map, Counter> m = + {{1,1}, {2,2}, {3,3}, {4,4}, {5,5}, {6,6}}; + { + Counter keys[] = {1, 2, 3, 4, 5, 6}; + assert(Counter_base::gConstructed == 12+6); + test(m, std::begin(keys), std::end(keys)); + } + assert(Counter_base::gConstructed == 0); + } + + { + using min_alloc_map = + std::unordered_map, std::equal_to, + min_allocator>>; + min_alloc_map m = {{1, 1}, {2, 2}, {3, 3}, {4, 4}, {5, 5}, {6, 6}}; + int keys[] = {1, 2, 3, 4, 5, 6}; + test(m, std::begin(keys), std::end(keys)); + } +} diff --git a/libcxx/test/std/containers/unord/unord.map/unord.map.modifiers/insert_node_type.pass.cpp b/libcxx/test/std/containers/unord/unord.map/unord.map.modifiers/insert_node_type.pass.cpp new file mode 100644 index 00000000000..d434864885f --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.map/unord.map.modifiers/insert_node_type.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. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03, c++11, c++14 + +// + +// class unordered_map + +// insert_return_type insert(node_type&&); + +#include +#include "min_allocator.h" + +template +typename Container::node_type +node_factory(typename Container::key_type const& key, + typename Container::mapped_type const& mapped) +{ + static Container c; + auto p = c.insert({key, mapped}); + assert(p.second); + return c.extract(p.first); +} + +template +void test(Container& c) +{ + auto* nf = &node_factory; + + for (int i = 0; i != 10; ++i) + { + typename Container::node_type node = nf(i, i + 1); + assert(!node.empty()); + typename Container::insert_return_type irt = c.insert(std::move(node)); + assert(node.empty()); + assert(irt.inserted); + assert(irt.node.empty()); + assert(irt.position->first == i && irt.position->second == i + 1); + } + + assert(c.size() == 10); + + { // Insert empty node. + typename Container::node_type def; + auto irt = c.insert(std::move(def)); + assert(def.empty()); + assert(!irt.inserted); + assert(irt.node.empty()); + assert(irt.position == c.end()); + } + + { // Insert duplicate node. + typename Container::node_type dupl = nf(0, 42); + auto irt = c.insert(std::move(dupl)); + assert(dupl.empty()); + assert(!irt.inserted); + assert(!irt.node.empty()); + assert(irt.position == c.find(0)); + assert(irt.node.key() == 0 && irt.node.mapped() == 42); + } + + assert(c.size() == 10); + + for (int i = 0; i != 10; ++i) + { + assert(c.count(i) == 1); + assert(c[i] == i + 1); + } +} + +int main() +{ + std::unordered_map m; + test(m); + std::unordered_map, std::equal_to, min_allocator>> m2; + test(m2); +} diff --git a/libcxx/test/std/containers/unord/unord.map/unord.map.modifiers/insert_node_type_hint.pass.cpp b/libcxx/test/std/containers/unord/unord.map/unord.map.modifiers/insert_node_type_hint.pass.cpp new file mode 100644 index 00000000000..ef98453b627 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.map/unord.map.modifiers/insert_node_type_hint.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. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03, c++11, c++14 + +// + +// class unordered_map + +// iterator insert(const_iterator hint, node_type&&); + +#include +#include "min_allocator.h" + +template +typename Container::node_type +node_factory(typename Container::key_type const& key, + typename Container::mapped_type const& mapped) +{ + static Container c; + auto p = c.insert({key, mapped}); + assert(p.second); + return c.extract(p.first); +} + +template +void test(Container& c) +{ + auto* nf = &node_factory; + + for (int i = 0; i != 10; ++i) + { + typename Container::node_type node = nf(i, i + 1); + assert(!node.empty()); + size_t prev = c.size(); + auto it = c.insert(c.end(), std::move(node)); + assert(node.empty()); + assert(prev + 1 == c.size()); + assert(it->first == i); + assert(it->second == i + 1); + } + + assert(c.size() == 10); + + for (int i = 0; i != 10; ++i) + { + assert(c.count(i) == 1); + assert(c[i] == i + 1); + } +} + +int main() +{ + std::unordered_map m; + test(m); + std::unordered_map, std::equal_to, min_allocator>> m2; + test(m2); +} diff --git a/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/extract_iterator.pass.cpp b/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/extract_iterator.pass.cpp new file mode 100644 index 00000000000..adb2ddb2ba8 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/extract_iterator.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. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03, c++11, c++14 + +// + +// class unordered_multimap + +// node_type extract(const_iterator); + +#include +#include "min_allocator.h" +#include "Counter.h" + +template +void test(Container& c) +{ + size_t sz = c.size(); + + auto some_key = c.cbegin()->first; + + for (auto first = c.cbegin(); first != c.cend();) + { + auto key_value = first->first; + typename Container::node_type t = c.extract(first++); + --sz; + assert(t.key() == key_value); + t.key() = some_key; + assert(t.key() == some_key); + assert(t.get_allocator() == c.get_allocator()); + assert(sz == c.size()); + } + + assert(c.size() == 0); +} + +int main() +{ + { + using map_type = std::unordered_multimap; + map_type m = {{1,1}, {2,2}, {3,3}, {4,4}, {5,5}, {6,6}}; + test(m); + } + + { + std::unordered_multimap, Counter> m = + {{1,1}, {2,2}, {3,3}, {4,4}, {5,5}, {6,6}}; + assert(Counter_base::gConstructed == 12); + test(m); + assert(Counter_base::gConstructed == 0); + } + + { + using min_alloc_map = + std::unordered_multimap, std::equal_to, + min_allocator>>; + min_alloc_map m = {{1, 1}, {2, 2}, {3, 3}, {4, 4}, {5, 5}, {6, 6}}; + test(m); + } +} diff --git a/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/extract_key.pass.cpp b/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/extract_key.pass.cpp new file mode 100644 index 00000000000..8cf26fc7750 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/extract_key.pass.cpp @@ -0,0 +1,77 @@ +//===----------------------------------------------------------------------===// +// +// 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 + +// + +// class unordered_multimap + +// node_type extract(key_type const&); + +#include +#include "min_allocator.h" +#include "Counter.h" + +template +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.key() == *copy); + t.key() = *first; // We should be able to mutate key. + assert(t.key() == *first); + 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_multimap m = + {{1,1}, {2,2}, {3,3}, {4,4}, {5,5}, {6,6}}; + int keys[] = {1, 2, 3, 4, 5, 6}; + test(m, std::begin(keys), std::end(keys)); + } + + { + std::unordered_multimap, Counter> m = + {{1,1}, {2,2}, {3,3}, {4,4}, {5,5}, {6,6}}; + { + Counter keys[] = {1, 2, 3, 4, 5, 6}; + assert(Counter_base::gConstructed == 12+6); + test(m, std::begin(keys), std::end(keys)); + } + assert(Counter_base::gConstructed == 0); + } + + { + using min_alloc_map = + std::unordered_multimap, std::equal_to, + min_allocator>>; + min_alloc_map m = {{1, 1}, {2, 2}, {3, 3}, {4, 4}, {5, 5}, {6, 6}}; + int keys[] = {1, 2, 3, 4, 5, 6}; + test(m, std::begin(keys), std::end(keys)); + } +} diff --git a/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/insert_node_type.pass.cpp b/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/insert_node_type.pass.cpp new file mode 100644 index 00000000000..93c0462b324 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/insert_node_type.pass.cpp @@ -0,0 +1,77 @@ +//===----------------------------------------------------------------------===// +// +// 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 + +// + +// class unordered_multimap + +// iterator insert(node_type&&); + +#include +#include "min_allocator.h" + +template +typename Container::node_type +node_factory(typename Container::key_type const& key, + typename Container::mapped_type const& mapped) +{ + static Container c; + auto it = c.insert({key, mapped}); + return c.extract(it); +} + +template +void test(Container& c) +{ + auto* nf = &node_factory; + + for (int i = 0; i != 10; ++i) + { + typename Container::node_type node = nf(i, i + 1); + 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->first == i && it->second == i + 1); + } + + 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, 42); + auto it = c.insert(std::move(dupl)); + assert(dupl.empty()); + assert(it != c.end() && it->second == 42); + } + + assert(c.size() == 11); + assert(c.count(0) == 2); + for (int i = 1; i != 10; ++i) + { + assert(c.count(i) == 1); + assert(c.find(i)->second == i + 1); + } +} + +int main() +{ + std::unordered_multimap m; + test(m); + std::unordered_multimap, std::equal_to, min_allocator>> m2; + test(m2); +} diff --git a/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/insert_node_type_hint.pass.cpp b/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/insert_node_type_hint.pass.cpp new file mode 100644 index 00000000000..99a47cabb51 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/insert_node_type_hint.pass.cpp @@ -0,0 +1,63 @@ +//===----------------------------------------------------------------------===// +// +// 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 + +// + +// class unordered_multimap + +// iterator insert(const_iterator hint, node_type&&); + +#include +#include "min_allocator.h" + +template +typename Container::node_type +node_factory(typename Container::key_type const& key, + typename Container::mapped_type const& mapped) +{ + static Container c; + auto it = c.insert({key, mapped}); + return c.extract(it); +} + +template +void test(Container& c) +{ + auto* nf = &node_factory; + + for (int i = 0; i != 10; ++i) + { + typename Container::node_type node = nf(i, i + 1); + assert(!node.empty()); + size_t prev = c.size(); + auto it = c.insert(c.end(), std::move(node)); + assert(node.empty()); + assert(prev + 1 == c.size()); + assert(it->first == i); + assert(it->second == i + 1); + } + + assert(c.size() == 10); + + for (int i = 0; i != 10; ++i) + { + assert(c.count(i) == 1); + assert(c.find(i)->second == i + 1); + } +} + +int main() +{ + std::unordered_multimap m; + test(m); + std::unordered_multimap, std::equal_to, min_allocator>> m2; + test(m2); +} diff --git a/libcxx/test/std/containers/unord/unord.multiset/extract_iterator.pass.cpp b/libcxx/test/std/containers/unord/unord.multiset/extract_iterator.pass.cpp new file mode 100644 index 00000000000..1595c55a423 --- /dev/null +++ b/libcxx/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 + +// + +// class unordered_multiset + +// node_type extract(const_iterator); + +#include +#include "min_allocator.h" +#include "Counter.h" + +template +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; + set_type m = {1, 2, 3, 4, 5, 6}; + test(m); + } + + { + std::unordered_multiset> 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, std::equal_to, min_allocator>; + min_alloc_set m = {1, 2, 3, 4, 5, 6}; + test(m); + } +} diff --git a/libcxx/test/std/containers/unord/unord.multiset/extract_key.pass.cpp b/libcxx/test/std/containers/unord/unord.multiset/extract_key.pass.cpp new file mode 100644 index 00000000000..ffe46fb30f1 --- /dev/null +++ b/libcxx/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 + +// + +// class unordered_multiset + +// node_type extract(key_type const&); + +#include +#include "min_allocator.h" +#include "Counter.h" + +template +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 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> m = {1, 2, 3, 4, 5, 6}; + { + Counter 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, std::equal_to, min_allocator>; + 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/libcxx/test/std/containers/unord/unord.multiset/insert_node_type.pass.cpp b/libcxx/test/std/containers/unord/unord.multiset/insert_node_type.pass.cpp new file mode 100644 index 00000000000..c3d4cd2a0e8 --- /dev/null +++ b/libcxx/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 + +// + +// class unordered_multiset + +// iterator insert(node_type&&); + +#include +#include +#include "min_allocator.h" + +template +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 +void test(Container& c) +{ + auto* nf = &node_factory; + + 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 m; + test(m); + std::unordered_multiset, std::equal_to, min_allocator> m2; + test(m2); +} diff --git a/libcxx/test/std/containers/unord/unord.multiset/insert_node_type_hint.pass.cpp b/libcxx/test/std/containers/unord/unord.multiset/insert_node_type_hint.pass.cpp new file mode 100644 index 00000000000..79712d3ded7 --- /dev/null +++ b/libcxx/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 + +// + +// class unordered_multiset + +// iterator insert(const_iterator hint, node_type&&); + +#include +#include "min_allocator.h" + +template +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 +void test(Container& c) +{ + auto* nf = &node_factory; + + 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 m; + test(m); + std::unordered_multiset, std::equal_to, min_allocator> m2; + test(m2); +} diff --git a/libcxx/test/std/containers/unord/unord.set/extract_iterator.pass.cpp b/libcxx/test/std/containers/unord/unord.set/extract_iterator.pass.cpp new file mode 100644 index 00000000000..40feb0e2f85 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.set/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 + +// + +// class unordered_set + +// node_type extract(const_iterator); + +#include +#include "min_allocator.h" +#include "Counter.h" + +template +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_set; + set_type m = {1, 2, 3, 4, 5, 6}; + test(m); + } + + { + std::unordered_set> 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_set, std::equal_to, min_allocator>; + min_alloc_set m = {1, 2, 3, 4, 5, 6}; + test(m); + } +} diff --git a/libcxx/test/std/containers/unord/unord.set/extract_key.pass.cpp b/libcxx/test/std/containers/unord/unord.set/extract_key.pass.cpp new file mode 100644 index 00000000000..f686342b298 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.set/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 + +// + +// class unordered_set + +// node_type extract(key_type const&); + +#include +#include "min_allocator.h" +#include "Counter.h" + +template +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_set 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_set> m = {1, 2, 3, 4, 5, 6}; + { + Counter 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_set, std::equal_to, min_allocator>; + 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/libcxx/test/std/containers/unord/unord.set/insert_node_type.pass.cpp b/libcxx/test/std/containers/unord/unord.set/insert_node_type.pass.cpp new file mode 100644 index 00000000000..6c91b539356 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.set/insert_node_type.pass.cpp @@ -0,0 +1,83 @@ +//===----------------------------------------------------------------------===// +// +// 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 + +// + +// class unordered_set + +// insert_return_type insert(node_type&&); + +#include +#include +#include "min_allocator.h" + +template +typename Container::node_type +node_factory(typename Container::key_type const& key) +{ + static Container c; + auto p = c.insert(key); + assert(p.second); + return c.extract(p.first); +} + +template +void test(Container& c) +{ + auto* nf = &node_factory; + + for (int i = 0; i != 10; ++i) + { + typename Container::node_type node = nf(i); + assert(!node.empty()); + typename Container::insert_return_type irt = c.insert(std::move(node)); + assert(node.empty()); + assert(irt.inserted); + assert(irt.node.empty()); + assert(*irt.position == i); + } + + assert(c.size() == 10); + + { // Insert empty node. + typename Container::node_type def; + auto irt = c.insert(std::move(def)); + assert(def.empty()); + assert(!irt.inserted); + assert(irt.node.empty()); + assert(irt.position == c.end()); + } + + { // Insert duplicate node. + typename Container::node_type dupl = nf(0); + auto irt = c.insert(std::move(dupl)); + assert(dupl.empty()); + assert(!irt.inserted); + assert(!irt.node.empty()); + assert(irt.position == c.find(0)); + assert(irt.node.value() == 0); + } + + assert(c.size() == 10); + + for (int i = 0; i != 10; ++i) + { + assert(c.count(i) == 1); + } +} + +int main() +{ + std::unordered_set m; + test(m); + std::unordered_set, std::equal_to, min_allocator> m2; + test(m2); +} diff --git a/libcxx/test/std/containers/unord/unord.set/insert_node_type_hint.pass.cpp b/libcxx/test/std/containers/unord/unord.set/insert_node_type_hint.pass.cpp new file mode 100644 index 00000000000..626f27271da --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.set/insert_node_type_hint.pass.cpp @@ -0,0 +1,61 @@ +//===----------------------------------------------------------------------===// +// +// 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 + +// + +// class unordered_set + +// iterator insert(const_iterator hint, node_type&&); + +#include +#include "min_allocator.h" + +template +typename Container::node_type +node_factory(typename Container::key_type const& key) +{ + static Container c; + auto p = c.insert(key); + assert(p.second); + return c.extract(p.first); +} + +template +void test(Container& c) +{ + auto* nf = &node_factory; + + 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(node.empty()); + 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_set m; + test(m); + std::unordered_set, std::equal_to, min_allocator> m2; + test(m2); +} diff --git a/libcxx/test/support/Counter.h b/libcxx/test/support/Counter.h index 4a658c58c06..63ed6080155 100644 --- a/libcxx/test/support/Counter.h +++ b/libcxx/test/support/Counter.h @@ -23,7 +23,7 @@ public: Counter() : data_() { ++gConstructed; } Counter(const T &data) : data_(data) { ++gConstructed; } Counter(const Counter& rhs) : data_(rhs.data_) { ++gConstructed; } - Counter& operator=(const Counter& rhs) { ++gConstructed; data_ = rhs.data_; return *this; } + Counter& operator=(const Counter& rhs) { data_ = rhs.data_; return *this; } #if TEST_STD_VER >= 11 Counter(Counter&& rhs) : data_(std::move(rhs.data_)) { ++gConstructed; } Counter& operator=(Counter&& rhs) { ++gConstructed; data_ = std::move(rhs.data_); return *this; } @@ -49,7 +49,7 @@ struct hash > typedef Counter argument_type; typedef std::size_t result_type; - std::size_t operator()(const Counter& x) const {return std::hash(x.get());} + std::size_t operator()(const Counter& x) const {return std::hash()(x.get());} }; } -- cgit v1.2.3