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 F, class... Args>
12// concept equivalence_relation;
13
14#include <concepts>
15
16struct S1 {};
17struct S2 {};
18
19struct R {
20 bool operator()(S1, S1) const;
21 bool operator()(S1, S2) const;
22 bool operator()(S2, S1) const;
23 bool operator()(S2, S2) const;
24};
25
26// clang-format off
27template<class F, class T, class U>
28requires std::relation<F, T, U>
29constexpr bool check_equivalence_relation_subsumes_relation() {
30 return false;
31}
32
33template<class F, class T, class U>
34requires std::equivalence_relation<F, T, U> && true
35constexpr bool check_equivalence_relation_subsumes_relation() {
36 return true;
37}
38// clang-format on
39
40static_assert(check_equivalence_relation_subsumes_relation<int (*)(int, int), int, int>());
41static_assert(check_equivalence_relation_subsumes_relation<int (*)(int, double), int, double>());
42static_assert(check_equivalence_relation_subsumes_relation<R, S1, S1>());
43static_assert(check_equivalence_relation_subsumes_relation<R, S1, S2>());
44
45// clang-format off
46template<class F, class T, class U>
47requires std::relation<F, T, U> && true
48constexpr bool check_relation_subsumes_equivalence_relation() {
49 return true;
50}
51
52template<class F, class T, class U>
53requires std::equivalence_relation<F, T, U>
54constexpr bool check_relation_subsumes_equivalence_relation() {
55 return false;
56}
57// clang-format on
58
59static_assert(check_relation_subsumes_equivalence_relation<int (*)(int, int), int, int>());
60static_assert(check_relation_subsumes_equivalence_relation<int (*)(int, double), int, double>());
61static_assert(check_relation_subsumes_equivalence_relation<R, S1, S1>());
62static_assert(check_relation_subsumes_equivalence_relation<R, S1, S2>());
63
64// clang-format off
65template<class F, class T, class U>
66requires std::equivalence_relation<F, T, T> && std::equivalence_relation<F, U, U>
67constexpr bool check_equivalence_relation_subsumes_itself() {
68 return false;
69}
70
71template<class F, class T, class U>
72requires std::equivalence_relation<F, T, U>
73constexpr bool check_equivalence_relation_subsumes_itself() {
74 return true;
75}
76// clang-format on
77
78static_assert(
79 check_equivalence_relation_subsumes_itself<int (*)(int, int), int, int>());
80static_assert(check_equivalence_relation_subsumes_itself<R, S1, S1>());
81

source code of libcxx/test/std/concepts/concepts.callable/concept.equiv/equivalence_relation.subsumption.compile.pass.cpp