C++ 静态';当使用std::is_相同、std::result_of和std::bind时,无法按预期工作

C++ 静态';当使用std::is_相同、std::result_of和std::bind时,无法按预期工作,c++,c++11,static-assert,C++,C++11,Static Assert,当使用static\u assert断言函数对象的返回类型与另一个类型相同时,我遇到了一个奇怪的行为。类似这样的代码(这段代码只是用来表示问题,而不是我真正想做的) intfoo(){ 返回0; } int main(){ auto-funcObj=std::bind(foo); 静态断言(std::is_same::value,“FuncObj返回类型不是int”); 返回0; } 断言失败了。这里出了什么问题?的std::result\u是一个无法直接使用的类型 typename std:

当使用
static\u assert
断言
函数对象的返回类型与另一个类型相同时,我遇到了一个奇怪的行为。类似这样的代码(这段代码只是用来表示问题,而不是我真正想做的)

intfoo(){
返回0;
}
int main(){
auto-funcObj=std::bind(foo);
静态断言(std::is_same::value,“FuncObj返回类型不是int”);
返回0;
}
断言失败了。这里出了什么问题?

的std::result\u是一个无法直接使用的类型

typename std::result of::type
std::result of of
(在C++14中)您想要什么

获取此类错误消息的简单方法是:

std::result_of<decltype(funcObj)()> x = 3;
std::x=3的结果;
这将生成错误消息,明确说明lhs类型不是您预期的
int
。(通常无法将
int
转换为“某个复杂类型”。

std::result\u of
是一个无法直接使用的类型

typename std::result of::type
std::result of of
(在C++14中)您想要什么

获取此类错误消息的简单方法是:

std::result_of<decltype(funcObj)()> x = 3;
std::x=3的结果;
这将生成错误消息,明确说明lhs类型不是您预期的
int
。(通常无法将
int
转换为“某些复杂类型”。

static_assert(std::is_same<std::result_of<funcObj()>, int>::value, "FuncObj return type is not int");
static_断言(std::is_same::value,“FuncObj返回类型不是int”);
需要

static_assert(std::is_same<typename std::result_of<decltype(funcObj)()>::type, int>::value, "FuncObj return type is not int");
        // Missing pieces  ^^^^^^^^                                 ^^ ^^^^^^
static_断言(std::is_same::value,“FuncObj返回类型不是int”);
//缺件^^^^^^^^^^^^^^
线路

static_assert(std::is_same<std::result_of<funcObj()>, int>::value, "FuncObj return type is not int");
static_断言(std::is_same::value,“FuncObj返回类型不是int”);
需要

static_assert(std::is_same<typename std::result_of<decltype(funcObj)()>::type, int>::value, "FuncObj return type is not int");
        // Missing pieces  ^^^^^^^^                                 ^^ ^^^^^^
static_断言(std::is_same::value,“FuncObj返回类型不是int”);
//缺件^^^^^^^^^^^^^^

我猜您的意思是:
静态断言(std::is_same::value,“FuncObj返回类型不是int”)请发布实际生成问题错误消息的代码。当发生您不理解的事情时,如果您不测试简化没有删除导致它发生的部分,简化很可能会删除导致它发生的部分。我猜您的意思是:
static_assert(std::is_same::value,“FuncObj返回类型不是int”)请发布实际生成问题错误消息的代码。当发生您不理解的事情时,如果您不测试简化没有删除导致它发生的部分,简化很可能会删除导致它发生的部分。