【发布时间】:2020-02-11 12:43:49
【问题描述】:
我有一个函数main_func,我通过将参数包/可变参数模板转换为元组来修改它。我修改后,例如:original = tuple<int, float, string>变成modified = tuple<int float>我想将修改后的元组扩展为示例get_type_vector中的另一个函数,以便参数包代表修改后的元组Args = int, float的类型。
template<typename... Args>
void main_func()
{
// Modify the parameter pack (which if im correct can only be done by converting to tuple?)
using original = std::tuple<Args...>;
using modified = // something that alters the types of the original tuple
// This is what i want to accomplish
// somehow expand the tuple type like a parameter pack
auto vec = get_type_vector<modified...>()
}
// Returns a vector of type_info
template<typename... Args>
std::vector<type_info> get_type_vector()
{
return { type_info<Args>()... };
}
是否可以像参数包的类型一样扩展元组类型?我找到了使用 std::apply 等的示例,但这需要您有一个值,而不仅仅是元组的 typedef。
【问题讨论】:
标签: c++ tuples metaprogramming variadic-templates typetraits