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