我試圖修復了一個庫(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