83 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&, 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 {29 // The constructors in this subclause shall not participate in overload30 // resolution unless uses_allocator_v<container_type, Alloc> is true.31 32 using C = test_less<int>;33 using A1 = test_allocator<int>;34 using A2 = other_allocator<int>;35 using V1 = KeyContainer<int, A1>;36 using V2 = KeyContainer<int, A2>;37 using M1 = std::flat_multiset<int, C, V1>;38 using M2 = std::flat_multiset<int, C, V2>;39 static_assert(std::is_constructible_v<M1, const M1&, const A1&>);40 static_assert(std::is_constructible_v<M2, const M2&, const A2&>);41 static_assert(!std::is_constructible_v<M1, const M1&, const A2&>);42 static_assert(!std::is_constructible_v<M2, const M2&, const A1&>);43 }44 {45 using C = test_less<int>;46 KeyContainer<int, test_allocator<int>> ks({1, 3, 5, 5}, test_allocator<int>(6));47 using M = std::flat_multiset<int, C, decltype(ks)>;48 auto mo = M(ks, C(5));49 auto m = M(mo, test_allocator<int>(3));50 51 assert(m.key_comp() == C(5));52 assert(std::ranges::equal(m, ks));53 auto keys = std::move(m).extract();54 assert(keys.get_allocator() == test_allocator<int>(3));55 56 // mo is unchanged57 assert(mo.key_comp() == C(5));58 assert(std::ranges::equal(mo, ks));59 auto keys2 = std::move(mo).extract();60 assert(keys2.get_allocator() == test_allocator<int>(6));61 }62}63 64constexpr bool test() {65 test<std::vector>();66 67#ifndef __cpp_lib_constexpr_deque68 if (!TEST_IS_CONSTANT_EVALUATED)69#endif70 test<std::deque>();71 72 return true;73}74 75int main(int, char**) {76 test();77#if TEST_STD_VER >= 2678 static_assert(test());79#endif80 81 return 0;82}83