1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
|
template <typename Type>
concept Subtractable =
requires(Type lh, Type rh)
{
lh - rh;
};
//functions
template <typename Type> // advice: define concepts in
concept Addable = // separate headers.
requires(Type lh, Type rh)
{
lh + rh;
};
template <typename Type> // declares an unconstrained
void fun(); // function template
template <Addable Type> // declares a constrained overloaded
void fun(); // function template
template <typename Type> // same, requirement follows fun
void fun() requires Addable<Type>;
template <typename Type> // same, requirement precedes fun
requires Addable<Type> void fun();
//=
//classes
template <typename Type> // unconstrained
struct Data; // declaration
template <Addable Type> // constrained declaration
struct Data<Type>; // (i.e., a specialization)
// template <typename Type> // same specialization
// requires Addable<Type> struct Data<Type>;
//=
//multi
template <typename Type> // used concepts
concept C1 = true;
template <typename Type>
concept C2 = true;
template <C1 Type> // multiply constrained
requires C2<Type> void fun(); // function template
template <typename Type> // same, using 'and'
requires C1<Type> and C2<Type> void fun();
template <typename Type> // same, trailing 'requires'
void fun() requires C1<Type> and C2<Type>;
template <typename Type>
struct Multi;
template <C1 Type> // multiply constrained
requires C2<Type> struct Multi<Type>; // class template
//=
|