我试图修复了一个库(entityx)目前未在Windows上使用VS 2013年它在Linux上编译罚款与海湾合作委员会,并在Windows上使用MinGW编译。解决方法VS 2013 SFINAE未尽
看来问题是SFINAE - 我猜VS 2013不正确地忽略模板替换故障。
有微软连接,here这个问题的报告。
之前,我潜入entityx,有问题(在Microsoft连接从报告中获得)的样本:
#include <vector>
#include <future>
using namespace std;
typedef int async_io_op;
struct Foo
{
//! Invoke the specified callable when the supplied operation completes
template<class R> inline std::pair < std::vector < future <R>> , std::vector <async_io_op>> call(const std::vector<async_io_op> &ops, const std::vector < std::function < R() >> &callables);
//! Invoke the specified callable when the supplied operation completes
template<class R> std::pair < std::vector < future <R>> , std::vector <async_io_op>> call(const std::vector < std::function < R() >> &callables) { return call(std::vector<async_io_op>(), callables); }
//! Invoke the specified callable when the supplied operation completes
template<class R> inline std::pair<future<R>, async_io_op> call(const async_io_op &req, std::function<R()> callback);
//! Invoke the specified callable when the supplied operation completes
template<class C, class... Args> inline std::pair<future<typename std::result_of<C(Args...)>::type>, async_io_op> call(const async_io_op &req, C callback, Args... args);
};
int main(void)
{
Foo foo;
std::vector<async_io_op> ops;
std::vector < std::function < int() >> callables;
foo.call(ops, std::move(callables));
return 0;
}
我得到试图编译这个时候出现以下错误:
错误C2064:术语不评估为取0参数的函数
c:\ program files(x86)\ microsoft visual studio 12.0 \ vc \ include \ xrefwrap 58
显然,我们可以使用std::enable_if
来解决此问题。但是,我无法弄清楚如何。
有谁知道我怎么能解决这个编译错误?
编辑:全输出VS 2013:
1>------ Build started: Project: VS2013_SFINAE_Failure, Configuration: Debug Win32 ------
1> test_case.cpp
1>c:\program files (x86)\microsoft visual studio 12.0\vc\include\xrefwrap(58): error C2064: term does not evaluate to a function taking 0 arguments
1> c:\program files (x86)\microsoft visual studio 12.0\vc\include\xrefwrap(118) : see reference to class template instantiation 'std::_Result_of<_Fty,>' being compiled
1> with
1> [
1> _Fty=std::vector<std::function<int (void)>,std::allocator<std::function<int (void)>>>
1> ]
1> c:\users\jarrett\downloads\vs2013_sfinae_failure\vs2013_sfinae_failure\test_case.cpp(25) : see reference to class template instantiation 'std::result_of<std::vector<std::function<int (void)>,std::allocator<_Ty>> (void)>' being compiled
1> with
1> [
1> _Ty=std::function<int (void)>
1> ]
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
我记得当我与这样的东西工作。 我希望你有很多压力球和纸巾。 – 2014-02-11 03:15:47
你能发布整个错误吗?后续的行通常提供额外的信息。 –
@ R.MartinhoFernandes完成。 – Jarrett