brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.9 KiB · 3a7ff86 Raw
114 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();14 15#include <cassert>16#include <deque>17#include <flat_set>18#include <functional>19#include <type_traits>20#include <vector>21 22#include "min_allocator.h"23#include "MoveOnly.h"24#include "test_allocator.h"25#include "test_macros.h"26 27struct DefaultCtableComp {28  constexpr explicit DefaultCtableComp() { default_constructed_ = true; }29  constexpr bool operator()(int, int) const { return false; }30  bool default_constructed_ = false;31};32 33struct ThrowingCtorComp {34  constexpr ThrowingCtorComp() noexcept(false) {}35  constexpr bool operator()(const auto&, const auto&) const { return false; }36};37 38template <template <class...> class KeyContainer>39constexpr void test() {40  {41    std::flat_multiset<int, std::less<int>, KeyContainer<int>> m;42    assert(m.empty());43  }44  {45    // explicit(false)46    std::flat_multiset<int, std::less<int>, KeyContainer<int>> m = {};47    assert(m.empty());48  }49  {50    std::flat_multiset<int, DefaultCtableComp, KeyContainer<int, min_allocator<int>>> m;51    assert(m.empty());52    assert(m.begin() == m.end());53    assert(m.key_comp().default_constructed_);54  }55  {56    using A1 = explicit_allocator<int>;57    {58      std::flat_multiset<int, DefaultCtableComp, KeyContainer<int, A1>> m;59      assert(m.empty());60      assert(m.key_comp().default_constructed_);61    }62    {63      A1 a1;64      std::flat_multiset<int, DefaultCtableComp, std::vector<int, A1>> m(a1);65      assert(m.empty());66      assert(m.key_comp().default_constructed_);67    }68  }69#if defined(_LIBCPP_VERSION)70  {71    using C = std::flat_multiset<MoveOnly, std::less<MoveOnly>>;72    static_assert(std::is_nothrow_default_constructible_v<C>);73    C c;74  }75  {76    using C = std::flat_multiset<MoveOnly, std::less<MoveOnly>, KeyContainer<MoveOnly, test_allocator<MoveOnly>>>;77    static_assert(std::is_nothrow_default_constructible_v<C>);78    C c;79  }80#endif // _LIBCPP_VERSION81  {82    using C = std::flat_multiset<MoveOnly, std::less<MoveOnly>, KeyContainer<MoveOnly, other_allocator<MoveOnly>>>;83    static_assert(!std::is_nothrow_default_constructible_v<C>);84    C c;85  }86  {87    using C = std::flat_multiset<MoveOnly, ThrowingCtorComp, KeyContainer<MoveOnly>>;88    static_assert(!std::is_nothrow_default_constructible_v<C>);89    C c;90  }91}92 93constexpr bool test() {94  test<std::vector>();95 96#ifndef __cpp_lib_constexpr_deque97  if (!TEST_IS_CONSTANT_EVALUATED)98#endif99  {100    test<std::deque>();101  }102 103  return true;104}105 106int main(int, char**) {107  test();108#if TEST_STD_VER >= 26109  static_assert(test());110#endif111 112  return 0;113}114