brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.5 KiB · 712f33a Raw
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_set(const key_compare& comp);14// template <class Alloc>15//   flat_set(const key_compare& comp, const Alloc& a);16 17#include <deque>18#include <flat_set>19#include <functional>20#include <type_traits>21#include <vector>22 23#include "test_macros.h"24#include "../../../test_compare.h"25#include "test_allocator.h"26#include "MinSequenceContainer.h"27#include "min_allocator.h"28 29template <class KeyContainer>30constexpr void test_compare() {31  {32    using C = test_less<int>;33    auto m  = std::flat_set<int, C, KeyContainer>(C(3));34    assert(m.empty());35    assert(m.begin() == m.end());36    assert(m.key_comp() == C(3));37  }38  {39    // The one-argument ctor is explicit.40    using C = test_less<int>;41    static_assert(std::is_constructible_v<std::flat_set<int, C, KeyContainer>, C>);42    static_assert(!std::is_convertible_v<C, std::flat_set<int, C, KeyContainer>>);43 44    static_assert(std::is_constructible_v<std::flat_set<int, std::less<int>, KeyContainer>, std::less<int>>);45    static_assert(!std::is_convertible_v<std::less<int>, std::flat_set<int, std::less<int>, KeyContainer>>);46  }47}48 49template <template <class...> class KeyContainer>50constexpr void test_compare_alloc() {51  {52    using C  = test_less<int>;53    using A1 = test_allocator<int>;54    auto m   = std::flat_set<int, C, KeyContainer<int, A1>>(C(4), A1(5));55    assert(m.empty());56    assert(m.begin() == m.end());57    assert(m.key_comp() == C(4));58    auto keys = std::move(m).extract();59    assert(keys.get_allocator() == A1(5));60  }61  {62    // explicit(false)63    using C                                        = test_less<int>;64    using A1                                       = test_allocator<int>;65    std::flat_set<int, C, KeyContainer<int, A1>> m = {C(4), A1(5)};66    assert(m.empty());67    assert(m.begin() == m.end());68    assert(m.key_comp() == C(4));69    auto keys = std::move(m).extract();70    assert(keys.get_allocator() == A1(5));71  }72}73 74constexpr bool test() {75  {76    // The constructors in this subclause shall not participate in overload77    // resolution unless uses_allocator_v<container_type, Alloc> is true.78 79    using C  = test_less<int>;80    using A1 = test_allocator<int>;81    using A2 = other_allocator<int>;82    using V1 = std::vector<int, A1>;83    using V2 = std::vector<int, A2>;84    using M1 = std::flat_set<int, C, V1>;85    using M2 = std::flat_set<int, C, V2>;86    static_assert(std::is_constructible_v<M1, const C&, const A1&>);87    static_assert(std::is_constructible_v<M2, const C&, const A2&>);88    static_assert(!std::is_constructible_v<M1, const C&, const A2&>);89    static_assert(!std::is_constructible_v<M2, const C&, const A1&>);90  }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