gcc 4.9 allows the following code, but gcc 4.8 and clang 3.5.0 reject it.
void foo(auto c)
{
std::cout << c.c_str();
}
I get warning: ISO C++ forbids use of 'auto' in parameter declaration [-Wpedantic]
in 4.9 but in 4.8 and clang I get error: parameter declared 'auto'
.
Yes, this is an extension. It's likely to be added to C++17 as part of the 'concepts' proposal, I believe.
This is Concepts Lite speak for
The
auto
just replaces the more verbosetemplate<class T>
. Similarly, you can writeas a shorthand for
Here,
Sortable
is a concept, which is implemented as a conjunction ofconstexpr
predicates that formalize the requirements on the template parameter. Checking these requirements is done during name lookup.In this sense,
auto
is a completely unconstrained template.