Visual Studio 2013 C ++ lambda capture parameter pack

Currently, Visual Studio 2013 2 update does not support full C ++ 11, one of these functions is the collection of parameter packages in lambda. Is there an easy way around this, or will I have to resort to the groove of the visual studio and use a compatible compiler like mingw / g ++?

The following code demonstrates a simple example of what I had in mind:

template <typename ... Args> std::thread init_threaded(SomeObject sample, Args && ... args) { auto func = [=]() { sample->init(args...); }; return std::thread(func); } 

This works fine in recent versions of xcode (5.1.1) and latest versions of g ++ (using 4.9.0) under Linux, however in Visual Studio 2013 2 update it gives an error:

 error C2536: 'init_threaded::<lambda_3a984affe0045c597607c0ec0a116b46>::init_threaded::<lambda_3a984affe0045c597607c0ec0a116b46>::<args_0>' : cannot specify explicit initializer for arrays 

Edit: This error occurs when the init function has different types. The following example does not compile.

 #include <thread> struct foo { void init(int arg1, std::string arg2) {} }; template <typename ... Args> std::thread init_threaded(foo *sample, Args && ... args) { auto func = [=]() { sample->init(args...); }; return std::thread(func); } int main() { foo f; auto t = init_threaded(&f, 1, "two"); t.join(); } 
+6
source share
1 answer

As discussed in the comment, this is an MSVC compiler error, and there is work. The big ticket is here if someone else is faced with this and wants to know the status.

0
source

Source: https://habr.com/ru/post/970293/


All Articles