这是我用来连接元组的二元运算符:
template <class... Args1, class... Args2>
constexpr decltype(auto) operator+(const std::tuple<Args1...> &tup1,
const std::tuple<Args2...> &tup2) {
return std::tuple_cat(tup1, tup2);
}
它在带有两个元组的两个编译器(gcc、clang)上都能完美运行:
template <class Arg1, class Arg2>
constexpr decltype(auto) concat_test(Arg1 &&arg1, Arg2 &&arg2) {
return arg1 + arg2;
}
但是当我尝试在折叠表达式中使用它时,如下所示:
template <class... Args>
constexpr decltype(auto) multiple_concat(Args &&... args) {
return (args + ...);
}
gcc 7.1.1 编译它没有任何错误,不像 clang 5.0,它会产生错误输出:
error: call to function 'operator+' that is neither visible in the template definition nor found by argument-dependent lookup
return (args + ...);
note: in instantiation of function template specialization 'multiple_concat < std::__1::tuple &, std::__1::tuple &>' requested here
multiple_concat(tup1, tup2);
note: 'operator+' should be declared prior to the call site
constexpr decltype(auto) operator+(const std::tuple &tup1, const std::tuple &tup2)
这段代码格式不正确吗?clang 到底在说什么?
最佳答案
关于c++ - Clang 在折叠表达式中找不到模板二元运算符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45569698/