C++0x: how to get variadic template parameters without reference?

Posted by Sydius on Stack Overflow See other posts from Stack Overflow or by Sydius
Published on 2011-02-26T06:13:24Z Indexed on 2011/02/26 7:25 UTC
Read the original article Hit count: 135

Given the following contrived (and yes, terrible) example:

template<typename... Args>
void something(Args... args)
{
    std::tuple<Args...> tuple; // not initializing for sake of example
    std::get<0>(tuple) = 5;
}

It works if you call it like so:

int x = 10;
something<int>(x);

However, it does not work if you call it like this:

int x = 10;
something<int&>(x);

Because of the assignment to 5. Assuming that I cannot, for whatever reason, initialize the tuple when it is defined, how might I get this to work when specifying the type as a reference?

Specifically, I would like the tuple to be std::tuple<int> even when Args... is int&.

© Stack Overflow or respective owner

Related posts about c++

Related posts about templates