Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to work around 10 limit for make_shared in Visual Studio

While utilizing new features of C++10 on some old code, I ended up with the problem that I cannot call make_shared that takes 12 parameters. I remember Microsoft's STL talking how they use emulation for make_shared and that 10 is maximum. Obviously refactoring code just for this is out of the question, so basically my question is - Is there a way to get more than 10 params to make_shared in VS 2010.

like image 356
NoSenseEtAl Avatar asked Dec 15 '22 15:12

NoSenseEtAl


1 Answers

make_shared<foobar>(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12);

can be replaced with

shared_ptr<foobar>(new foobar(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12));

In C++11, std::make_shared is actually a performance optimization over creating an object using the second method, because it only performs one memory allocation instead of two, but once you get past 10 variables, you don't have much choice about which to use.

like image 71
Drew Avatar answered Dec 28 '22 22:12

Drew