brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.2 KiB · 3b7a355 Raw
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// template<class Allocator>14//   explicit flat_set(const Allocator& a);15 16#include <cassert>17#include <deque>18#include <flat_set>19#include <functional>20#include <vector>21 22#include "MinSequenceContainer.h"23#include "test_macros.h"24#include "test_allocator.h"25#include "../../../test_compare.h"26 27template <template <class...> class KeyContainer>28constexpr void test() {29  {30    // The constructors in this subclause shall not participate in overload31    // resolution unless uses_allocator_v<container_type, Alloc> is true.32 33    using C  = test_less<int>;34    using A1 = test_allocator<int>;35    using A2 = other_allocator<int>;36    using V1 = KeyContainer<int, A1>;37    using V2 = KeyContainer<int, A2>;38    using M1 = std::flat_set<int, C, V1>;39    using M2 = std::flat_set<int, C, V2>;40    static_assert(std::is_constructible_v<M1, const A1&>);41    static_assert(std::is_constructible_v<M2, const A2&>);42    static_assert(!std::is_constructible_v<M1, const A2&>);43    static_assert(!std::is_constructible_v<M2, const A1&>);44  }45  {46    // explicit47    using M = std::flat_set<int, std::less<int>, KeyContainer<int, test_allocator<int>>>;48 49    static_assert(std::is_constructible_v<M, test_allocator<int>>);50    static_assert(!std::is_convertible_v<test_allocator<int>, M>);51  }52  {53    using A = test_allocator<short>;54    using M = std::flat_set<int, std::less<int>, KeyContainer<int, test_allocator<int>>>;55    M m(A(0, 5));56    assert(m.empty());57    assert(m.begin() == m.end());58    auto v = std::move(m).extract();59    assert(v.get_allocator().get_id() == 5);60  }61}62 63constexpr bool test() {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