87 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_set>12 13// flat_multiset(const flat_multiset& m);14 15#include <algorithm>16#include <cassert>17#include <deque>18#include <flat_set>19#include <vector>20 21#include "test_macros.h"22#include "../../../test_compare.h"23#include "test_allocator.h"24 25template <template <class...> class KeyContainer>26constexpr void test() {27 {28 using C = test_less<int>;29 KeyContainer<int, test_allocator<int>> ks({1, 3, 5, 3, 1}, test_allocator<int>(6));30 const int expected[] = {1, 1, 3, 3, 5};31 using M = std::flat_multiset<int, C, decltype(ks)>;32 auto mo = M(ks, C(5));33 auto m = mo;34 35 assert(m.key_comp() == C(5));36 assert(std::ranges::equal(m, expected));37 auto keys = std::move(m).extract();38 assert(keys.get_allocator() == test_allocator<int>(6));39 40 // mo is unchanged41 assert(mo.key_comp() == C(5));42 assert(std::ranges::equal(mo, expected));43 auto keys2 = std::move(mo).extract();44 assert(keys2.get_allocator() == test_allocator<int>(6));45 }46 {47 using C = test_less<int>;48 using Ks = KeyContainer<int, other_allocator<int>>;49 auto ks = Ks({1, 3, 5, 3, 1}, other_allocator<int>(6));50 const int expected[] = {1, 1, 3, 3, 5};51 using M = std::flat_multiset<int, C, Ks>;52 auto mo = M(Ks(ks, other_allocator<int>(6)), C(5));53 auto m = mo;54 55 assert(m.key_comp() == C(5));56 assert(std::ranges::equal(m, expected));57 auto keys = std::move(m).extract();58 assert(keys.get_allocator() == other_allocator<int>(-2));59 60 // mo is unchanged61 assert(mo.key_comp() == C(5));62 assert(std::ranges::equal(mo, expected));63 auto keys2 = std::move(mo).extract();64 assert(keys2.get_allocator() == other_allocator<int>(6));65 }66}67 68constexpr bool test() {69 test<std::vector>();70 71#ifndef __cpp_lib_constexpr_deque72 if (!TEST_IS_CONSTANT_EVALUATED)73#endif74 test<std::deque>();75 76 return true;77}78 79int main(int, char**) {80 test();81#if TEST_STD_VER >= 2682 static_assert(test());83#endif84 85 return 0;86}87