84 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_set(const flat_set& 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}, test_allocator<int>(6));30 using M = std::flat_set<int, C, decltype(ks)>;31 auto mo = M(ks, C(5));32 auto m = mo;33 34 assert(m.key_comp() == C(5));35 assert(std::ranges::equal(m, ks));36 auto keys = std::move(m).extract();37 assert(keys.get_allocator() == test_allocator<int>(6));38 39 // mo is unchanged40 assert(mo.key_comp() == C(5));41 assert(std::ranges::equal(mo, ks));42 auto keys2 = std::move(mo).extract();43 assert(keys2.get_allocator() == test_allocator<int>(6));44 }45 {46 using C = test_less<int>;47 using Ks = KeyContainer<int, other_allocator<int>>;48 auto ks = Ks({1, 3, 5}, other_allocator<int>(6));49 using M = std::flat_set<int, C, Ks>;50 auto mo = M(Ks(ks, other_allocator<int>(6)), C(5));51 auto m = mo;52 53 assert(m.key_comp() == C(5));54 assert(std::ranges::equal(m, ks));55 auto keys = std::move(m).extract();56 assert(keys.get_allocator() == other_allocator<int>(-2));57 58 // mo is unchanged59 assert(mo.key_comp() == C(5));60 assert(std::ranges::equal(mo, ks));61 auto keys2 = std::move(mo).extract();62 assert(keys2.get_allocator() == other_allocator<int>(6));63 }64}65 66constexpr bool test() {67 test<std::vector>();68#ifndef __cpp_lib_constexpr_deque69 if (!TEST_IS_CONSTANT_EVALUATED)70#endif71 test<std::deque>();72 73 return true;74}75 76int main(int, char**) {77 test();78#if TEST_STD_VER >= 2679 static_assert(test());80#endif81 82 return 0;83}84