问题标签 [result-of]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
c++ - std::result_of 不适用于在 Visual Studio 2012 中 operator() 具有右值参数的函子
这里简单的例子:
当我尝试在 VisualStudio 2012 中编译它时出现错误:
我在 mingw-g++ 中编译了相同的代码,一切正常。除了编写自己的 result_of 实现之外,我还能做些什么吗?(我把它写成解决方法)。
c++ - 有人可以解释如何在模板中使用 result_of 吗?
我正在尝试创建一个可延迟的调用对象。类似于(伪代码)的东西:
我尝试使用 result_of::type 作为调用的返回类型,但在模板的实例化过程中出现错误,因为显然需要单独指定参数类型。
实例化:
我读过的有关 result_of 的错误消息和文档似乎表明还必须指定参数类型。因此result_of<FN>::type
,我需要指定result_of<FN(bool, double)>::type
. 这确实解决了我遇到的编译问题,但打破了模板的通用性。
那么,当模板参数表示函数签名时,如何将 result_of 与模板参数一起使用?
c++ - VS 2013 SFINAE 缺陷的解决方法
我正在尝试修复一个库(entityx),该库当前无法使用 VS 2013 在 Windows 上编译。它可以在 Linux 上使用 gcc 编译,也可以在 Windows 上使用 MinGW 编译。
似乎问题出在 SFINAE - 我猜 VS 2013 没有正确忽略模板的替换失败。
Microsoft Connect 上有关于此问题的报告,请点击此处。
在我深入研究 entityx之前,有一个问题示例(取自 Microsoft Connect 的报告):
尝试编译时出现以下错误:
错误 C2064:术语不计算为采用 0 个参数的函数
c:\program 文件 (x86)\microsoft visual studio 12.0\vc\include\xrefwrap 58
显然,我们可以std::enable_if
用来解决这个问题。但是,我无法弄清楚如何。
有谁知道我可以如何解决这个编译错误?
编辑:VS 2013 的完整输出:
c++ - std::bind 上的 std::result_of 无法在 clang++ 3.4 上编译
以下代码使用 g++-4.8 编译,但在使用 clang 3.4 时不编译。
g++-4.8 -std=c++0x test.cpp #OK
clang++ -std=c++0x test.cpp
当您取消注释注释行并注释以下行时,代码将在两个 clang ang g++ 上编译。
c++ - 调用模板参数成员函数的result_of
我需要获取类模板参数的成员函数的结果。不幸的是,我绑定到 C++03 并且不能使用 decltype,但是我可以使用 tr1::result_of。我尝试了以下代码,但这不适用于我的编译器(gcc 4.3,我也无法更改):
上面的代码反映了我的理解result_of<Fn(ArgTypes ...)
:
如果 Fn 是指向非静态成员函数的指针,并且 ArgTypes 中的第一个类型是该成员所属的类(或对它的引用,或对派生类型的引用,或指向它的指针),并且ArgTypes 中的其余类型描述了它的参数。
我将一个指向成员函数的指针传递给它,并将第一个参数类型指定为指向该类的指针。但是,编译器会打印以下错误:
我无法将 O 类更改为例如添加结果 typedef,因此我必须能够在编译时获得返回类型。
c++ - 使用 std::result_of 的意外 SFINAE 失败
在 c++14 中,如果表达式格式不正确*,则 std::result_of 应该导致 SFINAE。相反,我在下面的最后一个案例中得到了一个编译错误(“二进制表达式的无效操作数”)(即让编译器推断 std::plus<> 的类型)。前三个案例按预期工作。代码和结果如下所示。
输出:
任何关于我做错了什么的指示将不胜感激!
谢谢。
- 来自cppreference.com。我认为相关的标准参考是 20.10.7.6,对最后一个表条目的评论。
c++ - 如何使用 result_of 而不是 decltype?
在这个答案中,我创建了一个类型特征:
这工作得很好,但我最初打算使用result_of
,现在我不知道该怎么做,这让我很恼火。
我试图用这样的东西替换上面的行:
但我得到一个编译器错误,如下所示:
错误 C2275:“T”:非法使用此类型作为表达式
注意:请参阅“T”声明
错误 C2974:“std::result_of”:“_Fty”的模板参数无效,预期类型
我已经尝试了其他几个输入result_of
但没有成功,谁能帮我理解result_of
这里期待什么论点?
c++ - std::result_of doesn't compile
I'm trying to use std::result_of
to determine the return type of a callable object:
Somewhere else in the code:
This code doesn't compile for some reason. I will appreciate if someone would tell me why.
c++ - Getting the Return Type of a Templatized Object's Method
Say that I have:
And I implement a Foo
: Foo<int> bar
Now I want to get the return type of bar.func()
. I've been trying to force result_of
to work with me but to no avail.
What I'd really like is to just be able to do result_of_t<foo.func>
and be done with it but I imagine it's significantly more difficult? How should I go about getting this return type?
EDIT:
I was hoping to accomplish this without without respect to how bar
was declared. That is to say, I want to just be able to pass bar.func
into result_of
or similar and gt out the return type.