C++核心准则T.11:只要可能就使用标准概念
天人菊
T.11: Whenever possible use standard concept
T.11:只要可能就使用标准概念
Reason(原因)
"Standard" concepts (as provided by the GSL and the Ranges TS, and hopefully soon the ISO standard itself) save us the work of thinking up our own concepts, are better thought out than we can manage to do in a hurry, and improve interoperability.
“标准”的概念(由GSL或Range技术规格提供,很有可能很快ISO标准也会提供)可以节约我们设计自用概念的工作,而且标准概念会比我们匆忙之间设计的概念更好,也更具互换性。
Note(注意)
Unless you are creating a new generic library, most of the concepts you need will already be defined by the standard library
除非你在开发新的通用库,大部分你需要的概念应该已经在标准库中有定义而不需要另外设计。
Example (using TS concepts)(实例(使用TS概念))
template<typename T>
// don't define this: Sortable is in the GSL
concept Ordered_container = Sequence<T> && Random_access<Iterator<T>> && Ordered<Value_type<T>>;
void sort(Ordered_container& s);
This Ordered_container is quite plausible, but it is very similar to the Sortable concept in the GSL (and the Range TS). Is it better? Is it right? Does it accurately reflect the standard's requirements for sort? It is better and simpler just to use Sortable:
Ordered_container相当合理,但是它和GSL(和RangeTS)中的Sortable概念非常相似。这么做更好么?这么做正确么?它准确地反映了排序的标准需求么?直接使用Sortable的方式更简单也更好。
void sort(Sortable& s); // better
Note(注意)
The set of "standard" concepts is evolving as we approach an ISO standard including concepts.
在我们努力将概念引入ISO标准的过程中,这一套“标准”概念也在逐步发展。
Note(注意)
Designing a useful concept is challenging.
设计一个有用的概念是一种挑战。
Enforcement(实施建议)
Hard.
很难
- Look for unconstrained arguments, templates that use "unusual"/non-standard concepts, templates that use "homebrew" concepts without axioms.
- 寻找使用没有约束的参数,使用“不一般的”/非标准概念的模板,使用没有经过严密论证的自己定义的概念的模板。
- Develop a concept-discovery tool (e.g., see an early experiment).
- 设计一个发现概念的工具 参见 :https://www.stroustrup.com/sle2010_webversion.pdf
原文链接
https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#t11-whenever-possible-use-standard-concepts
- 名为“闪电比特币”Lightning Bitcoin,LBTC的新型比特币硬叉被释放
- IDHub亮相区块链行业巅峰盛宴 分享网络生活的“进化论”
- 总结:如何加速你的 WordPress 站点?
- 百年老牌的创新之路:看可口可乐如何用AI、大数据颠覆传统营销
- 微信小游戏上线,小程序或将成为未来的营销工具
- WooCommerce 自定义商品价格显示HTML结构
- 借助Github 为第三方WordPress 主题/插件添加“自动更新”功能
- vue-cli#2.0 webpack 配置分析
- 短代码插件S-shortcodes 更新2.4版本:修复font icon的冲突问题
- 景驰落户广州 王劲称不知百度为何指控 四条回应两大疑点
- 全球各行业2020年将需要270万位数据科学家
- 解决iOS 版Safari 中浮动(float)导致页面右侧偏移的bug
- 学而思网校又玩大了:引入人工智能技术,办了一场“人机对话”英语赛事
- 全球首个机器人公民索菲亚亮相2017双12知商节 引爆全场知识产权新高潮
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- Codeforces 660C-Hard Process【尺取法练习】
- 杭电5178 (二分练习!)
- Java 13 新特性
- 杭电 1789(贪心思维练习)
- 利用反转函数确定回文串
- Codeforces Round #618 (Div. 2)
- Educational Codeforces Round 82 (Rated for Div. 2)
- [C# 开发技巧]如何防止程序多次运行
- 问题 1117: K-进制数
- Java 11 新垃圾回收器 ZGC
- Red and Black(DFS 深搜练习)
- Codeforces Round #619 (Div. 2)
- 问题 1255: [蓝桥杯][算法提高]能量项链
- C# 开发技巧]如何防止程序多次运行 线程 进程
- 问题 1433: [蓝桥杯][2013年第四届真题]危险系数