Решил я поиграться с fold expression в c++1z, сделал шаблонный оператор, который объединяет два кортежа
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);
}
template <class... Args1, class... Args2>
constexpr decltype(auto) operator+(::std::tuple<Args1...> &&tup1,
::std::tuple<Args2...> &&tup2) {
return ::std::tuple_cat(tup1, tup2);
}
И вроде бы отлично работает для двух параметров
template <class Arg1, class Arg2>
constexpr decltype(auto) concat_test(Arg1 &&arg1, Arg2 &&arg2) {
return arg1 + arg2;
}
Но вот беда, если пытаюсь соединить таким образом n кортежей, то gcc скомпилирует это все нормально, а clang на меня ругается
constexpr decltype(auto) multiple_concat() {
return ::std::make_tuple();
}
template <class... Args>
constexpr decltype(auto) multiple_concat(Args &&... args) {
return (args + ...);
}
И вот я думаю, толь clang мой не едет, толь я - тупой
Выхлоп clang'а:
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<int, int> &, std::__1::tuple<int, char> &>' requested here multiple_concat(tup1, tup2);
note: 'operator+' should be declared prior to the call site constexpr decltype(auto) operator+(const ::std::tuple<Args1...> &tup1,
1 error generated.
P.S: Не работает ни с 4.0.1, ни с 5.0 (branches/release_50 309888), ни с 6.0 (trunk 310399) версией