<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)則C.11:讓具體類型符合常規(guī)

          2721e8d9af539a80141f3306541f33af.webp

          C.11:?Make?concrete?types?regular

          C.11:讓具體類型符合常規(guī)


          Reason(原因)

          Regular?types?are?easier?to?understand?and?reason?about?than?types?that?are?not?regular?(irregularities?requires?extra?effort?to?understand?and?use).

          常規(guī)類型和非常規(guī)類型相比更容易理解和推測(cè)。理解和使用不符合常規(guī)的類型需要額外努力才行。


          Example(示例)

          struct Bundle {
          string name;
          vector vr;
          };

          bool operator==(const Bundle& a, const Bundle& b)
          {
          return a.name == b.name && a.vr == b.vr;
          }

          Bundle b1 { "my bundle", {r1, r2, r3}};
          Bundle b2 = b1;
          if (!(b1 == b2)) error("impossible!");
          b2.name = "the other bundle";
          if (b1 == b2) error("No!");

          In?particular,?if?a?concrete?type?has?an?assignment also give it an equals operator so?that a?=?b?implies?a?==?b.

          通常情況下,如果具體類型包含賦值操作,同時(shí)應(yīng)提供判斷相等的操作。也就是說(shuō)有a=b意味著也有a==b。


          Note(注意)

          Handles?for?resources?that?cannot?be?cloned,?e.g.,?a?scoped_lock?for?a?mutex,?resemble?concrete?types?in?that?they?most?often?are?stack-allocated.

          However, objects of such types typically cannot be copied (instead, they can usually be moved),so they can't be regular; instead, they tend to be semiregular.Often,?such types are referred to as?"move-only?types".

          管理不允許克隆的資源,例如用于管理mutex的scoped_lock,由于經(jīng)常在堆棧上分配,因此看起來(lái)像具體類型。但是這類類型的對(duì)象通常不能被拷貝(它們通常被移動(dòng)),因此它們不屬于常規(guī)的范疇,而是趨向于半常規(guī)。這樣的類型經(jīng)常被成為“只移動(dòng)類型”。


          Enforcement(實(shí)施建議)

          ???


          原文鏈接:

          https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#c11-make-concrete-types-regular




          覺(jué)得本文有幫助?請(qǐng)分享給更多人。

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

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

          瀏覽 24
          點(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>
                  午夜亚洲AV永久无码精品蜜芽 | 91久久久久无码精品国产麻豆 | 亚洲色情视频在线 | 翔田千里无码XXXXXX | 中文有码一区二区三区 |