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
18using CompInt = bool(*)(int, int);
19using CompDefault = std::ranges::less;
20
21using AllConstraintsSatisfied = int*;
22static_assert( std::permutable<AllConstraintsSatisfied>);
23static_assert( std::indirect_strict_weak_order<CompDefault, AllConstraintsSatisfied>);
24static_assert( std::sortable<AllConstraintsSatisfied>);
25static_assert( std::indirect_strict_weak_order<CompInt, AllConstraintsSatisfied>);
26static_assert( std::sortable<AllConstraintsSatisfied, CompInt>);
27
28struct Foo {};
29using Proj = int(*)(Foo);
30static_assert( std::permutable<Foo*>);
31static_assert(!std::indirect_strict_weak_order<CompDefault, Foo*>);
32static_assert( std::indirect_strict_weak_order<CompDefault, std::projected<Foo*, Proj>>);
33static_assert(!std::sortable<Foo*, CompDefault>);
34static_assert( std::sortable<Foo*, CompDefault, Proj>);
35static_assert(!std::indirect_strict_weak_order<CompInt, Foo*>);
36static_assert( std::indirect_strict_weak_order<CompInt, std::projected<Foo*, Proj>>);
37static_assert(!std::sortable<Foo*, CompInt>);
38static_assert( std::sortable<Foo*, CompInt, Proj>);
39
40using NotPermutable = const int*;
41static_assert(!std::permutable<NotPermutable>);
42static_assert( std::indirect_strict_weak_order<CompInt, NotPermutable>);
43static_assert(!std::sortable<NotPermutable, CompInt>);
44
45struct Empty {};
46using NoIndirectStrictWeakOrder = Empty*;
47static_assert( std::permutable<NoIndirectStrictWeakOrder>);
48static_assert(!std::indirect_strict_weak_order<CompInt, NoIndirectStrictWeakOrder>);
49static_assert(!std::sortable<NoIndirectStrictWeakOrder, CompInt>);
50

source code of libcxx/test/std/iterators/iterator.requirements/alg.req.sortable/sortable.compile.pass.cpp