Debian Codegraph @

yo/advancedtemplates/concepts/examples/predefined.cc

raw
1 #include <string>
2 #include <concepts>
3
4 template <typename LHS, typename RHS>
5 concept CommonWith = std::common_with<LHS, RHS>;
6
7 template <typename T1, typename T2>
8 requires CommonWith<T1, T2>
9 void fun2(T1 &&t1, T2 &&t2)
10 {}
11
12
13 template <typename LHS, typename RHS>
14 concept CommonRef = std::common_reference_with<LHS, RHS>;
15
16 template <typename T1, typename T2>
17 requires CommonRef<T1, T2>
18 void fun(T1 &&t1, T2 &&t2)
19 {}
20
21 struct B
22 {};
23
24 struct D1: public B
25 {
26 };
27
28 struct D2: public B
29 {
30 };
31
32 int main()
33 {
34 fun(4, 'a');
35 fun(4.5, 'a');
36
37 D1 d1;
38 B b;
39
40 fun(b, d1); // OK
41 fun(d1, b); // OK
42 fun(B{}, d1); // OK
43 fun(d1, B{}); // OK
44 fun(b, D1{}); // OK
45 fun(D1{}, b); // OK
46 fun(B{}, D1{}); // OK
47 fun(D1{}, B{}); // OK
48
49 fun2(B{}, D2{}); // OK
50 }