MSVC++ doesn't yet support variadic templates, so its standard library "fakes" these for classes like std::tuple
through use of macros. I recently tried compiling one of my projects with the VC11 beta, and got this to show for it:
MSVC++还不支持可变模板,因此它的标准库“冒牌”用于类std::tuple使用宏。我最近试着用VC11测试版来编译我的一个项目,并得到了这个结果:
gtest\gtest.h(9735): error C2977: 'std::tuple' : too many template arguments
c:\program files (x86)\microsoft visual studio 11.0\vc\include\utility(72) : see declaration of 'std::tuple'
gtest\gtest.h(9743): error C2977: 'std::tuple' : too many template arguments
gtest\gtest.h(14568): error C2977: 'std::tuple' : too many template arguments
gtest\gtest.h(14568): error C3203: 'tuple' : unspecialized class template can't be used as a template argument for template parameter 'T', expected a real type
gtest\gtest.h(14568): error C2955: 'std::tuple' : use of class template requires template argument list
gtest\gtest.h(14568): error C2955: 'testing::internal::ParamGeneratorInterface' : use of class template requires template argument list
c:\users\billy\documents\visual studio 2010\projects\instalog\logtests\gtest\gtest.h(10076) : see declaration of 'testing::internal::ParamGeneratorInterface'
gtest\gtest.h(14570): error C2977: 'std::tuple' : too many template arguments
gtest\gtest.h(14581): error C3203: 'tuple' : unspecialized class template can't be used as a template argument for template parameter 'T', expected a real type
gtest\gtest.h(14581): error C2955: 'std::tuple' : use of class template requires template argument list
gtest\gtest.h(14586): error C3203: 'tuple' : unspecialized class template can't be used as a template argument for template parameter 'T', expected a real type
gtest\gtest.h(14586): error C2955: 'std::tuple' : use of class template requires template argument list
gtest\gtest.h(14593): error C3203: 'tuple' : unspecialized class template can't be used as a template argument for template parameter 'T', expected a real type
c:\users\billy\documents\visual studio 2010\projects\instalog\logtests\gtest\gtest.h(14593) : see reference to class template instantiation 'testing::internal::CartesianProductGenerator9<T1,T2,T3,T4,T5,T6,T7,T8,T9>::Iterator' being compiled
gtest\gtest.h(14593): error C2955: 'std::tuple' : use of class template requires template argument list
gtest\gtest.h(14593): error C2955: 'testing::internal::ParamIteratorInterface' : use of class template requires template argument list
c:\users\billy\documents\visual studio 2010\projects\instalog\logtests\gtest\gtest.h(10003) : see declaration of 'testing::internal::ParamIteratorInterface'
gtest\gtest.h(14595): error C3203: 'tuple' : unspecialized class template can't be used as a template argument for template parameter 'T', expected a real type
gtest\gtest.h(14595): error C2955: 'std::tuple' : use of class template requires template argument list
gtest\gtest.h(14628): error C3203: 'tuple' : unspecialized class template can't be used as a template argument for template parameter 'T', expected a real type
gtest\gtest.h(14628): error C2955: 'std::tuple' : use of class template requires template argument list
gtest\gtest.h(14670): error C3203: 'tuple' : unspecialized class template can't be used as a template argument for template parameter 'T', expected a real type
gtest\gtest.h(14670): error C2955: 'std::tuple' : use of class template requires template argument list
gtest\gtest.h(14674): error C3203: 'tuple' : unspecialized class template can't be used as a template argument for template parameter 'T', expected a real type
gtest\gtest.h(14674): error C2955: 'std::tuple' : use of class template requires template argument list
gtest\gtest.h(14755): error C3203: 'tuple' : unspecialized class template can't be used as a template argument for template parameter 'T', expected a real type
gtest\gtest.h(14755): error C2955: 'std::tuple' : use of class template requires template argument list
gtest\gtest.h(14807): error C2977: 'std::tuple' : too many template arguments
gtest\gtest.h(14807): error C3203: 'tuple' : unspecialized class template can't be used as a template argument for template parameter 'T', expected a real type
gtest\gtest.h(14807): error C2955: 'std::tuple' : use of class template requires template argument list
gtest\gtest.h(14807): error C2955: 'testing::internal::ParamGeneratorInterface' : use of class template requires template argument list
gtest\gtest.h(14809): error C2977: 'std::tuple' : too many template arguments
gtest\gtest.h(14821): error C3203: 'tuple' : unspecialized class template can't be used as a template argument for template parameter 'T', expected a real type
gtest\gtest.h(14821): error C2955: 'std::tuple' : use of class template requires template argument list
gtest\gtest.h(14826): error C3203: 'tuple' : unspecialized class template can't be used as a template argument for template parameter 'T', expected a real type
gtest\gtest.h(14826): error C2955: 'std::tuple' : use of class template requires template argument list
gtest\gtest.h(14833): error C3203: 'tuple' : unspecialized class template can't be used as a template argument for template parameter 'T', expected a real type
c:\users\billy\documents\visual studio 2010\projects\instalog\logtests\gtest\gtest.h(14833) : see reference to class template instantiation 'testing::internal::CartesianProductGenerator10<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10>::Iterator' being compiled
gtest\gtest.h(14833): error C2955: 'std::tuple' : use of class template requires template argument list
gtest\gtest.h(14833): error C2955: 'testing::internal::ParamIteratorInterface' : use of class template requires template argument list
gtest\gtest.h(14835): error C3203: 'tuple' : unspecialized class template can't be used as a template argument for template parameter 'T', expected a real type
gtest\gtest.h(14835): error C2955: 'std::tuple' : use of class template requires template argument list
gtest\gtest.h(14871): error C3203: 'tuple' : unspecialized class template can't be used as a template argument for template parameter 'T', expected a real type
gtest\gtest.h(14871): error C2955: 'std::tuple' : use of class template requires template argument list
gtest\gtest.h(14917): error C3203: 'tuple' : unspecialized class template can't be used as a template argument for template parameter 'T', expected a real type
gtest\gtest.h(14917): error C2955: 'std::tuple' : use of class template requires template argument list
gtest\gtest.h(14921): error C3203: 'tuple' : unspecialized class template can't be used as a template argument for template parameter 'T', expected a real type
gtest\gtest.h(14921): error C2955: 'std::tuple' : use of class template requires template argument list
gtest\gtest.h(15007): error C3203: 'tuple' : unspecialized class template can't be used as a template argument for template parameter 'T', expected a real type
gtest\gtest.h(15007): error C2955: 'std::tuple' : use of class template requires template argument list
gtest\gtest.h(15289): error C2977: 'std::tuple' : too many template arguments
gtest\gtest.h(15289): error C3203: 'tuple' : unspecialized class template can't be used as a template argument for template parameter 'T', expected a real type
gtest\gtest.h(15289): error C2955: 'std::tuple' : use of class template requires template argument list
gtest\gtest.h(15333): error C2977: 'std::tuple' : too many template arguments
gtest\gtest.h(15333): error C3203: 'tuple' : unspecialized class template can't be used as a template argument for template parameter 'T', expected a real type
gtest\gtest.h(15333): error C2955: 'std::tuple' : use of class template requires template argument list
I've heard there's a #define
that can be set somewhere to change this setting, but I (for the life of me) can't remember what it is. What is it?
我听说有一个#define可以设置在某处来改变这个设置,但是我(对于我的生活)不记得它是什么。它是什么?
3 个解决方案
#1
6
You can define _VARIADIC_MAX
to any value between 5 and 10, inclusive.
您可以将_vari_max定义为5到10之间的任何值,包括。
This, and many other interesting facts about Visual C++ 11, can be found in the MSDN article, "C++11 Features (Modern C++)." This particular macro is discussed in the section entitled "Faux variadics."
关于Visual c++ 11的许多其他有趣的事实,可以在MSDN的文章中找到,“c++ 11特性(现代c++)”。这个特别的宏在标题为“人造变量”的章节中进行了讨论。
#2
2
Interesting quote from blogs.msdn.com article:
有趣的引用来自blogs.msdn.com的文章:
Faux variadics: We've developed a new scheme for simulating variadic templates. Previously in VC9 SP1 and VC10, we repeatedly included subheaders with macros defined differently each time, in order to stamp out overloads for 0, 1, 2, 3, etc. arguments. (For example, included the internal subheader repeatedly, in order to stamp out make_shared(args, args, args).) In VC11, the subheaders are gone. Now we define variadic templates themselves as macros (with lots of backslash-continuations), then expand them with master macros. This internal implementation change has some user-visible effects. First, the code is more maintainable, easier to use (adding subheaders was a fair amount of work), and slightly less hideously unreadable. This is what allowed us to easily implement variadic emplacement, and should make it easier to squash bugs in the future. Second, it's harder to step into with the debugger (sorry!). Third, pair's pair(piecewise_construct_t, tuple, tuple) constructor had "interesting" effects. This requires N^2 overloads (if we support up to 10-tuples, that means 121 overloads, since empty tuples count here too). We initially observed that this (spamming out so many pair-tuple overloads, plus all of the emplacement overloads) consumed a massive amount of memory during compilation, so as a workaround we reduced infinity. In VC9 SP1 and VC10, infinity was 10 (i.e. "variadic" templates supported 0 to 10 arguments inclusive). In the VC11 Developer Preview, infinity is 5 by default. This got our compiler memory consumption back to what it was in VC10. If you need more arguments (e.g. you had code compiling with VC9 SP1 or VC10 that used 6-tuples), there's an escape hatch. You can define _VARIADIC_MAX project-wide between 5 and 10 inclusive (it defaults to 5). Increasing it will make the compiler consume more memory, and may require you to use the /Zm option to reserve more space for PCHes.
我们开发了一种模拟可变模板的新方案。在之前的VC9 SP1和VC10中,我们重复地包含了每一次以不同的方式定义宏的subheader,以便在0、1、2、3等参数中消除重载。(例如,为了消除make_shared(args, args, args),将内部子头重复包含在内。)在VC11中,subheaders消失了。现在,我们将可变模板本身定义为宏(有大量的反斜杠延续),然后使用主宏展开它们。这种内部实现更改具有一些用户可见的效果。首先,代码更易于维护,更易于使用(添加子标题是相当多的工作),并且稍微不那么令人难以理解。这使得我们能够很容易地实现可变的放置,并且应该更容易在将来消除错误。其次,调试器很难进入(对不起!)第三,成对的构造函数具有“有趣”的效果。这需要N ^ 2过载(如果我们支持10-tuples,这意味着121年过载,因为这里空元组数)。我们最初观察到,这(发送大量的pair-tuple重载,加上所有的emplacement重载)在编译过程中消耗了大量的内存,所以作为一个解决方案,我们减少了无穷大。在VC9 SP1和VC10中,无穷大是10。“可变”模板支持0到10个参数。在VC11开发者预览版中,“无限”默认为5。这使我们的编译器内存消耗回到了VC10中。如果您需要更多的参数(例如,您使用了使用6元组的VC9 SP1或VC10进行代码编译),就会有一个逃生出口。您可以定义_variext_max项目范围在5到10之间(它默认为5)。增加它将使编译器消耗更多的内存,并且可能要求您使用/Zm选项为PCHes预留更多的空间。
#3
1
This is fixed in revision 675. See https://code.google.com/p/googletest/source/detail?r=675
这是修正版675。参见https://code.google.com/p/googletest/source/detail?r=675
#1
6
You can define _VARIADIC_MAX
to any value between 5 and 10, inclusive.
您可以将_vari_max定义为5到10之间的任何值,包括。
This, and many other interesting facts about Visual C++ 11, can be found in the MSDN article, "C++11 Features (Modern C++)." This particular macro is discussed in the section entitled "Faux variadics."
关于Visual c++ 11的许多其他有趣的事实,可以在MSDN的文章中找到,“c++ 11特性(现代c++)”。这个特别的宏在标题为“人造变量”的章节中进行了讨论。
#2
2
Interesting quote from blogs.msdn.com article:
有趣的引用来自blogs.msdn.com的文章:
Faux variadics: We've developed a new scheme for simulating variadic templates. Previously in VC9 SP1 and VC10, we repeatedly included subheaders with macros defined differently each time, in order to stamp out overloads for 0, 1, 2, 3, etc. arguments. (For example, included the internal subheader repeatedly, in order to stamp out make_shared(args, args, args).) In VC11, the subheaders are gone. Now we define variadic templates themselves as macros (with lots of backslash-continuations), then expand them with master macros. This internal implementation change has some user-visible effects. First, the code is more maintainable, easier to use (adding subheaders was a fair amount of work), and slightly less hideously unreadable. This is what allowed us to easily implement variadic emplacement, and should make it easier to squash bugs in the future. Second, it's harder to step into with the debugger (sorry!). Third, pair's pair(piecewise_construct_t, tuple, tuple) constructor had "interesting" effects. This requires N^2 overloads (if we support up to 10-tuples, that means 121 overloads, since empty tuples count here too). We initially observed that this (spamming out so many pair-tuple overloads, plus all of the emplacement overloads) consumed a massive amount of memory during compilation, so as a workaround we reduced infinity. In VC9 SP1 and VC10, infinity was 10 (i.e. "variadic" templates supported 0 to 10 arguments inclusive). In the VC11 Developer Preview, infinity is 5 by default. This got our compiler memory consumption back to what it was in VC10. If you need more arguments (e.g. you had code compiling with VC9 SP1 or VC10 that used 6-tuples), there's an escape hatch. You can define _VARIADIC_MAX project-wide between 5 and 10 inclusive (it defaults to 5). Increasing it will make the compiler consume more memory, and may require you to use the /Zm option to reserve more space for PCHes.
我们开发了一种模拟可变模板的新方案。在之前的VC9 SP1和VC10中,我们重复地包含了每一次以不同的方式定义宏的subheader,以便在0、1、2、3等参数中消除重载。(例如,为了消除make_shared(args, args, args),将内部子头重复包含在内。)在VC11中,subheaders消失了。现在,我们将可变模板本身定义为宏(有大量的反斜杠延续),然后使用主宏展开它们。这种内部实现更改具有一些用户可见的效果。首先,代码更易于维护,更易于使用(添加子标题是相当多的工作),并且稍微不那么令人难以理解。这使得我们能够很容易地实现可变的放置,并且应该更容易在将来消除错误。其次,调试器很难进入(对不起!)第三,成对的构造函数具有“有趣”的效果。这需要N ^ 2过载(如果我们支持10-tuples,这意味着121年过载,因为这里空元组数)。我们最初观察到,这(发送大量的pair-tuple重载,加上所有的emplacement重载)在编译过程中消耗了大量的内存,所以作为一个解决方案,我们减少了无穷大。在VC9 SP1和VC10中,无穷大是10。“可变”模板支持0到10个参数。在VC11开发者预览版中,“无限”默认为5。这使我们的编译器内存消耗回到了VC10中。如果您需要更多的参数(例如,您使用了使用6元组的VC9 SP1或VC10进行代码编译),就会有一个逃生出口。您可以定义_variext_max项目范围在5到10之间(它默认为5)。增加它将使编译器消耗更多的内存,并且可能要求您使用/Zm选项为PCHes预留更多的空间。
#3
1
This is fixed in revision 675. See https://code.google.com/p/googletest/source/detail?r=675
这是修正版675。参见https://code.google.com/p/googletest/source/detail?r=675