16

While looking at the GCC 4.9.0 release changes here, I was pleasantly surprised to read the following; under the "New Languages and Language specific improvements" section for C++:

G++ supports unconstrained generic functions as specified by §4.1.2 and §5.1.1 of N3889: Concepts Lite Specification. Briefly, auto may be used as a type-specifier in a parameter declaration of any function declarator in order to introduce an implicit function template parameter, akin to generic lambdas.

// the following two function declarations are equivalent
auto incr(auto x) { return x++; }
template <typename T>
auto incr(T x) { return x++; }

I built GCC 4.9.0 and my initial tests worked as expected. I believe that Concepts Lite will remain somehow auxiliary to the upcoming C++14 specification. Is there though any plan for "unconstrained generic functions" to become a part of C++?

4

1 回答 1

5

如果我们查看最新的标准草案N3936,它非常接近 C++14 DIS N3937这在N3938中有介绍)。它不包含在sections4.1.25.1.1of中指定的任何语言N3889

所以对于 C++14 来说,答案似乎是否定的,但Bjarne Stroustrup 说概念精简版将是一份技术报告您可以在ISO cpp 的当前状态页面上找到有关技术报告的更多信息,该页面显示:

除了 C++14,委员会还计划在 2017 年左右制定另一个 C++ 标准。但这并不意味着在此期间什么都没有发生,但是,因为我们目前有八 (8) 个单独的技术规范正在进行中,其中一些正在按计划进行将于 2014 年和 2015 年发布。从 2012 年开始,委员会已过渡到“解耦”模式,其中主要工作可以独立于标准本身进行,并作为单独的 TS 交付。供应商可以选择实施这些,社区可以获得每个功能的 std::experimental 版本的经验。这让我们在正式包含在实际 C++ 标准的未来版本中之前,可以根据经验学习和调整每个特性的设计

于 2014-06-15T18:06:18.997 回答