S
S
sidsukana2016-08-16 10:08:39
C++ / C#
sidsukana, 2016-08-16 10:08:39

How to get an element by index in std::tuple for an unknown number of arguments?

Good afternoon!
Just a straight-forward question:
Why doesn't this construction compile?

template<typename... Args>
MotionState* MotionMaster::CreateStandartState(MotionStateId stateId, Args... args)
{
    std::tuple<Args...> params = std::make_tuple(std::forward<Args>(args)...);
    float x = std::get<0>(params);
    float y = std::get<1>(params);
    float z = std::get<2>(params);
    ...
}

And it gives an error
std::get': no ​​matching overloaded function found
And if you explicitly specify the number of template arguments, then this construction works.
How to unpack parameters sequentially?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
AtomKrieg, 2016-08-16
@AtomKrieg

stackoverflow.com/questions/687490/how-do-i-expand...
Expand into an array and take from there by index.

S
sidsukana, 2016-08-16
@sidsukana

As I understand it, only the same type of parameters can be expanded into an array. I may have different ones.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question