[英]How to create a std::tuple which containins members from a vector specified by a tuple of indexes?
我有一些值的std :: vector,例如std::vector<std::string> v = {"a", "b", "c", "d", "e"};
然后我有一个从参数包创建的数字元组(即它可以有任意大小)。 如何创建向量成员的元组(此处为std :: string的元组),将其索引元组用作向量的索引? 例如,如果索引的元组的值为auto result = std::make_tuple("a", "d", "b");
,则结果应与我写的auto result = std::make_tuple("a", "d", "b");
。 我正在使用Visual Studio 2015。
编辑:澄清索引的元组
遵循这些思路,也许是:
template <typename C, typename Tuple, int... Is>
auto project_impl(const C& c, const Tuple& indices,
std::integer_sequence<int, Is...>) {
return std::make_tuple(c[std::get<Is>(indices)]...);
}
template <typename C, typename Tuple>
auto project(const C& c, const Tuple& indices) {
return project_impl(c, indices,
std::make_integer_sequence<int, std::tuple_size<Tuple>::value>());
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.