网站首页 > 博客文章 正文
I.9: If an interface is a template, document its parameters using concepts(如果接口是模板类型,则使用concept文档化其参数)
Reason(原因)
Make the interface precisely specified and compile-time checkable in the (not so distant) future.
这样做可以让接口被准确地定义,并且将来可以在编译时检查。
译者注:concept是C++20将要引入的新特性。使用concept库可以实现编译时对模板参数的检查,从而大大降低使用模板的难度。详细请参照:https://en.cppreference.com/w/cpp/concepts
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(注意)
Soon (maybe in 2018), most compilers will be able to check requires clauses once the // is removed. Concepts are supported in GCC 6.1 and later.
不久以后(可能在2018年内),如果移除代码中的“//”,很多编译器将可以检查requires从句。GCC6.1及以后的版本都会支持Concepts。
译者注:
1.由于作者在考虑这条准则的时候,concept还没有被标准C++支持,因此暂时用“//”注释掉。
2.2019/9开始,VisualStudio2019预览版也能够支持concept。
See also: Generic programming and concepts.
参考:泛型编程和concepts。
猜你喜欢
- 2024-10-12 C++核心准则T.24:用标签类或特征区分只有语义不同的概念
- 2024-10-12 用苹果发布会方式打开C++20(苹果在哪开发布会)
- 2024-10-12 C++核心准则T.25:避免互补性约束(规矩是一种约束,一种准则)
- 2024-10-12 C++核心准则T.21:为概念定义一套完整的操作
- 2024-10-12 C++核心准则T.5:结合使用泛型和面向对象技术应该增强效果
- 2024-10-12 C++经典书籍(c++相关书籍)
- 2024-10-12 C++一行代码实现任意系统函数Hook
- 2024-10-12 C++核心准则T.11:只要可能就使用标准概念
- 2024-10-12 C++核心准则T.48:如果不能用概念,用enable_if
- 2024-10-12 C++核心准则T.13:简单、单类型参数概念使用缩略记法更好
你 发表评论:
欢迎- 最近发表
-
- 给3D Slicer添加Python第三方插件库
- Python自动化——pytest常用插件详解
- Pycharm下安装MicroPython Tools插件(ESP32开发板)
- IntelliJ IDEA 2025.1.3 发布(idea 2020)
- IDEA+Continue插件+DeepSeek:开发者效率飙升的「三体组合」!
- Cursor:提升Python开发效率的必备IDE及插件安装指南
- 日本旅行时想借厕所、买香烟怎么办?便利商店里能解决大问题!
- 11天!日本史上最长黄金周来了!旅游万金句总结!
- 北川景子&DAIGO缘定1.11 召开记者会宣布结婚
- PIKO‘PPAP’ 洗脑歌登上美国告示牌
- 标签列表
-
- ifneq (61)
- messagesource (56)
- aspose.pdf破解版 (56)
- promise.race (63)
- 2019cad序列号和密钥激活码 (62)
- window.performance (66)
- qt删除文件夹 (72)
- mysqlcaching_sha2_password (64)
- ubuntu升级gcc (58)
- nacos启动失败 (64)
- ssh-add (70)
- jwt漏洞 (58)
- macos14下载 (58)
- yarnnode (62)
- abstractqueuedsynchronizer (64)
- source~/.bashrc没有那个文件或目录 (65)
- springboot整合activiti工作流 (70)
- jmeter插件下载 (61)
- 抓包分析 (60)
- idea创建mavenweb项目 (65)
- vue回到顶部 (57)
- qcombobox样式表 (68)
- vue数组concat (56)
- tomcatundertow (58)
- pastemac (61)
本文暂时没有评论,来添加一个吧(●'◡'●)