111 lines · cpp
1//===----------------------------------------------------------------------===//2//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-exception6//7//===----------------------------------------------------------------------===//8 9// UNSUPPORTED: c++03, c++11, c++14, c++17, c++2010 11// <flat_map>12 13// class flat_multimap14 15// friend void swap(flat_multimap& x, flat_multimap& y) noexcept16 17#include <flat_map>18#include <cassert>19#include <deque>20#include <functional>21#include <vector>22 23#include "MinSequenceContainer.h"24#include "MoveOnly.h"25#include "min_allocator.h"26#include "test_macros.h"27#include "../helpers.h"28 29// test noexcept30 31template <class T>32concept NoExceptAdlSwap = requires(T t1, T t2) {33 { swap(t1, t2) } noexcept;34};35 36static_assert(NoExceptAdlSwap<std::flat_multimap<int, int>>);37 38#ifndef TEST_HAS_NO_EXCEPTIONS39static_assert(NoExceptAdlSwap<40 std::flat_multimap<int, int, std::less<int>, ThrowOnMoveContainer<int>, ThrowOnMoveContainer<int>>>);41#endif42 43template <class KeyContainer, class ValueContainer>44constexpr void test() {45 using Key = typename KeyContainer::value_type;46 using Value = typename ValueContainer::value_type;47 using M = std::flat_multimap<Key, Value, std::less<Key>, KeyContainer, ValueContainer>;48 using V = std::pair<const Key, Value>;49 50 {51 M m1;52 M m2;53 M m1_save = m1;54 M m2_save = m2;55 swap(m1, m2);56 assert(m1 == m2_save);57 assert(m2 == m1_save);58 }59 {60 V ar2[] = {V(5, 5), V(5, 6), V(5, 7), V(8, 8), V(9, 9), V(10, 10), V(10, 11), V(10, 12)};61 M m1;62 M m2(ar2, ar2 + sizeof(ar2) / sizeof(ar2[0]));63 M m1_save = m1;64 M m2_save = m2;65 swap(m1, m2);66 assert(m1 == m2_save);67 assert(m2 == m1_save);68 }69 {70 V ar1[] = {V(1, 1), V(1, 2), V(3, 3), V(4, 4)};71 M m1(ar1, ar1 + sizeof(ar1) / sizeof(ar1[0]));72 M m2;73 M m1_save = m1;74 M m2_save = m2;75 swap(m1, m2);76 assert(m1 == m2_save);77 assert(m2 == m1_save);78 }79 {80 V ar1[] = {V(1, 1), V(1, 2), V(3, 3), V(4, 4)};81 V ar2[] = {V(5, 5), V(5, 6), V(5, 7), V(8, 8), V(9, 9), V(10, 10), V(10, 11), V(10, 12)};82 M m1(ar1, ar1 + sizeof(ar1) / sizeof(ar1[0]));83 M m2(ar2, ar2 + sizeof(ar2) / sizeof(ar2[0]));84 M m1_save = m1;85 M m2_save = m2;86 swap(m1, m2);87 assert(m1 == m2_save);88 assert(m2 == m1_save);89 }90}91 92constexpr bool test() {93 test<std::vector<int>, std::vector<double>>();94#ifndef __cpp_lib_constexpr_deque95 if (!TEST_IS_CONSTANT_EVALUATED)96#endif97 test<std::deque<int>, std::vector<double>>();98 test<MinSequenceContainer<int>, MinSequenceContainer<double>>();99 test<std::vector<int, min_allocator<int>>, std::vector<double, min_allocator<double>>>();100 return true;101}102 103int main(int, char**) {104 test();105#if TEST_STD_VER >= 26106 static_assert(test());107#endif108 109 return 0;110}111