<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++核心準則C.89:保證哈希不會拋出異常

          b4c63993e910c9ecaa0f630b59018c25.webp

          白云母晶簇

          7775d707a3688d47ecd98ac50022c262.webp

          C.89: Make a hash noexcept

          C.89:保證哈希不會拋出異常

          c78ee9e9001e718f797d10e3338ad75b.webp


          884de63f0d2941c0fcff7ae03be01d2b.webp7bfacf38fead3671c0b7d12e55d99348.webpReason(原因)7bfacf38fead3671c0b7d12e55d99348.webp

          Users of hashed containers use hash indirectly and don't expect simple access to throw. It's a standard-library?

          requirement.

          哈希容器的用戶間接地使用哈希功能,不希望簡單的操作發(fā)生異常。這是標準庫的要求。


          884de63f0d2941c0fcff7ae03be01d2b.webp7bfacf38fead3671c0b7d12e55d99348.webpExample, bad(反面示例)7bfacf38fead3671c0b7d12e55d99348.webp
          template<>
          struct hash { ?// thoroughly bad hash specialization
          ? ?using result_type = size_t;
          ? ?using argument_type = My_type;

          ? ?size_t operator() (const My_type & x) const
          ? ?{
          ? ? ? ?size_t xs = x.s.size();
          ? ? ? ?if (xs < 4) throw Bad_My_type{}; ? ?// "Nobody expects the Spanish inquisition!"
          ? ? ? ?return hash()(x.s.size()) ^ trim(x.s);
          ? ?}
          };

          int main()
          {
          ? ?unordered_map m;
          ? ?My_type mt{ "asdfg" };
          ? ?m[mt] = 7;
          ? ?cout << m[My_type{ "asdfg" }] << '\n';
          }

          If you have to define a hash specialization, try simply to let it combine standard-library hash specializations with ^ (xor). That tends to work better than "cleverness" for non-specialists.

          如果你已經(jīng)定義了哈希特化,爭取簡單地實現(xiàn)為通過異或和標準庫哈希特化的組合。

          884de63f0d2941c0fcff7ae03be01d2b.webp7bfacf38fead3671c0b7d12e55d99348.webpEnforcement(實現(xiàn)建議)7bfacf38fead3671c0b7d12e55d99348.webp
          • Flag throwing hashes.

          • 提示拋出異常的哈希。

          884de63f0d2941c0fcff7ae03be01d2b.webp7bfacf38fead3671c0b7d12e55d99348.webp原文鏈接7bfacf38fead3671c0b7d12e55d99348.webp

          https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#c89-make-a-hash-noexcept




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

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

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

          瀏覽 45
          點贊
          評論
          收藏
          分享

          手機掃一掃分享

          分享
          舉報
          評論
          圖片
          表情
          推薦
          <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热 | 国产打骚逼 |