Given,
template<typename T>
void foo(T t)
{
std::tie(/*xxx*/)=t;
auto &[/*yyy*/]=t;
}
int main()
{
foo(forward_as_tuple(1,2,3));
foo(forward_as_tuple(1,2,3,4,5));
}
I want foo()
to unpack the tuple that's passed to itself.
Can decomposition declarations with auto
or std::tie()
, handle the unknown tuple sizes like xxx - yyy up there?
If yes, how?
I'm trying to think of another ways, maybe all elements could be pushed back to a vector of that type, once they're got.
std::vector<T> bar;
size_t baz=std::tuple_size<T>::value; //useless because it can't be used as:
for(int i=0; i<baz; i++)
bar.push_back(std::get<i>(t)); //since i isn't constant
Using vectors was just a bad idea that failed.
How else can it be done?
What I'm trying to, shortly is; I want to get tuple elements in a for loop. That's why I think I need them to be extracted somehow.