Debian Codegraph @

gcc/testsuite/g++.dg/cpp2a/concepts-pr84140.C

raw
1 // { dg-do run { target c++20 } }
2
3 template<class, class> constexpr bool is_same_v = false;
4 template<class T> constexpr bool is_same_v<T, T> = true;
5
6 template<class T, class U>
7 concept Same = is_same_v<T, U>;
8
9 template<class T, class U>
10 concept Diff = requires(T& t, U& u) { u - t; };
11
12 template<class I, class S>
13 int distance(I, S) { return 0; }
14
15 template<class I, Diff<I> S>
16 int distance(I first, S last)
17 {
18 return last - first;
19 }
20
21 template<class T>
22 struct I
23 {
24 template<class U>
25 requires Same<T, U>
26 friend int operator-(I const&, I<U> const&)
27 {
28 static_assert(Same<T, U>);
29 return 42;
30 }
31 };
32
33 int main()
34 {
35 return distance(I<int>{}, I<void>{});
36 }