<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.44:使用函數(shù)模板推斷類模板參數(shù)類型(如果可能)

          T.44: Use function templates to deduce class template argument types (where feasible)

          T.44:使用函數(shù)模板推斷類模板參數(shù)類型(如果可能)


          Reason(原因)

          Writing the template argument types explicitly can be tedious and unnecessarily verbose.

          顯示輸入模板參數(shù)類型冗長且無必要。


          Example(示例)

          tuple t1 = {1, "Hamlet", 3.14};   // explicit type
          auto t2 = make_tuple(1, "Ophelia"s, 3.14); // better; deduced type

          Note the use of the?s?suffix to ensure that the string is a?std::string, rather than a C-style string.

          注意通過使用s后綴可以保證string是std::string而不是C風(fēng)格字符串。


          Note(注意)

          Since you can trivially write a?make_T?function, so could the compiler. Thus,?make_T?functions might become redundant in the future.

          你可以直接編寫make_T函數(shù),編譯器也可以。因此make_T函數(shù)將來可能會變得多余。


          Exception(例外)

          Sometimes there isn't a good way of getting the template arguments deduced and sometimes, you want to specify the arguments explicitly:

          有時,沒有合適的方式實現(xiàn)模板參數(shù)推斷,也有可能你希望顯式定義參數(shù)類型。

          vector v = { 1, 2, 3, 7.9, 15.99 };
          list lst;
          Note(注意)

          Note that C++17 will make this rule redundant by allowing the template arguments to be deduced directly from constructor arguments:?Template parameter deduction for constructors (Rev. 3). For example:

          注意C++17將會令本規(guī)則多余,原因是C++17允許直接通過構(gòu)造函數(shù)參數(shù)直接推斷模板參數(shù):構(gòu)造函數(shù)的模板參數(shù)推斷(Rev.3)。例如:

          tuple t1 = {1, "Hamlet"s, 3.14}; // deduced: tuple

          Enforcement(實施建議)

          Flag uses where an explicitly specialized type exactly matches the types of the arguments used.

          標(biāo)記顯示定義的類型和實際使用的參數(shù)完全匹配的情況。


          原文鏈接

          https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#t44-use-function-templates-to-deduce-class-template-argument-types-where-feasible


          新書介紹

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

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

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




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

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

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



          瀏覽 27
          點贊
          評論
          收藏
          分享

          手機(jī)掃一掃分享

          分享
          舉報
          評論
          圖片
          表情
          推薦
          <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>
                  国内爱爱视频 | 亚洲免费操大香蕉 | 草逼视频网址 | 日韩三级免费观看 | 精品内射在线无码 |