aboutsummaryrefslogtreecommitdiff
path: root/test/std/containers/unord/unord.multiset/insert_node_type.pass.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'test/std/containers/unord/unord.multiset/insert_node_type.pass.cpp')
-rw-r--r--test/std/containers/unord/unord.multiset/insert_node_type.pass.cpp76
1 files changed, 76 insertions, 0 deletions
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);
+}