Expanding Variadic Template Arguments in Lambda

I'm trying to expand a template + argument parameter list inside a lambda function like this:

1
2
3
4
5
6
7
8
9
10
template <typename Class, typename ...Args>
static void create(Args ...args)
{
// Perform pre-thread creation work.
    std::thread([=]()
                {
                    new Class(args...);
                }).detach();
// Do post-thread start work.
}


But this does not work:
The compiler error is "error: parameter packs not expanded with ‘...’:|"

However, when I do the following:

1
2
3
4
5
6
7
8
9
10
11
template <typename Class, typename ...Args>
static void create(Args ...args)
{
// Pre-thread work. 
   auto tthr = [](Args ...ar) -> void
                {
                    new Class(ar...);
                };
    std::thread(tthr, args...).detach();
// Post-thread work.
}


It works just fine. That shows that lambda threads are able to take variadic arguments...

So here is my question; what is the correct capture clause for capturing the variadic object correctly?
The function is actually a member function of a class, that's why it's static.

Shameless self-bump :x -> I tried everything in the capture clause: "Args...", "...args", "args...", "...", ...
Are you using GCC? It's a known bug: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41933

Compiles just fine with clang++
Yeah I'm using GNU GCC, well I'll use the temporary solution for now; works just as fine, I just like things to be easily readable :P

Thanks.
Topic archived. No new replies allowed.