2014-02-11 39 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