I'm experiencing a weird behavior when using static_assert
for asserting that the return type of a function object
is the same as another type. Something like (This code is just for presenting the problem and not actually what i'm trying to do).
int foo() {
return 0;
}
int main() {
auto funcObj = std::bind(foo);
static_assert(std::is_same<std::result_of<funcObj()>, int>::value, "FuncObj return type is not int");
return 0;
}
The assertion fails. What's going wrong here?
std::result_of<?>
is a useless type to use directly.typename std::result_of<?>::type
andstd::result_of_t<?>
(in C++14) what you want.An easy way to get a good error message for this kind of thing is:
which should generate error messages that make it clear that the lhs type is not
int
like you expected. (cannot convertint
to 'some complex type' usually).