C++中为什么接口是模板类型就使用concept文档化其参数

这篇文章主要介绍“C++中为什么接口是模板类型就使用concept文档化其参数”,在日常操作中,相信很多人在C++中为什么接口是模板类型就使用concept文档化其参数问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”C++中为什么接口是模板类型就使用concept文档化其参数”的疑惑有所帮助!接下来,请跟着小编一起来学习吧!

Reason(原因)

Make the interface precisely specified and compile-time checkable in the (not so distant) future.

这样做可以让接口被准确地定义,并且将来可以在编译时检查。

Example(示例)

Use the ISO Concepts TS style of requirements specification. For example:

使用ISO Concepts技术规范风格的需求定义,例如:

template<typename Iter, typename Val>// requires InputIterator<Iter> && EqualityComparable<ValueType<Iter>>, Val>Iter find(Iter first, Iter last, Val v){    // ...}

Note(注意)

不久以后(可能在2018年内),如果移除代码中的“//”,很多编译器将可以检查requires从句。GCC6.1及以后的版本都会支持Concepts。

到此,关于“C++中为什么接口是模板类型就使用concept文档化其参数”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注网站,小编会继续努力为大家带来更多实用的文章!