简体   繁体   English

C ++之前的类模板参数推导17

[英]Class template argument deduction before C++17

I was reading standard library documentation and found out that there were some functions like make_tuple. 我正在阅读标准库文档,发现有一些函数,如make_tuple。 As far as I can see, these functions serve only one purpose: to construct class instance using automatic template argument deduction. 据我所知,这些函数只有一个目的:使用自动模板参数推导构造类实例。 Since CTAD was not available before C++17, associated make-functions had to be called. 由于CTAD在C ++ 17之前不可用,因此必须调用相关的make函数。 This gap was filled only in C++17. 这个差距只在C ++ 17中填补。 Now I wonder, why it couldn't be implemented earlier "the same way" as function template argument deduction? 现在我想知道,为什么它不能像函数模板参数推导那样“以同样的方式”实现? There should be an example that leads to ambiguity that cannot be resolved before C++17, I guess. 应该有一个导致模糊的例子,在C ++ 17之前无法解决,我想。 Can someone confirm it? 有人可以证实吗? What is the difference between functions and classes in that regard? 在这方面,功能和类之间有什么区别? Thank you! 谢谢!

As mentioned in the comments, standardization of a feature takes a long time. 正如评论中所提到的,功能的标准化需要很长时间。
If you wish to know in detail about it, you can check out the section on Standardization from https://isocpp.org , particularly "The life of an ISO proposal: From “cool idea” to “international standard”" . 如果您想详细了解它,可以查看https://isocpp.org上的标准化部分,特别是“ISO提案的生命:从”酷想法“到”国际标准“”

The paper that eventually made CTAD possible in C++17 is titled Template Tidbits and was first published on 2012-09-22. 最终制成的纸CTAD在C ++ 17种可能的标题为模板花絮 ,并首次发表于2012年9月22日。

It underwent many revisions and the paper "Template argument deduction for class templates" , which is the sixth revision of the paper was published on 2016-06-24. 它经历了多次修订,论文“类模板的模板论证演绎” ,该论文的第六次修订于2016-06-24发表。

So it took about five years for CTAD to go from “cool idea” to “international standard”. 因此,CTAD花了大约五年时间才从“酷想法”走向“国际标准”。

Also as @StoryTeller notes, the idea itself has been around for a much longer time and is presented in the paper Argument Deduction for Constructors which was published in 2007. 同样正如@StoryTeller指出的那样,这个想法本身已经存在了很长时间,并在2007年出版的论文“建筑师论文演绎 ”一文中提出。

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

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