2014-02-11 42 views
1

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

我記得當我與這樣的東西工作。 我希望你有很多壓力球和紙巾。 – 2014-02-11 03:15:47

+0

你能發佈整個錯誤嗎?後續的行通常提供額外的信息。 –

+0

@ R.MartinhoFernandes完成。 – Jarrett

回答

3

VS2013,如果你與它decltype + std::declval等同替換std::result_of編譯代碼。所以最後Foo::call()定義修改爲

template<class C, class... Args> 
inline pair<future<decltype(declval<C>()(declval<Args>()...))>, async_io_op> 
call(const async_io_op& req, C callback, Args... args); 

如果我的理解描述here錯誤正確,它涉及到的缺陷,但隨後令人驚訝的是GCC和鐺管理編譯result_of代碼沒有錯誤。

+0

感謝@Praetorian的回覆。我試圖複製和粘貼,但現在我得到一個'錯誤LNK2019:無法解析的外部符號'錯誤。 – Jarrett

+0

@Jarrett那麼,你得到與gcc和鏗鏘還,因爲'美孚:: call'你想從內部主稱尚未確定:) – Praetorian

+0

哦,哈哈。好吧,那麼我想這解決了它:)謝謝@Praetorian。 – Jarrett