1 //===----------------------------------------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
13 // void swap(flat_map& y) noexcept;
21 #include "MinSequenceContainer.h"
23 #include "min_allocator.h"
24 #include "test_macros.h"
25 #include "../helpers.h"
30 concept NoExceptMemberSwap
= requires(T t1
, T t2
) {
31 { t1
.swap(t2
) } noexcept
;
34 static_assert(NoExceptMemberSwap
<std::flat_map
<int, int>>);
35 #ifndef TEST_HAS_NO_EXCEPTIONS
37 NoExceptMemberSwap
<std::flat_map
<int, int, std::less
<int>, ThrowOnMoveContainer
<int>, ThrowOnMoveContainer
<int>>>);
40 template <class KeyContainer
, class ValueContainer
>
42 using Key
= typename
KeyContainer::value_type
;
43 using Value
= typename
ValueContainer::value_type
;
44 using M
= std::flat_map
<Key
, Value
, std::less
<Key
>, KeyContainer
, ValueContainer
>;
45 using V
= std::pair
<const Key
, Value
>;
52 assert(m1
== m2_save
);
53 assert(m2
== m1_save
);
56 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)};
58 M
m2(ar2
, ar2
+ sizeof(ar2
) / sizeof(ar2
[0]));
62 assert(m1
== m2_save
);
63 assert(m2
== m1_save
);
66 V ar1
[] = {V(1, 1), V(2, 2), V(3, 3), V(4, 4)};
67 M
m1(ar1
, ar1
+ sizeof(ar1
) / sizeof(ar1
[0]));
72 assert(m1
== m2_save
);
73 assert(m2
== m1_save
);
76 V ar1
[] = {V(1, 1), V(2, 2), V(3, 3), V(4, 4)};
77 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)};
78 M
m1(ar1
, ar1
+ sizeof(ar1
) / sizeof(ar1
[0]));
79 M
m2(ar2
, ar2
+ sizeof(ar2
) / sizeof(ar2
[0]));
83 assert(m1
== m2_save
);
84 assert(m2
== m1_save
);
88 int main(int, char**) {
89 test
<std::vector
<int>, std::vector
<double>>();
90 test
<std::deque
<int>, std::vector
<double>>();
91 test
<MinSequenceContainer
<int>, MinSequenceContainer
<double>>();
92 test
<std::vector
<int, min_allocator
<int>>, std::vector
<double, min_allocator
<double>>>();