溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

C++單類型參數(shù)概念是什么

發(fā)布時間:2021-11-24 11:18:12 來源:億速云 閱讀:184 作者:iii 欄目:大數(shù)據(jù)

本篇內(nèi)容主要講解“C++單類型參數(shù)概念是什么”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實用性強(qiáng)。下面就讓小編來帶大家學(xué)習(xí)“C++單類型參數(shù)概念是什么”吧!

T.13:對于簡單的,單類型參數(shù)概念,使用縮略記法更好

Reason(原因)

Readability. Direct expression of an idea.

可讀性。直接表現(xiàn)想法。

Example (using TS concepts)示例(使用TS概念)

To say "T is Sortable":

為了表達(dá)“T是可排序類型”:

template<typename T>       // Correct but verbose: "The parameter is
//    requires Sortable<T>   // of type T which is the name of a type
void sort(T&);             // that is Sortable"

template<Sortable T>       // Better (assuming support for concepts): "The parameter is of type T
void sort(T&);             // which is Sortable"

void sort(Sortable&);      // Best (assuming support for concepts): "The parameter is Sortable"

The shorter versions better match the way we speak. Note that many templates don't need to use the template keyword.

較短的版本更符合我們想要表達(dá)的。注意很多模板不需要使用模板關(guān)鍵字。

Note(注意)

"Concepts" are defined in an ISO Technical Specification: concepts. A draft of a set of standard-library concepts can be found in another ISO TS: ranges Concepts are supported in GCC 6.1 and later. Consequently, we comment out uses of concepts in examples; that is, we use them as formalized comments only. If you use a compiler that supports concepts (e.g., GCC 6.1 or later), you can remove the //

“概念”在ISO技術(shù)規(guī)格concepts中被定義。一套標(biāo)準(zhǔn)庫concepts的初步版本可以在另一個ISO技術(shù)規(guī)格:ranges中找到。GCC6.1以后都支持concepts。因此我們在實例代碼中注釋掉使用concepts的部分;也就是說我們只是將它們用作標(biāo)準(zhǔn)的注釋。如果你使用GCC6.1之后的版本,可以打開注釋。

Enforcement(實施建議)

  • Not feasible in the short term when people convert from the <typename T> and <class T> notation.

  • 如果人們從<typename T> 和<class T>記法轉(zhuǎn)過來,使用縮略記法是不合適的。

  • Later, flag declarations that first introduce a typename and then constrain it with a simple, single-type-argument concept.

  • 隨后,標(biāo)記第一次引入類型名并馬上使用簡單的,單類型概念對其進(jìn)行約束的情況。

到此,相信大家對“C++單類型參數(shù)概念是什么”有了更深的了解,不妨來實際操作一番吧!這里是億速云網(wǎng)站,更多相關(guān)內(nèi)容可以進(jìn)入相關(guān)頻道進(jìn)行查詢,關(guān)注我們,繼續(xù)學(xué)習(xí)!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

c++
AI