<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          C++核心準(zhǔn)則T.41:在模板概念中只對(duì)本質(zhì)屬性定義需求?

          T.41: Require only essential properties in a template's concepts

          T.41:在模板概念中只對(duì)本質(zhì)屬性定義需求


          Reason(原因)

          Keep interfaces simple and stable.

          維持接口的簡(jiǎn)單和穩(wěn)定。


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

          Consider, a?sort?instrumented with (oversimplified) simple debug support:

          考慮一種包含(過于簡(jiǎn)單了)簡(jiǎn)單的調(diào)試功能的排序處理:

          void sort(Sortable& s)  // sort sequence s
          {
          if (debug) cerr << "enter sort( " << s << ")\n";
          // ...
          if (debug) cerr << "exit sort( " << s << ")\n";
          }

          Should this be rewritten to:

          應(yīng)該這樣寫:

          template
          requires Streamable
          void sort(S& s) // sort sequence s
          {
          if (debug) cerr << "enter sort( " << s << ")\n";
          // ...
          if (debug) cerr << "exit sort( " << s << ")\n";
          }

          After all, there is nothing in?Sortable?that requires?iostream?support. On the other hand, there is nothing in the fundamental idea of sorting that says anything about debugging.

          畢竟Sortable中沒有任何需要iostream支持的東西。同樣,排序的基本想法中也沒有任何關(guān)于調(diào)試的需求。


          Note(注意)

          If we require every operation used to be listed among the requirements, the interface becomes unstable: Every time we change the debug facilities, the usage data gathering, testing support, error reporting, etc., the definition of the template would need change and every use of the template would have to be recompiled. This is cumbersome, and in some environments infeasible.

          如果我們要求所有用到的操作都被羅列在需求中,接口的可用性就會(huì)降低:每次我們改變調(diào)試功能,用法數(shù)據(jù)收集,測(cè)試支持,錯(cuò)誤報(bào)告,等等,模板的定義都需要修改,并且每個(gè)使用模板的代碼都必須重新編譯。這種方式很笨拙,在某些環(huán)境中也是無法做到的。

          Conversely, if we use an operation in the implementation that is not guaranteed by concept checking, we may get a late compile-time error.

          相反,如果我們使用某個(gè)沒有被概念檢查保證的實(shí)現(xiàn)中的操作,我們可能得到遲到的編譯時(shí)錯(cuò)誤。

          By not using concept checking for properties of a template argument that is not considered essential, we delay checking until instantiation time. We consider this a worthwhile tradeoff.

          通過不用概念檢查非本質(zhì)模板參數(shù)的屬性,我們將檢查延遲到實(shí)例化時(shí)。我們認(rèn)為這是一種值得的妥協(xié)。

          Note that using non-local, non-dependent names (such as?debug?and?cerr) also introduces context dependencies that may lead to "mysterious" errors.

          注意,使用非局部,獨(dú)立名稱(例如debug和cerr)也會(huì)引入可能導(dǎo)致“神秘”錯(cuò)誤的上下文依賴。


          Note(注意)

          It can be hard to decide which properties of a type are essential and which are not.

          很難決定類型的那個(gè)屬性是本質(zhì)的,那個(gè)屬性不是本質(zhì)的。


          Enforcement(實(shí)施建議)

          ???


          原文鏈接

          https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#t41-require-only-essential-properties-in-a-templates-concepts


          新書介紹

          《實(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 語(yǔ)言進(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>



          瀏覽 59
          點(diǎn)贊
          評(píng)論
          收藏
          分享

          手機(jī)掃一掃分享

          分享
          舉報(bào)
          評(píng)論
          圖片
          表情
          推薦
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  一级欧美日韩 | 麻豆乱婬一区二区三区 | 影音资源男人 | 欧美成人操B视频 | 免费A片国产毛无码A片牛牛 |