我正在尝试将向量元组更改为元组向量(反之亦然)。我无法调用该tuple_transpose
函数。当我用一个参数调用它时,我得到一个no matching function call
错误:
prog.cpp:在函数“int main()”中:
prog.cpp:44:24:错误:没有匹配函数调用“tuple_transpose(std::tuple >, std::vector > >&)”<br> prog.cpp:44:24: 注意: 候选是:
prog.cpp:30:6: 注意: 模板类型名 transpose::type tuple_transpose(std::tuple >...>&, seq)
prog.cpp:30: 6:注意:模板参数推导/替换失败:
prog.cpp:44:24:注意:候选人需要 2 个参数,提供 1 个
prog.cpp:36:6:注意:模板类型名 transpose::type tuple_transpose(std::tuple >...>&)
prog.cpp:36:6: 注意:模板参数推导/替换失败:
prog.cpp: 替换'模板类型名转置::type tuple_transpose(std::tuple >...>& ) [with T = {int, bool}]':
prog.cpp:44:24: 从这里需要
prog.cpp:36:6: 错误: 'struct transpose >, std::vector > >&>' 中没有名为'type'的类型</sub>
#include <vector>
#include <tuple>
#include <type_traits>
template <typename... T>
struct transpose {};
template <typename... T>
struct transpose<std::tuple<std::vector<T>...>>
{
using type = std::vector<std::tuple<T...>>;
};
template <typename... T>
struct transpose<std::vector<std::tuple<T...>>>
{
using type = std::tuple<std::vector<T>...>;
};
// Indicies from Andy Prowl's answer
template <int... Is>
struct seq {};
template <int N, int... Is>
struct gen_seq : gen_seq<N - 1, N - 1, Is...> {};
template <int... Is>
struct gen_seq<0, Is...> : seq<Is...> {};
template <typename... T, int... Is>
auto tuple_transpose(std::tuple<std::vector<T>...>& var, seq<Is...>) -> typename transpose<decltype(var)>::type
{
return { std::make_tuple(std::get<Is>(var)...) };
}
template <typename... T>
auto tuple_transpose(std::tuple<std::vector<T>...>& var) -> typename transpose<decltype(var)>::type
{
return tuple_transpose(var, gen_seq<sizeof...(T)>{});
}
int main()
{
std::tuple<std::vector<int>, std::vector<bool>> var;
tuple_transpose(var); // error
...
}
这是一个包含错误的演示:http: //ideone.com/7AWiQQ#view_edit_box
我做错了什么,我该如何解决?谢谢。