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 |
10 | |
11 | // template<class I, class R = ranges::less, class P = identity> |
12 | // concept sortable = see below; // since C++20 |
13 | |
14 | #include <iterator> |
15 | |
16 | #include <functional> |
17 | |
18 | using CompInt = bool(*)(int, int); |
19 | using CompDefault = std::ranges::less; |
20 | |
21 | using AllConstraintsSatisfied = int*; |
22 | static_assert( std::permutable<AllConstraintsSatisfied>); |
23 | static_assert( std::indirect_strict_weak_order<CompDefault, AllConstraintsSatisfied>); |
24 | static_assert( std::sortable<AllConstraintsSatisfied>); |
25 | static_assert( std::indirect_strict_weak_order<CompInt, AllConstraintsSatisfied>); |
26 | static_assert( std::sortable<AllConstraintsSatisfied, CompInt>); |
27 | |
28 | struct Foo {}; |
29 | using Proj = int(*)(Foo); |
30 | static_assert( std::permutable<Foo*>); |
31 | static_assert(!std::indirect_strict_weak_order<CompDefault, Foo*>); |
32 | static_assert( std::indirect_strict_weak_order<CompDefault, std::projected<Foo*, Proj>>); |
33 | static_assert(!std::sortable<Foo*, CompDefault>); |
34 | static_assert( std::sortable<Foo*, CompDefault, Proj>); |
35 | static_assert(!std::indirect_strict_weak_order<CompInt, Foo*>); |
36 | static_assert( std::indirect_strict_weak_order<CompInt, std::projected<Foo*, Proj>>); |
37 | static_assert(!std::sortable<Foo*, CompInt>); |
38 | static_assert( std::sortable<Foo*, CompInt, Proj>); |
39 | |
40 | using NotPermutable = const int*; |
41 | static_assert(!std::permutable<NotPermutable>); |
42 | static_assert( std::indirect_strict_weak_order<CompInt, NotPermutable>); |
43 | static_assert(!std::sortable<NotPermutable, CompInt>); |
44 | |
45 | struct Empty {}; |
46 | using NoIndirectStrictWeakOrder = Empty*; |
47 | static_assert( std::permutable<NoIndirectStrictWeakOrder>); |
48 | static_assert(!std::indirect_strict_weak_order<CompInt, NoIndirectStrictWeakOrder>); |
49 | static_assert(!std::sortable<NoIndirectStrictWeakOrder, CompInt>); |
50 | |