116 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// explicit flat_multiset(const key_compare& comp);14// template <class Alloc>15// flat_multiset(const key_compare& comp, const Alloc& a);16 17#include <cassert>18#include <deque>19#include <flat_set>20#include <functional>21#include <type_traits>22#include <vector>23 24#include "MinSequenceContainer.h"25#include "min_allocator.h"26#include "test_macros.h"27#include "../../../test_compare.h"28#include "test_allocator.h"29 30template <class KeyContainer>31constexpr void test_compare() {32 using Key = typename KeyContainer::value_type;33 {34 // The one-argument ctor is explicit.35 using C = test_less<Key>;36 static_assert(std::is_constructible_v<std::flat_multiset<Key, C>, C>);37 static_assert(!std::is_convertible_v<C, std::flat_multiset<Key, C>>);38 39 static_assert(std::is_constructible_v<std::flat_multiset<Key>, std::less<Key>>);40 static_assert(!std::is_convertible_v<std::less<Key>, std::flat_multiset<Key>>);41 }42 {43 using C = test_less<Key>;44 auto m = std::flat_multiset<Key, C>(C(3));45 assert(m.empty());46 assert(m.begin() == m.end());47 assert(m.key_comp() == C(3));48 }49}50 51template <template <class...> class KeyContainer>52constexpr void test_compare_alloc() {53 {54 // The constructors in this subclause shall not participate in overload55 // resolution unless uses_allocator_v<container_type, Alloc> is true56 57 using C = test_less<int>;58 using A1 = test_allocator<int>;59 using A2 = other_allocator<int>;60 using V1 = KeyContainer<int, A1>;61 using V2 = KeyContainer<int, A2>;62 using M1 = std::flat_multiset<int, C, V1>;63 using M2 = std::flat_multiset<int, C, V2>;64 static_assert(std::is_constructible_v<M1, const C&, const A1&>);65 static_assert(std::is_constructible_v<M2, const C&, const A2&>);66 static_assert(!std::is_constructible_v<M1, const C&, const A2&>);67 static_assert(!std::is_constructible_v<M2, const C&, const A1&>);68 }69 {70 using C = test_less<int>;71 using A1 = test_allocator<int>;72 auto m = std::flat_multiset<int, C, KeyContainer<int, A1>>(C(4), A1(5));73 assert(m.empty());74 assert(m.begin() == m.end());75 assert(m.key_comp() == C(4));76 assert(std::move(m).extract().get_allocator() == A1(5));77 }78 {79 // explicit(false)80 using C = test_less<int>;81 using A1 = test_allocator<int>;82 std::flat_multiset<int, C, KeyContainer<int, A1>> m = {C(4), A1(5)};83 assert(m.empty());84 assert(m.begin() == m.end());85 assert(m.key_comp() == C(4));86 assert(std::move(m).extract().get_allocator() == A1(5));87 }88}89 90constexpr bool test() {91 test_compare<std::vector<int>>();92 test_compare<MinSequenceContainer<int>>();93 test_compare<std::vector<int, min_allocator<int>>>();94 95 test_compare_alloc<std::vector>();96 97#ifndef __cpp_lib_constexpr_deque98 if (!TEST_IS_CONSTANT_EVALUATED)99#endif100 {101 test_compare<std::deque<int>>();102 test_compare_alloc<std::deque>();103 }104 105 return true;106}107 108int main(int, char**) {109 test();110#if TEST_STD_VER >= 26111 static_assert(test());112#endif113 114 return 0;115}116