The following code is an usage example of the requires
-clause:
#include <type_traits>
template <typename T>
requires std::is_integral_v<T>
void take_integral(T value);
It accepts an expression that evalutes to a bool
value (std::is_integral_v<T>
in this case), and works as expected.
However, when such expression is negated with the !
operator, it results in a compilation error:
#include <type_traits>
template <typename T>
requires !std::is_integral_v<T>
void take_integral(T value);
Diagnostic from GCC:
<source>:4:12: error: expression must be enclosed in parentheses
4 | requires !std::is_integral_v<T>
| ^~~~~~~~~~~~~~~~~~~~~~
| ( )
Compiler returned: 1
Diagnostic from Clang:
<source>:4:12: error: parentheses are required around this expression in a requires clause
requires !std::is_integral_v<T>
^~~~~~~~~~~~~~~~~~~~~~
( )
1 error generated.
Compiler returned: 1
Why are parentheses needed here?