95 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// flat_map& operator=(flat_map&&);14 15#include <algorithm>16#include <deque>17#include <flat_map>18#include <functional>19#include <string>20#include <utility>21#include <vector>22 23#include "test_macros.h"24#include "MoveOnly.h"25#include "../../../test_compare.h"26#include "test_allocator.h"27#include "min_allocator.h"28 29template <template <class...> class KeyContainer, template <class...> class ValueContainer>30constexpr void test() {31 {32 using C = test_less<int>;33 using A1 = test_allocator<int>;34 using A2 = test_allocator<char>;35 using M = std::flat_map<int, char, C, KeyContainer<int, A1>, ValueContainer<char, A2>>;36 M mo = M({{1, 1}, {2, 3}, {3, 2}}, C(5), A1(7));37 M m = M({}, C(3), A1(7));38 m = std::move(mo);39 assert((m == M{{1, 1}, {2, 3}, {3, 2}}));40 assert(m.key_comp() == C(5));41 auto [ks, vs] = std::move(m).extract();42 assert(ks.get_allocator() == A1(7));43 assert(vs.get_allocator() == A2(7));44 assert(mo.empty());45 }46 {47 using C = test_less<int>;48 using A1 = other_allocator<int>;49 using A2 = other_allocator<char>;50 using M = std::flat_map<int, char, C, KeyContainer<int, A1>, ValueContainer<char, A2>>;51 M mo = M({{4, 5}, {5, 4}}, C(5), A1(7));52 M m = M({{1, 1}, {2, 2}, {3, 3}, {4, 4}}, C(3), A1(7));53 m = std::move(mo);54 assert((m == M{{4, 5}, {5, 4}}));55 assert(m.key_comp() == C(5));56 auto [ks, vs] = std::move(m).extract();57 assert(ks.get_allocator() == A1(7));58 assert(vs.get_allocator() == A2(7));59 assert(mo.empty());60 }61 {62 using A = min_allocator<int>;63 using M = std::flat_map<int, int, std::greater<int>, KeyContainer<int, A>, ValueContainer<int, A>>;64 M mo = M({{5, 1}, {4, 2}, {3, 3}}, A());65 M m = M({{4, 4}, {3, 3}, {2, 2}, {1, 1}}, A());66 m = std::move(mo);67 assert((m == M{{5, 1}, {4, 2}, {3, 3}}));68 auto [ks, vs] = std::move(m).extract();69 assert(ks.get_allocator() == A());70 assert(vs.get_allocator() == A());71 assert(mo.empty());72 }73}74 75constexpr bool test() {76 test<std::vector, std::vector>();77 78#ifndef __cpp_lib_constexpr_deque79 if (!TEST_IS_CONSTANT_EVALUATED)80#endif81 {82 test<std::deque, std::deque>();83 }84 85 return true;86}87 88int main(int, char**) {89 test();90#if TEST_STD_VER >= 2691 static_assert(test());92#endif93 94 return 0;95}