| 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 | // Test CTAD on cases where deduction should fail. |
| 14 | |
| 15 | #include <flat_set> |
| 16 | #include <functional> |
| 17 | #include <memory> |
| 18 | #include <utility> |
| 19 | #include <vector> |
| 20 | |
| 21 | struct NotAnAllocator { |
| 22 | friend bool operator<(NotAnAllocator, NotAnAllocator) { return false; } |
| 23 | }; |
| 24 | |
| 25 | template <class... Args> |
| 26 | concept CanDeductFlatSet = requires { std::flat_set(std::declval<Args>()...); }; |
| 27 | |
| 28 | static_assert(CanDeductFlatSet<std::vector<int>>); |
| 29 | |
| 30 | // cannot deduce Key and T from nothing |
| 31 | static_assert(!CanDeductFlatSet<>); |
| 32 | |
| 33 | // cannot deduce Key and T from just (Compare) |
| 34 | static_assert(!CanDeductFlatSet<std::less<int>>); |
| 35 | |
| 36 | // cannot deduce Key and T from just (Compare, Allocator) |
| 37 | static_assert(!CanDeductFlatSet<std::less<int>, std::allocator<int>>); |
| 38 | |
| 39 | // cannot deduce Key and T from just (Allocator) |
| 40 | static_assert(!CanDeductFlatSet<std::allocator<int>>); |
| 41 | |
| 42 | // cannot convert from some arbitrary unrelated type |
| 43 | static_assert(!CanDeductFlatSet<NotAnAllocator>); |
| 44 | |