3 ms·
I see it like this: requires can enforce any constraints (any logical predicate/boolean expression) that are able to be checked at compilation time / template i
by nsajko 6y ago
I see it like this: requires can enforce any constraints (any logical predicate/boolean expression) that are able to be checked at compilation time / template instantiation time. So, you can use requires to check other stuff than if certain operations exist, like e.g.:
* that a certain non-type template parameter belongs to a set of hard-coded values
* that a certain non-type template parameter is an even number
* constrain the number of elements in a parameter pack
* things involving sizeof
* that a certain non-type template parameter has a popcount of one (i.e., it only has a single bit)
* that a certain type template parameter is integral AND unsigned
* ...