代码初始化菜单规则(C核心准则GSL.view)(1)

GSL.view: ViewsGSL.view:视图

These types allow the user to distinguish between owning and non-owning pointers and between pointers to a single object and pointers to the first element of a sequence.

这些类型使用户可以区分拥有和不拥有的指针,以及指向单个对象的指针和指向序列的第一个元素的指针。

These "views" are never owners.

这里的各种“view”绝不是所有者。

References are never owners (see R.4. Note: References have many opportunities to outlive the objects they refer to (returning a local variable by reference, holding a reference to an element of a vector and doing push_back, binding to std::max(x, y 1), etc. The Lifetime safety profile aims to address those things, but even so owner<T&> does not make sense and is discouraged.

引用永远都不是所有者(请参阅R.4.注意:引用有很多机会使它们引用的对象寿命更长(通过引用返回局部变量,持有对vector元素的引用并进行push_back,绑定到std :: max(x,y 1)等)。生命周期安全规则群组旨在解决这些问题,但是即使如此,owner <T&>也没有意义,因此不建议使用。

The names are mostly ISO standard-library style (lower case and underscore):

名称主要是ISO标准库样式(小写和下划线):

The "raw-pointer" notation (e.g. int*) is assumed to have its most common meaning; that is, a pointer points to an object, but does not own it. Owners should be converted to resource handles (e.g., unique_ptr or vector<T>) or marked owner<T*>.

假定“原始指针”表示法(例如int *)具有最常见的含义;也就是说,指针指向一个对象,但不拥有它。所有者应转换为资源句柄(例如,unique_ptr或vector <T>)或标记为所有者<T *>。

owner is used to mark owning pointers in code that cannot be upgraded to use proper resource handles. Reasons for that include:

owner用于在无法升级为使用适当资源句柄的代码中标记所有者指针。原因包括:

An owner<T> differs from a resource handle for a T by still requiring an explicit delete.

owner <T>与T的资源句柄不同,它仍然需要显式删除。

An owner<T> is assumed to refer to an object on the free store (heap).

假定owner <T>引用自由存储(堆)上的对象。

If something is not supposed to be nullptr, say so:

如果不应该使用nullptr,请这样说:

A span<T> refers to zero or more mutable Ts unless T is a const type.

除非T是const类型,否则span <T>表示零个或多个可变Ts。

"Pointer arithmetic" is best done within spans. A char* that points to more than one char but is not a C-style string (e.g., a pointer into an input buffer) should be represented by a span.

最好在范围完成“指针算术”。指向多个char但不是C样式字符串的char *(例如,指向输入缓冲区的指针)应以span表示。

Logically, those last two aliases are not needed, but we are not always logical, and they make the distinction between a pointer to one char and a pointer to a C-style string explicit. A sequence of characters that is not assumed to be zero-terminated should be a char*, rather than a zstring. French accent optional.

从逻辑上讲,不需要最后两个别名,但是我们并不总是合乎逻辑的,它们使指向一个char的指针和指向C样式字符串的指针之间的区别变得明确。不假定以零结尾的字符序列应该是char *,而不是zstring。法国口音可选。

Use not_null<zstring> for C-style strings that cannot be nullptr. ??? Do we need a name for not_null<zstring>? or is its ugliness a feature?

对于不能为nullptr的C样式字符串,请使用not_null <zstring>。???我们需要一个not_null <zstring>的名称吗?还是它的丑陋功能?

原文链接

https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#gslview-views

新书介绍

《实战Python设计模式》是作者最近出版的新书,拜托多多关注!

代码初始化菜单规则(C核心准则GSL.view)(2)

本书利用Python 的标准GUI 工具包tkinter,通过可执行的示例对23 个设计模式逐个进行说明。这样一方面可以使读者了解真实的软件开发工作中每个设计模式的运用场景和想要解决的问题;另一方面通过对这些问题的解决过程进行说明,让读者明白在编写代码时如何判断使用设计模式的利弊,并合理运用设计模式。

对设计模式感兴趣而且希望随学随用的读者通过本书可以快速跨越从理解到运用的门槛;希望学习Python GUI 编程的读者可以将本书中的示例作为设计和开发的参考;使用Python 语言进行图像分析、数据处理工作的读者可以直接以本书中的示例为基础,迅速构建自己的系统架构。


觉得本文有帮助?请分享给更多人。

关注微信公众号【面向对象思考】轻松学习每一天!

面向对象开发,面向对象思考!

,