I want to do this:
template<T>
bool AssertThrows() {
try {
T; // T is an expression, so evaluate it here
return false;
} catch(...) {
return true;
}
}
int main() {
bool throws = !AssertThrows<5 + 2>();
return !throws;
}
But this does not work: all I get is these compiler errors:
$ clang++ a.cc
a.cc:1:10: error: unknown type name 'T'
template<T>
^
a.cc:4:5: error: use of undeclared identifier 'T'
T; // T is an expression
^
2 errors generated.
Is it possible to have an expression as a template parameter?
In this case a function taking another function to simulate pass by name could work if you don’t mind