That should be obvious, is there some short syntax to get a subtuple?
Something like that:
std::tuple<std::string, double, int> myTuple;
std::tuple<std::string, int> subTuple = std::get<std::string, int>(myTuple);
You need to make your own template function, this below implementation requires C++14 (because it requires std::get<T>, you can implement it in C++11 yourself):
template<typename... R, typename ...Args>
std::tuple<R...> sub_tuple(const std::tuple<Args...>& original) {
return std::make_tuple(std::get<R>(original)...);
}
int main()
{
std::tuple<std::string, double, int> myTuple = std::make_tuple("Hello", 1201.0, 51);
std::tuple<std::string, int> subTuple = sub_tuple<std::string, int>(myTuple);
std::cout << std::get<0>(subTuple) << " " << std::get<1>(subTuple);
}
Note: this will create a copy for each element in the original tuple
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With