summaryrefslogtreecommitdiff
path: root/test/std/containers/associative/multimap/multimap.special
diff options
context:
space:
mode:
Diffstat (limited to 'test/std/containers/associative/multimap/multimap.special')
-rw-r--r--test/std/containers/associative/multimap/multimap.special/member_swap.pass.cpp176
-rw-r--r--test/std/containers/associative/multimap/multimap.special/non_member_swap.pass.cpp281
-rw-r--r--test/std/containers/associative/multimap/multimap.special/swap_noexcept.pass.cpp148
3 files changed, 605 insertions, 0 deletions
diff --git a/test/std/containers/associative/multimap/multimap.special/member_swap.pass.cpp b/test/std/containers/associative/multimap/multimap.special/member_swap.pass.cpp
new file mode 100644
index 0000000000000..fb17e7340bd4f
--- /dev/null
+++ b/test/std/containers/associative/multimap/multimap.special/member_swap.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.
+//
+//===----------------------------------------------------------------------===//
+
+// <map>
+
+// class multimap
+
+// void swap(multimap& m);
+
+#include <map>
+#include <cassert>
+
+#include "min_allocator.h"
+
+int main()
+{
+ typedef std::pair<const int, double> V;
+ {
+ typedef std::multimap<int, double> M;
+ {
+ M m1;
+ M m2;
+ M m1_save = m1;
+ M m2_save = m2;
+ m1.swap(m2);
+ assert(m1 == m2_save);
+ assert(m2 == m1_save);
+ }
+ {
+ V ar2[] =
+ {
+ V(5, 5),
+ V(6, 6),
+ V(7, 7),
+ V(8, 8),
+ V(9, 9),
+ V(10, 10),
+ V(11, 11),
+ V(12, 12)
+ };
+ M m1;
+ M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0]));
+ M m1_save = m1;
+ M m2_save = m2;
+ m1.swap(m2);
+ assert(m1 == m2_save);
+ assert(m2 == m1_save);
+ }
+ {
+ V ar1[] =
+ {
+ V(1, 1),
+ V(2, 2),
+ V(3, 3),
+ V(4, 4)
+ };
+ M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0]));
+ M m2;
+ M m1_save = m1;
+ M m2_save = m2;
+ m1.swap(m2);
+ assert(m1 == m2_save);
+ assert(m2 == m1_save);
+ }
+ {
+ V ar1[] =
+ {
+ V(1, 1),
+ V(2, 2),
+ V(3, 3),
+ V(4, 4)
+ };
+ V ar2[] =
+ {
+ V(5, 5),
+ V(6, 6),
+ V(7, 7),
+ V(8, 8),
+ V(9, 9),
+ V(10, 10),
+ V(11, 11),
+ V(12, 12)
+ };
+ M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0]));
+ M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0]));
+ M m1_save = m1;
+ M m2_save = m2;
+ m1.swap(m2);
+ assert(m1 == m2_save);
+ assert(m2 == m1_save);
+ }
+ }
+#if __cplusplus >= 201103L
+ {
+ typedef std::multimap<int, double, std::less<int>, min_allocator<std::pair<const int, double>>> M;
+ {
+ M m1;
+ M m2;
+ M m1_save = m1;
+ M m2_save = m2;
+ m1.swap(m2);
+ assert(m1 == m2_save);
+ assert(m2 == m1_save);
+ }
+ {
+ V ar2[] =
+ {
+ V(5, 5),
+ V(6, 6),
+ V(7, 7),
+ V(8, 8),
+ V(9, 9),
+ V(10, 10),
+ V(11, 11),
+ V(12, 12)
+ };
+ M m1;
+ M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0]));
+ M m1_save = m1;
+ M m2_save = m2;
+ m1.swap(m2);
+ assert(m1 == m2_save);
+ assert(m2 == m1_save);
+ }
+ {
+ V ar1[] =
+ {
+ V(1, 1),
+ V(2, 2),
+ V(3, 3),
+ V(4, 4)
+ };
+ M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0]));
+ M m2;
+ M m1_save = m1;
+ M m2_save = m2;
+ m1.swap(m2);
+ assert(m1 == m2_save);
+ assert(m2 == m1_save);
+ }
+ {
+ V ar1[] =
+ {
+ V(1, 1),
+ V(2, 2),
+ V(3, 3),
+ V(4, 4)
+ };
+ V ar2[] =
+ {
+ V(5, 5),
+ V(6, 6),
+ V(7, 7),
+ V(8, 8),
+ V(9, 9),
+ V(10, 10),
+ V(11, 11),
+ V(12, 12)
+ };
+ M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0]));
+ M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0]));
+ M m1_save = m1;
+ M m2_save = m2;
+ m1.swap(m2);
+ assert(m1 == m2_save);
+ assert(m2 == m1_save);
+ }
+ }
+#endif
+}
diff --git a/test/std/containers/associative/multimap/multimap.special/non_member_swap.pass.cpp b/test/std/containers/associative/multimap/multimap.special/non_member_swap.pass.cpp
new file mode 100644
index 0000000000000..a91dfebb14a9d
--- /dev/null
+++ b/test/std/containers/associative/multimap/multimap.special/non_member_swap.pass.cpp
@@ -0,0 +1,281 @@
+//===----------------------------------------------------------------------===//
+//
+// 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.
+//
+//===----------------------------------------------------------------------===//
+
+// <map>
+
+// class multimap
+
+// template <class Key, class T, class Compare, class Allocator>
+// void
+// swap(multimap<Key, T, Compare, Allocator>& x, multimap<Key, T, Compare, Allocator>& y);
+
+#include <map>
+#include <cassert>
+#include "test_allocator.h"
+#include "../../../test_compare.h"
+#include "min_allocator.h"
+
+int main()
+{
+ typedef std::pair<const int, double> V;
+ {
+ typedef std::multimap<int, double> M;
+ {
+ M m1;
+ M m2;
+ M m1_save = m1;
+ M m2_save = m2;
+ swap(m1, m2);
+ assert(m1 == m2_save);
+ assert(m2 == m1_save);
+ }
+ {
+ V ar2[] =
+ {
+ V(5, 5),
+ V(6, 6),
+ V(7, 7),
+ V(8, 8),
+ V(9, 9),
+ V(10, 10),
+ V(11, 11),
+ V(12, 12)
+ };
+ M m1;
+ M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0]));
+ M m1_save = m1;
+ M m2_save = m2;
+ swap(m1, m2);
+ assert(m1 == m2_save);
+ assert(m2 == m1_save);
+ }
+ {
+ V ar1[] =
+ {
+ V(1, 1),
+ V(2, 2),
+ V(3, 3),
+ V(4, 4)
+ };
+ M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0]));
+ M m2;
+ M m1_save = m1;
+ M m2_save = m2;
+ swap(m1, m2);
+ assert(m1 == m2_save);
+ assert(m2 == m1_save);
+ }
+ {
+ V ar1[] =
+ {
+ V(1, 1),
+ V(2, 2),
+ V(3, 3),
+ V(4, 4)
+ };
+ V ar2[] =
+ {
+ V(5, 5),
+ V(6, 6),
+ V(7, 7),
+ V(8, 8),
+ V(9, 9),
+ V(10, 10),
+ V(11, 11),
+ V(12, 12)
+ };
+ M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0]));
+ M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0]));
+ M m1_save = m1;
+ M m2_save = m2;
+ swap(m1, m2);
+ assert(m1 == m2_save);
+ assert(m2 == m1_save);
+ }
+ {
+ typedef test_allocator<V> A;
+ typedef test_compare<std::less<int> > C;
+ typedef std::multimap<int, double, C, A> M;
+ V ar1[] =
+ {
+ V(1, 1),
+ V(2, 2),
+ V(3, 3),
+ V(4, 4)
+ };
+ V ar2[] =
+ {
+ V(5, 5),
+ V(6, 6),
+ V(7, 7),
+ V(8, 8),
+ V(9, 9),
+ V(10, 10),
+ V(11, 11),
+ V(12, 12)
+ };
+ M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0]), C(1), A(1));
+ M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0]), C(2), A(2));
+ M m1_save = m1;
+ M m2_save = m2;
+ swap(m1, m2);
+ assert(m1 == m2_save);
+ assert(m2 == m1_save);
+ assert(m1.key_comp() == C(2));
+ assert(m1.get_allocator() == A(1));
+ assert(m2.key_comp() == C(1));
+ assert(m2.get_allocator() == A(2));
+ }
+ {
+ typedef other_allocator<V> A;
+ typedef test_compare<std::less<int> > C;
+ typedef std::multimap<int, double, C, A> M;
+ V ar1[] =
+ {
+ V(1, 1),
+ V(2, 2),
+ V(3, 3),
+ V(4, 4)
+ };
+ V ar2[] =
+ {
+ V(5, 5),
+ V(6, 6),
+ V(7, 7),
+ V(8, 8),
+ V(9, 9),
+ V(10, 10),
+ V(11, 11),
+ V(12, 12)
+ };
+ M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0]), C(1), A(1));
+ M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0]), C(2), A(2));
+ M m1_save = m1;
+ M m2_save = m2;
+ swap(m1, m2);
+ assert(m1 == m2_save);
+ assert(m2 == m1_save);
+ assert(m1.key_comp() == C(2));
+ assert(m1.get_allocator() == A(2));
+ assert(m2.key_comp() == C(1));
+ assert(m2.get_allocator() == A(1));
+ }
+ }
+#if __cplusplus >= 201103L
+ {
+ typedef std::multimap<int, double, std::less<int>, min_allocator<std::pair<const int, double>>> M;
+ {
+ M m1;
+ M m2;
+ M m1_save = m1;
+ M m2_save = m2;
+ swap(m1, m2);
+ assert(m1 == m2_save);
+ assert(m2 == m1_save);
+ }
+ {
+ V ar2[] =
+ {
+ V(5, 5),
+ V(6, 6),
+ V(7, 7),
+ V(8, 8),
+ V(9, 9),
+ V(10, 10),
+ V(11, 11),
+ V(12, 12)
+ };
+ M m1;
+ M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0]));
+ M m1_save = m1;
+ M m2_save = m2;
+ swap(m1, m2);
+ assert(m1 == m2_save);
+ assert(m2 == m1_save);
+ }
+ {
+ V ar1[] =
+ {
+ V(1, 1),
+ V(2, 2),
+ V(3, 3),
+ V(4, 4)
+ };
+ M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0]));
+ M m2;
+ M m1_save = m1;
+ M m2_save = m2;
+ swap(m1, m2);
+ assert(m1 == m2_save);
+ assert(m2 == m1_save);
+ }
+ {
+ V ar1[] =
+ {
+ V(1, 1),
+ V(2, 2),
+ V(3, 3),
+ V(4, 4)
+ };
+ V ar2[] =
+ {
+ V(5, 5),
+ V(6, 6),
+ V(7, 7),
+ V(8, 8),
+ V(9, 9),
+ V(10, 10),
+ V(11, 11),
+ V(12, 12)
+ };
+ M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0]));
+ M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0]));
+ M m1_save = m1;
+ M m2_save = m2;
+ swap(m1, m2);
+ assert(m1 == m2_save);
+ assert(m2 == m1_save);
+ }
+ {
+ typedef min_allocator<V> A;
+ typedef test_compare<std::less<int> > C;
+ typedef std::multimap<int, double, C, A> M;
+ V ar1[] =
+ {
+ V(1, 1),
+ V(2, 2),
+ V(3, 3),
+ V(4, 4)
+ };
+ V ar2[] =
+ {
+ V(5, 5),
+ V(6, 6),
+ V(7, 7),
+ V(8, 8),
+ V(9, 9),
+ V(10, 10),
+ V(11, 11),
+ V(12, 12)
+ };
+ M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0]), C(1), A());
+ M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0]), C(2), A());
+ M m1_save = m1;
+ M m2_save = m2;
+ swap(m1, m2);
+ assert(m1 == m2_save);
+ assert(m2 == m1_save);
+ assert(m1.key_comp() == C(2));
+ assert(m1.get_allocator() == A());
+ assert(m2.key_comp() == C(1));
+ assert(m2.get_allocator() == A());
+ }
+ }
+#endif
+}
diff --git a/test/std/containers/associative/multimap/multimap.special/swap_noexcept.pass.cpp b/test/std/containers/associative/multimap/multimap.special/swap_noexcept.pass.cpp
new file mode 100644
index 0000000000000..1013c62804b87
--- /dev/null
+++ b/test/std/containers/associative/multimap/multimap.special/swap_noexcept.pass.cpp
@@ -0,0 +1,148 @@
+//===----------------------------------------------------------------------===//
+//
+// 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.
+//
+//===----------------------------------------------------------------------===//
+
+// <map>
+
+// void swap(multimap& c)
+// noexcept(!allocator_type::propagate_on_container_swap::value ||
+// __is_nothrow_swappable<allocator_type>::value);
+//
+// In C++17, the standard says that swap shall have:
+// noexcept(allocator_traits<Allocator>::is_always_equal::value &&
+// noexcept(swap(declval<Compare&>(), declval<Compare&>())));
+
+// This tests a conforming extension
+
+#include <map>
+#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&) {}
+ void deallocate(void*, unsigned) {}
+
+ typedef std::true_type propagate_on_container_swap;
+};
+
+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_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::multimap<MoveOnly, MoveOnly> C;
+ C c1, c2;
+ static_assert(noexcept(swap(c1, c2)), "");
+ }
+ {
+ typedef std::multimap<MoveOnly, MoveOnly, std::less<MoveOnly>, test_allocator<MoveOnly>> C;
+ C c1, c2;
+ static_assert(noexcept(swap(c1, c2)), "");
+ }
+ {
+ typedef std::multimap<MoveOnly, MoveOnly, std::less<MoveOnly>, other_allocator<MoveOnly>> C;
+ C c1, c2;
+ static_assert(noexcept(swap(c1, c2)), "");
+ }
+ {
+ typedef std::multimap<MoveOnly, MoveOnly, some_comp<MoveOnly>> C;
+ C c1, c2;
+ static_assert(!noexcept(swap(c1, c2)), "");
+ }
+
+#if TEST_STD_VER >= 14
+ { // POCS allocator, throwable swap for comp
+ typedef std::multimap<MoveOnly, MoveOnly, some_comp <MoveOnly>, some_alloc <MoveOnly>> C;
+ C c1, c2;
+ static_assert(!noexcept(swap(c1, c2)), "");
+ }
+ { // always equal allocator, throwable swap for comp
+ typedef std::multimap<MoveOnly, MoveOnly, some_comp <MoveOnly>, some_alloc2<MoveOnly>> C;
+ C c1, c2;
+ static_assert(!noexcept(swap(c1, c2)), "");
+ }
+ { // POCS allocator, nothrow swap for comp
+ typedef std::multimap<MoveOnly, MoveOnly, some_comp2<MoveOnly>, some_alloc <MoveOnly>> C;
+ C c1, c2;
+ static_assert( noexcept(swap(c1, c2)), "");
+ }
+ { // always equal allocator, nothrow swap for comp
+ typedef std::multimap<MoveOnly, MoveOnly, some_comp2<MoveOnly>, some_alloc2<MoveOnly>> C;
+ C c1, c2;
+ static_assert( noexcept(swap(c1, c2)), "");
+ }
+
+ { // NOT always equal allocator, nothrow swap for comp
+ typedef std::map<MoveOnly, MoveOnly, some_comp2<MoveOnly>, some_alloc3<MoveOnly>> C;
+ C c1, c2;
+ static_assert( noexcept(swap(c1, c2)), "");
+ }
+#endif
+
+#endif
+}