1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
|
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
// <flat_map>
// flat_multimap& operator=(flat_multimap&& c)
// noexcept(
// is_nothrow_move_assignable<key_container_type>::value &&
// is_nothrow_move_assignable<mapped_container_type>::value &&
// is_nothrow_copy_assignable<key_compare>::value);
// This tests a conforming extension
#include <flat_map>
#include <functional>
#include <memory_resource>
#include <type_traits>
#include <vector>
#include "MoveOnly.h"
#include "test_allocator.h"
#include "test_macros.h"
struct MoveSensitiveComp {
MoveSensitiveComp() noexcept(false) = default;
MoveSensitiveComp(const MoveSensitiveComp&) noexcept(false) = default;
MoveSensitiveComp(MoveSensitiveComp&& rhs) { rhs.is_moved_from_ = true; }
MoveSensitiveComp& operator=(const MoveSensitiveComp&) noexcept = default;
MoveSensitiveComp& operator=(MoveSensitiveComp&& rhs) {
rhs.is_moved_from_ = true;
return *this;
}
bool operator()(const auto&, const auto&) const { return false; }
bool is_moved_from_ = false;
};
struct MoveThrowsComp {
MoveThrowsComp(MoveThrowsComp&&) noexcept(false);
MoveThrowsComp(const MoveThrowsComp&) noexcept(true);
MoveThrowsComp& operator=(MoveThrowsComp&&) noexcept(false);
MoveThrowsComp& operator=(const MoveThrowsComp&) noexcept(true);
bool operator()(const auto&, const auto&) const;
};
int main(int, char**) {
{
using C = std::flat_multimap<int, int>;
LIBCPP_STATIC_ASSERT(std::is_nothrow_move_assignable_v<C>);
}
{
using C =
std::flat_multimap<MoveOnly,
int,
std::less<MoveOnly>,
std::vector<MoveOnly, test_allocator<MoveOnly>>,
std::vector<int, test_allocator<int>>>;
static_assert(!std::is_nothrow_move_assignable_v<C>);
}
{
using C =
std::flat_multimap<int,
MoveOnly,
std::less<int>,
std::vector<int, test_allocator<int>>,
std::vector<MoveOnly, test_allocator<MoveOnly>>>;
static_assert(!std::is_nothrow_move_assignable_v<C>);
}
{
using C =
std::flat_multimap<MoveOnly,
int,
std::less<MoveOnly>,
std::vector<MoveOnly, other_allocator<MoveOnly>>,
std::vector<int, other_allocator<int>>>;
LIBCPP_STATIC_ASSERT(std::is_nothrow_move_assignable_v<C>);
}
{
using C =
std::flat_multimap<int,
MoveOnly,
std::less<int>,
std::vector<int, other_allocator<int>>,
std::vector<MoveOnly, other_allocator<MoveOnly>>>;
LIBCPP_STATIC_ASSERT(std::is_nothrow_move_assignable_v<C>);
}
{
// Test with a comparator that throws on move-assignment.
using C = std::flat_multimap<int, int, MoveThrowsComp>;
LIBCPP_STATIC_ASSERT(!std::is_nothrow_move_assignable_v<C>);
}
{
// Test with a container that throws on move-assignment.
using C = std::flat_multimap<int, int, std::less<int>, std::pmr::vector<int>, std::vector<int>>;
static_assert(!std::is_nothrow_move_assignable_v<C>);
}
{
// Test with a container that throws on move-assignment.
using C = std::flat_multimap<int, int, std::less<int>, std::vector<int>, std::pmr::vector<int>>;
static_assert(!std::is_nothrow_move_assignable_v<C>);
}
return 0;
}
|