Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Will C++14 support unconstrained generic functions?

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++?

like image 625
user2023370 Avatar asked Jun 15 '14 16:06

user2023370


1 Answers

If we look at the latest draft standard N3936 which is pretty close to the C++14 DIS which is N3937(this is covered in N3938). It does not contain any of the language specified in sections 4.1.2 and 5.1.1 of N3889.

So for C++14 it looks like the answer is no, but Bjarne Stroustrup says concepts lite will be a technical report. You can find more about technical reports on ISO cpp's Current Status page which says:

Beyond C++14, the committee contemplates producing another C++ Standard in approximately 2017. That doesn’t mean nothing is happening in the meantime, however, because we currently have eight (8) separate Technical Specifications underway, several of which are on track to be published in 2014 and 2015. Starting in 2012, the committee has transitioned to a “decoupled” model where major pieces of work can progress independently from the Standard itself and be delivered as separate TS’s. Vendors can choose to implement these, and the community can gain experience with the std::experimental version of each feature. This lets us learn and adjust each feature’s design based on experience before it is formally included in a future version of the actual C++ Standard

like image 162
Shafik Yaghmour Avatar answered Oct 16 '22 00:10

Shafik Yaghmour