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
|
Simple:
=======
template <typename Type>
concept BasicMath =
requires(Type lhs, Type rhs)
{
lhs + rhs; // addition must be available
};
also calling a function may be used as simple requirement:
template< class T >
concept swappable =
requires(T &a, T &b)
{
ranges::swap(a, b);
};
Type:
=====
template <typename Type>
concept HasValueType =
requires()
{
typename Type::value_type;
};
Compound:
=========
concept ReturnType =
requires(Type par)
{
{ par[0] } -> std::same_as<Ret>; // par[..] returns a Ret
}
Nested:
=======
template <typename Type>
concept BiIterator =
FwdIterator<Type>
and
requires(Type type)
{
--type;
};
templates using concepts:
=========================
template <BiIterator Type>
void biFun(Type tp)
{}
---------------------------
template <typename Type>
void biFun(Type tp)
requires BiIterator<Type>
{}
|