#include <iostream>
#include <tuple>
#include <utility>
template <typename... T>
decltype(auto) getParameterPackVals(T&&... Args) noexcept {
return std::get<1>(std::forward_as_tuple(std::forward<T>(Args)...));
}
int main() {
std::cout << getParameterPackVals(2, 1.0, 2.0, 3.0, 4.0, 5.0) << std::endl;
//print(1.0, "Hello", "This", "is", "An", "Honour");
return 0;
}
This is my current code that works, with using 1
as a place holder for the variable. Although when I replace 1
with a variable (I tried both size_t
and int
in the arguments for getParameterPackVals
) it does not work.
template <size_t V, typename... T>
decltype(auto) getParameterPackVals(V n, T&&... Args){
return std::get<n>(std::forward_as_tuple(std::forward<T>(Args)...));
}
Is this a gap in my understanding of how the std::get
function works? Is there a way to make this work as is or would I need to write an entirely new function?