I have a template that calls a member function. How do I check with static_assert
that the method exists?
struct A {
};
struct B {
int foo() { return 42; } };
template <typename T> struct D {
static_assert(/* T has foo */, "T needs foo for reasons");
int bar() {
return t.foo();
}
T t; };
int main() {
D<A> d;
std::cout << d.bar() << std::endl;
return 0; }
I know this will just generate a compiler error that A does not have foo but I would like to check and give a better error output using static_assert
.