| 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-exception |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20 |
| 10 | |
| 11 | // <flat_set> |
| 12 | |
| 13 | // flat_set(); |
| 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 | |
| 27 | struct DefaultCtableComp { |
| 28 | explicit DefaultCtableComp() { default_constructed_ = true; } |
| 29 | bool operator()(int, int) const { return false; } |
| 30 | bool default_constructed_ = false; |
| 31 | }; |
| 32 | |
| 33 | struct ThrowingCtorComp { |
| 34 | ThrowingCtorComp() noexcept(false) {} |
| 35 | bool operator()(const auto&, const auto&) const { return false; } |
| 36 | }; |
| 37 | |
| 38 | void test() { |
| 39 | { |
| 40 | std::flat_set<int> m; |
| 41 | assert(m.empty()); |
| 42 | } |
| 43 | { |
| 44 | // explicit(false) |
| 45 | std::flat_set<int> m = {}; |
| 46 | assert(m.empty()); |
| 47 | } |
| 48 | { |
| 49 | std::flat_set<int, DefaultCtableComp, std::deque<int, min_allocator<int>>> m; |
| 50 | assert(m.empty()); |
| 51 | assert(m.begin() == m.end()); |
| 52 | assert(m.key_comp().default_constructed_); |
| 53 | } |
| 54 | { |
| 55 | using A1 = explicit_allocator<int>; |
| 56 | { |
| 57 | std::flat_set<int, DefaultCtableComp, std::vector<int, A1>> m; |
| 58 | assert(m.empty()); |
| 59 | assert(m.key_comp().default_constructed_); |
| 60 | } |
| 61 | { |
| 62 | A1 a1; |
| 63 | std::flat_set<int, DefaultCtableComp, std::vector<int, A1>> m(a1); |
| 64 | assert(m.empty()); |
| 65 | assert(m.key_comp().default_constructed_); |
| 66 | } |
| 67 | } |
| 68 | #if defined(_LIBCPP_VERSION) |
| 69 | { |
| 70 | using C = std::flat_set<MoveOnly>; |
| 71 | static_assert(std::is_nothrow_default_constructible_v<C>); |
| 72 | C c; |
| 73 | } |
| 74 | { |
| 75 | using C = std::flat_set<MoveOnly, std::less<MoveOnly>, std::vector<MoveOnly, test_allocator<MoveOnly>>>; |
| 76 | static_assert(std::is_nothrow_default_constructible_v<C>); |
| 77 | C c; |
| 78 | } |
| 79 | #endif // _LIBCPP_VERSION |
| 80 | { |
| 81 | using C = std::flat_set<MoveOnly, std::less<MoveOnly>, std::vector<MoveOnly, other_allocator<MoveOnly>>>; |
| 82 | static_assert(!std::is_nothrow_default_constructible_v<C>); |
| 83 | C c; |
| 84 | } |
| 85 | { |
| 86 | using C = std::flat_set<MoveOnly, ThrowingCtorComp>; |
| 87 | static_assert(!std::is_nothrow_default_constructible_v<C>); |
| 88 | C c; |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | int main(int, char**) { |
| 93 | test(); |
| 94 | |
| 95 | return 0; |
| 96 | } |
| 97 | |