| 1 |
|
| 2 |
template <typename Type> |
| 3 |
concept bool Constraint() // function concept |
| 4 |
{ |
| 5 |
return |
| 6 |
requires(Type lhs, Type rhs) |
| 7 |
{ |
| 8 |
{ lhs < rhs } -> bool; // multiple |
| 9 |
lhs + rhs; // constraints |
| 10 |
// typename Type::value_type; |
| 11 |
}; |
| 12 |
} |
| 13 |
|
| 14 |
template <typename Type> |
| 15 |
concept bool Constraint2 = // variable concept |
| 16 |
requires(Type lhs, Type rhs) |
| 17 |
{ |
| 18 |
// { operator<(lhs, rhs) } -> bool; // both OK |
| 19 |
{ lhs < rhs } -> bool; |
| 20 |
|
| 21 |
lhs + rhs; |
| 22 |
typename Type::value_type; |
| 23 |
}; |
| 24 |
|
| 25 |
|
| 26 |
// template <typename Type> concept bool Constraint = true ; |
| 27 |
|
| 28 |
struct Combi |
| 29 |
{ |
| 30 |
using value_type = int; |
| 31 |
}; |
| 32 |
|
| 33 |
bool operator<(Combi const &lhs, Combi const &rhs); |
| 34 |
Combi operator+(Combi const &lhs, Combi const &rhs); |
| 35 |
|
| 36 |
|
| 37 |
template <Constraint Type> // declares a multiply |
| 38 |
requires Constraint2<Type> void fun(); // constrained function template |
| 39 |
|
| 40 |
int main() |
| 41 |
{ |
| 42 |
fun<Combi>(); |
| 43 |
} |