81 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&, const allocator_type&);14 15#include <algorithm>16#include <cassert>17#include <deque>18#include <flat_set>19#include <functional>20#include <vector>21 22#include "test_macros.h"23#include "../../../test_compare.h"24#include "test_allocator.h"25 26template <template <class...> class KeyContainer>27constexpr void test() {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 = M(mo, test_allocator<int>(3));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>(3));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 46constexpr bool test() {47 {48 // The constructors in this subclause shall not participate in overload49 // resolution unless uses_allocator_v<container_type, Alloc> is true.50 51 using C = test_less<int>;52 using A1 = test_allocator<int>;53 using A2 = other_allocator<int>;54 using V1 = std::vector<int, A1>;55 using V2 = std::vector<int, A2>;56 using M1 = std::flat_set<int, C, V1>;57 using M2 = std::flat_set<int, C, V2>;58 static_assert(std::is_constructible_v<M1, const M1&, const A1&>);59 static_assert(std::is_constructible_v<M2, const M2&, const A2&>);60 static_assert(!std::is_constructible_v<M1, const M1&, const A2&>);61 static_assert(!std::is_constructible_v<M2, const M2&, const A1&>);62 }63 64 test<std::vector>();65#ifndef __cpp_lib_constexpr_deque66 if (!TEST_IS_CONSTANT_EVALUATED)67#endif68 test<std::deque>();69 70 return true;71}72 73int main(int, char**) {74 test();75#if TEST_STD_VER >= 2676 static_assert(test());77#endif78 79 return 0;80}81