溫馨提示×

溫馨提示×

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

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

C++中怎么使用TS概念

發布時間:2021-11-24 11:11:25 來源:億速云 閱讀:232 作者:iii 欄目:大數據

本篇內容介紹了“C++中怎么使用TS概念”的有關知識,在實際案例的操作過程中,不少人都會遇到這樣的困境,接下來就讓小編帶領大家學習一下如何處理這些情況吧!希望大家仔細閱讀,能夠學有所成!

T.24:使用標簽類或特征區分只有語義不同的概念

Reason(原因)

Two concepts requiring the same syntax but having different semantics leads to ambiguity unless the programmer differentiates them.

兩個概念具有相同的語法需求但是語義不同會引起歧義,除非程序員可以區分它們。

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

template<typename I>    // iterator providing random access
concept bool RA_iter = ...;

template<typename I>    // iterator providing random access to contiguous data
concept bool Contiguous_iter =
   RA_iter<I> && is_contiguous<I>::value;  // using is_contiguous trait

The programmer (in a library) must define is_contiguous (a trait) appropriately.

程序員(在庫代碼中)必須恰當地定義is_contiguous(特征)。

Wrapping a tag class into a concept leads to a simpler expression of this idea:

將一個標簽類封入概念可以更簡單地表現想法。

template<typename I> concept Contiguous = is_contiguous<I>::value;

template<typename I>
concept bool Contiguous_iter = RA_iter<I> && Contiguous<I>;

The programmer (in a library) must define is_contiguous (a trait) appropriately.

程序員(在庫代碼中)必須恰當地定義is_contiguous(特征)。

Note(注意)

Traits can be trait classes or type traits. These can be user-defined or standard-library ones. Prefer the standard-library ones.

特征的表達可以通過特征類和類型特征給你來實現。它們可以是用戶定義的,也可以由標準庫提供。標準庫提供的方式更好。

Enforcement(實施建議)

  • The compiler flags ambiguous use of identical concepts.

  • 編譯器應該標記想定義完全相同的概念的混亂用法。

  • Flag the definition of identical concepts.

  • 標記完全相同的概念定義。

“C++中怎么使用TS概念”的內容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業相關的知識可以關注億速云網站,小編將為大家輸出更多高質量的實用文章!

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

c++
AI

亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女