Debian Codegraph @

yo/advancedtemplates/concepts/examples/funorvar.cc

raw
1 template <typename Type>
2 concept bool Comparable() // function concept
3 {
4 return
5 requires(Type lhs, Type rhs)
6 {
7 operator<(lhs, rhs);
8 };
9 }
10
11 template <typename Type>
12 concept bool Comparable2 = // variable concept
13 requires(Type lhs, Type rhs)
14 {
15 operator<(lhs, rhs);
16 };
17
18
19 template<Comparable Type> // concept names can be function
20 Type const &min(Type const &x, Type const &y) // and variable concepts
21 {
22 return y < x ? y : x;
23 }
24
25 template<Comparable2 Type>
26 Type const &min(Type const &x, Type const &y)
27 {
28 return y < x ? y : x;
29 }
30
31 template<typename Type> requires Comparable2<Type> // cannot be fun. con.
32 Type const &min2(Type const &x, Type const &y)
33 {
34 return y < x ? y : x;
35 }