简体   繁体   English

在Visual Studio 2012中不使用可变参数模板的情况下,emplace_back()如何工作?

[英]How emplace_back() works without variadic templates in Visual Studio 2012?

Using Visual Studio 2012 with toolset v110 I can use container's emplace_back() function but can't use std::forward with variadic templates - accepting any amount of arguments. 将Visual Studio 2012与工具集v110结合使用时,我可以使用容器的emplace_back()函数,但不能将std::forward与可变参数模板一起使用-接受任意数量的参数。 How is it done? 怎么做?

As example, make_unique<>() won't compile: 例如, make_unique<>()将不会编译:

template<typename T, typename... Ts>
std::unique_ptr<T> make_unique(Ts&&... params)
{
  return std::unique_ptr<T>(new T(std::forward<Ts>(params)...));
}

According to this official list of supported C++11 language features, the variadic templates are not supported in VS 2012. 根据受支持的C ++ 11语言功能的正式列表 ,VS 2012不支持可变参数模板。

And there is the following note on the same page below: 在下面的同一页上还有以下注意事项:

Variadics: Visual C++ in Visual Studio 2012 had a scheme for simulating variadic templates. 可变参数: Visual Studio 2012中的Visual C ++具有模拟可变参数模板的方案。 In Visual C++ in Visual Studio 2013, the simulations are gone and variadics are fully implemented. 在Visual Studio 2013中的Visual C ++中,模拟消失了,并且变量实现已完全实现。 If your code relies on the old simulated variadics behavior, you have to fix it. 如果您的代码依赖于旧的模拟杂色行为,则必须对其进行修复。 However, the switch to real variadic templates has improved compile times and reduced compiler memory consumption. 但是,切换到实际的可变参数模板可以缩短编译时间并减少编译器内存消耗。

And on another page there is this note telling how the simulation have been done: 另一页上有此注释,告诉您如何完成模拟:

Over the years, we've simulated variadic templates with two different systems of "faux variadic" preprocessor macros - the first system involved repeatedly including subheaders, while the second system (more elegant, as far as crawling horrors go) eliminated the subheaders and replaced them with big backslash-continued macros that were stamped out by other macros. 多年以来,我们已经使用两个不同的“人造可变参量”预处理器宏系统模拟可变参量模板-第一个系统反复包含副标题,而第二个系统(就爬行恐怖而言更优雅)消除了副标题并替换了它们带有大的反斜杠连续的宏,这些宏被其他宏淘汰。 Functions that were supposed to be true variadic, like make_shared(args...), were actually implemented with overloads: make_shared(), make_shared(arg0), make_shared(arg0, arg1), etc. Classes that were supposed to be true variadic, like tuple, were actually implemented with default template arguments and partial specializations. 假定为真可变参数的函数,例如make_shared(args ...),实际上是通过重载实现的:make_shared(),make_shared(arg0),make_shared(arg0,arg1)等。应该为真可变参数的类像元组一样,实际上是通过默认模板参数和部分专业化实现的。 This allowed us to bring you make_shared/tuple/etc. 这使我们能够带给您make_shared / tuple / etc。 years ago, but it had lots of problems. 年前,但是有很多问题。 The macros were very difficult to maintain, making it hard to find and fix bugs in the affected code. 宏很难维护,因此很难找到并修复受影响代码中的错误。 Spamming out so many overloads and specializations increased compile times, and degraded Intellisense. 散布大量的重载和专业知识会增加编译时间,并降低Intellisense。 Finally, there was the infinity problem. 最后,存在无限性问题。 We originally stamped out overloads/specializations for 0 to 10 arguments inclusive, but as the amount of variadic machinery increased from TR1 through C++0x's evolution to C++11's final form, we lowered infinity from 10 to 5 in Visual C++ 2012 in order to improve compile times for most users (we provided a way to request the old limit of 10 through a macro, _VARIADIC_MAX). 最初,我们消除了0到10个参数(包括0到10个参数)的重载/专业化,但是随着可变参数机制的数量从TR1到C ++ 0x的演变到C ++ 11的最终形式,我们在Visual C ++ 2012中将无穷大从10降低到5。为了缩短大多数用户的编译时间(我们提供了一种通过_VARIADIC_MAX宏请求旧限制10的方法)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM