C++核心準(zhǔn)則?GSL.view:視圖

GSL.view: Views
GSL.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.
這些類型使用戶可以區(qū)分擁有和不擁有的指針,以及指向單個(gè)對(duì)象的指針和指向序列的第一個(gè)元素的指針。
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
引用永遠(yuǎn)都不是所有者(請(qǐng)參閱R.4.注意:引用有很多機(jī)會(huì)使它們引用的對(duì)象壽命更長(zhǎng)(通過引用返回局部變量,持有對(duì)vector元素的引用并進(jìn)行push_back,綁定到std :: max(x,y + 1)等)。生命周期安全規(guī)則群組旨在解決這些問題,但是即使如此,owner
The names are mostly ISO standard-library style (lower case and underscore):
名稱主要是ISO標(biāo)準(zhǔn)庫(kù)樣式(小寫和下劃線):
T*?// The?T*?is not an owner, might be null; assumed to be pointing to a single element.
T * // T *不是所有者,可以為null;假定指向單個(gè)元素。
T&?// The?T&?is not an owner and can never be a "null reference"; references are always bound to objects.
T&// T&不是所有者,永遠(yuǎn)不能是“空引用”;引用始終綁定到對(duì)象。
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
假定“原始指針”表示法(例如int *)具有最常見的含義;也就是說,指針指向一個(gè)對(duì)象,但不擁有它。所有者應(yīng)轉(zhuǎn)換為資源句柄(例如,unique_ptr或vector
owner
?// a?T*?that owns the object pointed/referred to; might be?nullptr. owner
//一個(gè)T *,它擁有指向/引用的對(duì)象;可能為nullptr。
owner?is used to mark owning pointers in code that cannot be upgraded to use proper resource handles. Reasons for that include:
owner用于在無法升級(jí)為使用適當(dāng)資源句柄的代碼中標(biāo)記所有者指針。原因包括:
Cost of conversion.
轉(zhuǎn)換成本。
The pointer is used with an ABI.
該指針與ABI一起使用。
The pointer is part of the implementation of a resource handle.
指針是資源句柄實(shí)現(xiàn)的一部分。
An?owner
owner
An?owner
假定owner
If something is not supposed to be?nullptr, say so:
如果不應(yīng)該使用nullptr,請(qǐng)這樣說:
not_null
?//?T?is usually a pointer type (e.g.,?not_null ?and?not_null >) that must not be?nullptr.?T?can be any type for which?==nullptr?is meaningful. not_null
// T通常是一個(gè)指針類型(例如not_null 和not_null >),不能為nullptr。T可以是== nullptr有意義的任何類型。 span
?//?[p:p+n), constructor from?{p, q}?and?{p, n};?T?is the pointer type span
// [p:p + n),{p,q}和{p,n}的構(gòu)造函數(shù);T是指針類型 span_p
?//?{p, predicate}?[p:q)?where?q?is the first element for which?predicate(*p)?is true span_p
// {p,謂詞} [p:q)其中q是謂詞(* p)為true的第一個(gè)元素
A?span
除非T是const類型,否則span
"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.
最好在范圍完成“指針?biāo)阈g(shù)”。指向多個(gè)char但不是C樣式字符串的char *(例如,指向輸入緩沖區(qū)的指針)應(yīng)以span表示。
zstring?// a?char*?supposed to be a C-style string; that is, a zero-terminated sequence of?char?or?nullptr
zstring //一個(gè)char *,應(yīng)該是C樣式的字符串;即char或nullptr的零終止序列
czstring?// a?const char*?supposed to be a C-style string; that is, a zero-terminated sequence of?const?char?or?nullptr
czstring //一個(gè)const char *,應(yīng)該是C樣式的字符串;也就是說,一個(gè)以零結(jié)尾的const char或nullptr序列
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.
從邏輯上講,不需要最后兩個(gè)別名,但是我們并不總是合乎邏輯的,它們使指向一個(gè)char的指針和指向C樣式字符串的指針之間的區(qū)別變得明確。不假定以零結(jié)尾的字符序列應(yīng)該是char *,而不是zstring。法國(guó)口音可選。
Use?not_null
對(duì)于不能為nullptr的C樣式字符串,請(qǐng)使用not_null
原文鏈接
https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#gslview-views
新書介紹
《實(shí)戰(zhàn)Python設(shè)計(jì)模式》是作者最近出版的新書,拜托多多關(guān)注!

本書利用Python 的標(biāo)準(zhǔn)GUI 工具包tkinter,通過可執(zhí)行的示例對(duì)23 個(gè)設(shè)計(jì)模式逐個(gè)進(jìn)行說明。這樣一方面可以使讀者了解真實(shí)的軟件開發(fā)工作中每個(gè)設(shè)計(jì)模式的運(yùn)用場(chǎng)景和想要解決的問題;另一方面通過對(duì)這些問題的解決過程進(jìn)行說明,讓讀者明白在編寫代碼時(shí)如何判斷使用設(shè)計(jì)模式的利弊,并合理運(yùn)用設(shè)計(jì)模式。
對(duì)設(shè)計(jì)模式感興趣而且希望隨學(xué)隨用的讀者通過本書可以快速跨越從理解到運(yùn)用的門檻;希望學(xué)習(xí)Python GUI 編程的讀者可以將本書中的示例作為設(shè)計(jì)和開發(fā)的參考;使用Python 語言進(jìn)行圖像分析、數(shù)據(jù)處理工作的讀者可以直接以本書中的示例為基礎(chǔ),迅速構(gòu)建自己的系統(tǒng)架構(gòu)。
覺得本文有幫助?請(qǐng)分享給更多人。
關(guān)注微信公眾號(hào)【面向?qū)ο笏伎肌枯p松學(xué)習(xí)每一天!
面向?qū)ο箝_發(fā),面向?qū)ο笏伎迹?/span>
