<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.22:為概念定義公理

          月季花

          T.22: Specify axioms for concepts

          T.22:為概念定義公理


          Reason(原因)

          A meaningful/useful concept has a semantic meaning. Expressing these semantics in an informal, semi-formal, or formal way makes the concept comprehensible to readers and the effort to express it can catch conceptual errors. Specifying semantics is a powerful design tool.

          有意義/有用的概念會(huì)包含語義上的含義。以非正規(guī)的,半正規(guī)的或者正規(guī)的方式進(jìn)行表現(xiàn)這些語義可以讓概念更容易被用戶理解,而且表達(dá)概念的努力可以捕捉概念方面的錯(cuò)誤。定義語義是一種有力的設(shè)計(jì)工具。


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

          template
          // The operators +, -, *, and / for a number are assumed to follow the usual mathematical rules
          // axiom(T a, T b) { a + b == b + a; a - a == 0; a * (b + c) == a * b + a * c; /*...*/ }
          concept Number = requires(T a, T b) {
          {a + b} -> T; // the result of a + b is convertible to T
          {a - b} -> T;
          {a * b} -> T;
          {a / b} -> T;
          }
          Note(注意)

          This is an axiom in the mathematical sense: something that may be assumed without proof. In general, axioms are not provable, and when they are the proof is often beyond the capability of a compiler. An axiom may not be general, but the template writer may assume that it holds for all inputs actually used (similar to a precondition).

          這是一條有關(guān)數(shù)學(xué)規(guī)律的公理:某些不需要證據(jù)的假設(shè)。通常,公理是不可證明的,即使它們可以證明,通常也會(huì)超越編譯器的能力。公理可能并不普遍,但是模板作者可以假設(shè)它對所有實(shí)際使用的輸入有效(類似前提條件)


          Note(注意)

          In this context axioms are Boolean expressions. See the?Palo Alto TR?for examples. Currently, C++ does not support axioms (even the ISO Concepts TS), so we have to make do with comments for a longish while. Once language support is available, the?//?in front of the axiom can be removed

          在這個(gè)上下文中公理是一個(gè)布爾類型的表達(dá)式。參見Palo Alto TR中的例子。目前C++還沒有支持公理(包括ISO Concepts TS),因此我們必須在很長一段時(shí)間將它放在注釋內(nèi)。一旦語言提供了對公理的支持,就可以去掉前面的//。


          Note(注意)

          The GSL concepts have well-defined semantics; see the Palo Alto TR and the Ranges TS.

          GSL概念提供了定義良好的語義。參見Palo Alto TR和范圍TS。


          Exception (using TS concepts)(例外(使用TS概念))

          Early versions of a new "concept" still under development will often just define simple sets of constraints without a well-specified semantics. Finding good semantics can take effort and time. An incomplete set of constraints can still be very useful:

          仍在開發(fā)中的新“概念”的早期版本通常只是定義某些約束的簡單集合,而這些約束可能并不具有良好定義的語義。發(fā)現(xiàn)完美的語義需要努力和時(shí)間。約束的不完全集合同樣可以非常有用。

          // balancer for a generic binary tree
          template concept bool Balancer = requires(Node* p) {
          add_fixup(p);
          touch(p);
          detach(p);
          }

          So a?Balancer?must supply at least thee operations on a tree?Node, but we are not yet ready to specify detailed semantics because a new kind of balanced tree might require more operations and the precise general semantics for all nodes is hard to pin down in the early stages of design.

          因此樹節(jié)點(diǎn)上的Balancer必須至少支持三個(gè)操作,但是我們還沒有準(zhǔn)備好定義語義的細(xì)節(jié),因?yàn)樾路N類的平衡樹可能需要更多的操作,而且適用于所有節(jié)點(diǎn)的準(zhǔn)確、通用的語義很難在設(shè)計(jì)的早期階段確定。


          A "concept" that is incomplete or without a well-specified semantics can still be useful. For example, it allows for some checking during initial experimentation. However, it should not be assumed to be stable. Each new use case may require such an incomplete concept to be improved.

          不完全或者沒有良好定義的“概念”仍然有用。例如,它允許在初始化階段進(jìn)行某些檢查。然而,它不應(yīng)該被認(rèn)定是穩(wěn)定的。每一次新用法都可能讓這個(gè)不完全的概念發(fā)生改變。


          Enforcement(實(shí)施建議)

          • Look for the word "axiom" in concept definition comments

          • 在概念定義的注釋中發(fā)現(xiàn)”axiom“。


          原文鏈接

          https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#t22-specify-axioms-for-concepts


          新書介紹

          《實(shí)戰(zhàn)Python設(shè)計(jì)模式》是作者最近出版的新書,拜托多多關(guān)注!

          本書利用Python 的標(biāo)準(zhǔn)GUI 工具包tkinter,通過可執(zhí)行的示例對23 個(gè)設(shè)計(jì)模式逐個(gè)進(jìn)行說明。這樣一方面可以使讀者了解真實(shí)的軟件開發(fā)工作中每個(gè)設(shè)計(jì)模式的運(yùn)用場景和想要解決的問題;另一方面通過對這些問題的解決過程進(jìn)行說明,讓讀者明白在編寫代碼時(shí)如何判斷使用設(shè)計(jì)模式的利弊,并合理運(yùn)用設(shè)計(jì)模式。

          對設(shè)計(jì)模式感興趣而且希望隨學(xué)隨用的讀者通過本書可以快速跨越從理解到運(yùn)用的門檻;希望學(xué)習(xí)Python GUI 編程的讀者可以將本書中的示例作為設(shè)計(jì)和開發(fā)的參考;使用Python 語言進(jìn)行圖像分析、數(shù)據(jù)處理工作的讀者可以直接以本書中的示例為基礎(chǔ),迅速構(gòu)建自己的系統(tǒng)架構(gòu)。




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

          關(guān)注微信公眾號【面向?qū)ο笏伎肌枯p松學(xué)習(xí)每一天!

          面向?qū)ο箝_發(fā),面向?qū)ο笏伎迹?/span>



          瀏覽 76
          點(diǎn)贊
          評論
          收藏
          分享

          手機(jī)掃一掃分享

          分享
          舉報(bào)
          評論
          圖片
          表情
          推薦
          <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>
                  99热在线99 | 后入美女人妻 | 无码一区二区三区四区精 | 国产色亚洲 | 超碰在线观 |