Is auto as a parameter in a regular function a GCC 4.9 extension?

社会主义新天地 提交于 2019-11-26 15:31:57

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

template<class T>
void foo(T c)
{
    std::cout << c.c_str();
}

The auto just replaces the more verbose template<class T>. Similarly, you can write

void foo(Sortable c)

as a shorthand for

template<class T> 
requires Sortable<T>{}
void foo(T c)

Here, Sortable is a concept, which is implemented as a conjunction of constexpr 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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!