Negations Using Concepts

Get an overview of how negation works with concepts.

!a is not the opposite of a

When we talk about concepts, the opposite of a true expression is not an expression that is evaluated to false. Let’s suppose we have a function foo() that takes two parameters, T bar and U baz. We have some constraints on them. One of them must have a nested type Blah that is unsigned.

Press + to interact
#include <concepts>
template <typename T, typename U>
requires std::unsigned_integral<typename T::Blah> ||
std::unsigned_integral<typename U::Blah>
void foo(T bar, U baz) {
// ...
}
class MyType {
public:
using Blah = unsigned int;
// ...
};
int main() {
MyType mt;
foo(mt, 5);
foo(5, mt);
// error: no operand of the disjunction is satisfied
// foo(5, 3);
}

When we call foo() on line 18 with an instance of MyType in the ...