C++核心准则T.12:声明局部变量类型时,概念比auto更好

2020-08-27 16:00:53 浏览数 (2)

T.12: Prefer concept names over auto for local variables

T.12:声明局部变量类型时,概念比auto更好

Reason(原因)

auto is the weakest concept. Concept names convey more meaning than just auto.

auto是最弱的概念。相比只用auto,概念名可以传递更多信息。

Example (using TS concepts)

示例(使用TS概念)

代码语言:javascript复制
vector<string> v{ "abc", "xyz" };
auto& x = v.front();     // bad
String& s = v.front();   // good (String is a GSL concept)
Enforcement(实施建议)
  • ???

原文链接

https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#t11-whenever-possible-use-standard-concepts

0 人点赞