[英]C++14 variadic template argument inference in clang and gcc
我正在使用clang 3.5.0和gcc版本4.9.2(都启用了C ++ 14选项,尽管使用尾随返回类型可以在C ++ 11中完成)。
以下代码在g ++中而不是在clang ++中编译。 我的问题是“哪个是对的?”
#include <iostream>
#include <tuple>
#include <functional>
using namespace std;
template<typename OP, typename F1, typename... Fs>
struct symop {
OP op;
tuple<F1,Fs...> fs;
symop(const OP &oopp, const F1 &f1, const Fs &...ffss)
: op(oopp), fs(f1,ffss...) {}
};
template<typename OP, typename... Fs>
auto baz(const symop<OP,Fs...> &so) {
return so.op(get<0>(so.fs),get<1>(so.fs));
}
/* // this version compiles on both compilers
template<typename OP, typename F1, typename... Fs>
auto baz(const symop<OP,F1,Fs...> &so) {
return so.op(get<0>(so.fs),get<1>(so.fs));
}
*/
int main() {
symop<plus<int>,int,int> so{plus<int>{},3,4};
cout << baz(so) << endl;
}
lang报告
q.cpp:29:10: error: no matching function for call to 'baz'
cout << baz(so) << endl;
^~~
q.cpp:16:6: note: candidate template ignored: couldn't infer template argument
'OP'
auto baz(const symop<OP,Fs...> &so) {
^
您应该了解Clang仍处于试验阶段(即使已“广泛”使用),并且基本上是基于GCC构建的(尽管它有一些重大更改),并且您可以确定在GCC中编译的所有内容(使用C ++代码)应该使用Clang编译,否则,这是Clang错误。
GCC有时间证明它很强大。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.