天天看點

C++核心準則T.23:通過增加新的使用模式,從更加普遍的場景中區分更精煉的概念

T.23: Differentiate a refined concept from its more general case by adding new use patterns.

T.23:通過增加新的使用模式,從更加普遍的場景中區分更精煉的概念

Reason(原因)

Otherwise they cannot be distinguished automatically by the compiler.

否則它們無法被編譯器自動區分。

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

template<typename I>
concept bool Input_iter = requires(I iter) { ++iter; };

template<typename I>
concept bool Fwd_iter = Input_iter<I> && requires(I iter) { iter++; }      

The compiler can determine refinement based on the sets of required operations (here, suffix ++). This decreases the burden on implementers of these types since they do not need any special declarations to "hook into the concept". If two concepts have exactly the same requirements, they are logically equivalent (there is no refinement).

編譯器可以決定基于一套必要操作(這裡是++字尾)的提煉。由于這種方式不需要深入概念内部的特别定義,因而減輕了實作這些類型的負擔。如果兩個概念具有完全相同的需求,它們邏輯上就是等價的(這裡不存在提煉)

Enforcement(實施建議)

  • Flag a concept that has exactly the same requirements as another already-seen concept (neither is more refined). To disambiguate them, see T.24.
  • 标記和其他已經見過的概念(兩者都沒有被提煉)具有完全相同的需求的概念。

​原文連結

​​https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#t23-differentiate-a-refined-concept-from-its-more-general-case-by-adding-new-use-patterns​​

新書介紹

​​《實戰Python設計模式》​​是作者最近出版的新書,拜托多多關注!

C++核心準則T.23:通過增加新的使用模式,從更加普遍的場景中區分更精煉的概念

本書利用Python 的标準GUI 工具包tkinter,通過可執行的示例對23 個設計模式逐個進行說明。這樣一方面可以使讀者了解真實的軟體開發工作中每個設計模式的運用場景和想要解決的問題;另一方面通過對這些問題的解決過程進行說明,讓讀者明白在編寫代碼時如何判斷使用設計模式的利弊,并合理運用設計模式。

對設計模式感興趣而且希望随學随用的讀者通過本書可以快速跨越從了解到運用的門檻;希望學習Python GUI 程式設計的讀者可以将本書中的示例作為設計和開發的參考;使用Python 語言進行圖像分析、資料處理工作的讀者可以直接以本書中的示例為基礎,迅速建構自己的系統架構。

覺得本文有幫助?請分享給更多人。

關注微信公衆号【面向對象思考】輕松學習每一天!

面向對象開發,面向對象思考!

繼續閱讀