Emplace_back and the frustration of VC ++

I am using Visual Studio 2012, trying this with both the default compiler and the Nov CTP compiler, and the following shows that my problem is:

struct doesCompile { int mA, mB, mC, mD, mE; doesCompile(int a, int b, int c, int d, int e) : mA(a), mB(b), mC(c), mD(d), mE(e) { } }; struct doesNotCompile { int mA, mB, mC, mD, mE, mF; doesNotCompile(int a, int b, int c, int d, int e, int f) : mA(a), mB(b), mC(c), mD(d), mE(e), mF(f) { } }; int _tmain(int argc, _TCHAR* argv[]) { std::vector<doesCompile> goodVec; goodVec.emplace_back(1, 2, 3, 4, 5); std::vector<doesNotCompile> badVec; badVec.emplace_back(1, 2, 3, 4, 5, 6); // error C2660: 'std::vector<_Ty>::emplace_back' : function does not take 6 arguments return 0; } 

Why does emplace_back seem to be limited to a maximum of 5 arguments? They even say in http://blogs.msdn.com/b/vcblog/archive/2011/09/12/10209291.aspx that this will require a harsh amount of arguments.

Is there any way around this using VS2012?

+7
c ++ vector c ++ 11 visual-c ++ stl
source share
2 answers

The VS2012 November CTP compiler supports variable templates, but their standard library has not yet been updated in this version. Must be installed in VS2013RC. An update is highly recommended since even the November CTP contains many errors. If this is not possible, use the macro specified by Conrad Rudolph.

+4
source share

This is a limitation caused by the previous Visual C ++ compiler architecture. Future versions of VC ++ will raise this limitation and allow the use of true variable templates.

At the moment, you can statically increase the maximum limit of faux variadic templates by adding the following before including in your code:

 #define _VARIADIC_MAX 6 

This will set the limit to 6 instead of 5 (the maximum possible value is 10) by reducing the compilation speed.

+7
source share

All Articles