欧美一级特黄大片做受成人-亚洲成人一区二区电影-激情熟女一区二区三区-日韩专区欧美专区国产专区

C++中為什么不要過度參數(shù)化

這篇文章主要介紹“C++中為什么不要過度參數(shù)化”,在日常操作中,相信很多人在C++中為什么不要過度參數(shù)化問題上存在疑惑,小編查閱了各式資料,整理出簡單好用的操作方法,希望對大家解答”C++中為什么不要過度參數(shù)化”的疑惑有所幫助!接下來,請跟著小編一起來學習吧!

創(chuàng)新互聯(lián)公司專業(yè)為企業(yè)提供沈陽網(wǎng)站建設(shè)、沈陽做網(wǎng)站、沈陽網(wǎng)站設(shè)計、沈陽網(wǎng)站制作等企業(yè)網(wǎng)站建設(shè)、網(wǎng)頁設(shè)計與制作、沈陽企業(yè)網(wǎng)站模板建站服務(wù),10年沈陽做網(wǎng)站經(jīng)驗,不只是建網(wǎng)站,更提供有價值的思路和整體網(wǎng)絡(luò)服務(wù)。

T.61:不要過度參數(shù)化成員(SCARY)

Reason(原因)

A member that does not depend on a template parameter cannot be used except for a specific template argument. This limits use and typically increases code size.

不依賴于模板參數(shù)的成員無法使用,特定的模板參數(shù)除外。這會限制使用并通常會增加代碼大小。

Example, bad(反面示例)

template<typename T, typename A = std::allocator{}>
   // requires Regular<T> && Allocator<A>
class List {
public:
   struct Link {   // does not depend on A
       T elem;
       T* pre;
       T* suc;
   };

   using iterator = Link*;

   iterator first() const { return head; }

   // ...
private:
   Link* head;
};

List<int> lst1;
List<int, My_allocator> lst2;

This looks innocent enough, but now Link formally depends on the allocator (even though it doesn't use the allocator). This forces redundant instantiations that can be surprisingly costly in some real-world scenarios. Typically, the solution is to make what would have been a nested class non-local, with its own minimal set of template parameters.

代碼看起來足夠正確,但是現(xiàn)在Link形式上依賴于分配器(即使它沒有使用分配器)。這會引發(fā)多余的例示,而這種例示在某些現(xiàn)實流程中可能會帶來令人驚訝的高成本。通常的解決方案是讓本來的嵌套類別弄成非局部的,同時它的成員只擁有最少的模板參數(shù)。

template<typename T>
struct Link {
   T elem;
   T* pre;
   T* suc;
};

template<typename T, typename A = std::allocator{}>
   // requires Regular<T> && Allocator<A>
class List2 {
public:
   using iterator = Link<T>*;

   iterator first() const { return head; }

   // ...
private:
   Link* head;
};

List<int> lst1;
List<int, My_allocator> lst2;

Some people found the idea that the Link no longer was hidden inside the list scary, so we named the technique SCARY. From that academic paper: "The acronym SCARY describes assignments and initializations that are Seemingly erroneous (appearing Constrained by conflicting generic parameters), but Actually work with the Right implementation (unconstrained bY the conflict due to minimized dependencies)."

有些人會發(fā)現(xiàn)Link不再被list隱藏,因此我們稱這種技術(shù)為SCARY。根據(jù)大學論文:“SCARY這個縮寫描述了一些看起來錯誤(看起來被沖突的參數(shù)約束),但實際上可以和正確的實現(xiàn)一起工作(由于最小化的依賴關(guān)系而不會被沖突所限制)的賦值和初始化?!?/p>

Enforcement(實施建議)

  • Flag member types that do not depend on every template argument

  • 標記不依賴于任何模板參數(shù)的成員

  • Flag member functions that do not depend on every template argument

  • 標記不依賴于任何模板參數(shù)的成員的成員函數(shù)。

到此,關(guān)于“C++中為什么不要過度參數(shù)化”的學習就結(jié)束了,希望能夠解決大家的疑惑。理論與實踐的搭配能更好的幫助大家學習,快去試試吧!若想繼續(xù)學習更多相關(guān)知識,請繼續(xù)關(guān)注創(chuàng)新互聯(lián)網(wǎng)站,小編會繼續(xù)努力為大家?guī)砀鄬嵱玫奈恼拢?/p>

網(wǎng)站標題:C++中為什么不要過度參數(shù)化
當前路徑:http://aaarwkj.com/article30/iihiso.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供動態(tài)網(wǎng)站、網(wǎng)站內(nèi)鏈、微信小程序、靜態(tài)網(wǎng)站、品牌網(wǎng)站制作手機網(wǎng)站建設(shè)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

成都網(wǎng)頁設(shè)計公司
亚洲中文永久免费视频| 亚洲中文字幕第三页在线观看| 日本道欧美一区二区aaaa| 日韩精品一区福利合集| 97全国免费观看视频| 日韩精品一区二区三区人妻视频 | 青青草青青草在线观看视频| 日韩成人手机视频在线观看 | 人人妻人人澡人人妻| 国产麻豆剧传媒国产av| 欧美激情韩国三级日本| 国产亚洲精品免费视频| 日本一区二区三区伦理| av中文字幕在线电影| 亚洲小视频免费在线观看| 亚洲国产精品福利在线| 日韩深夜成人在线视频| 日本韩国亚洲欧美一区二区| 亚洲激情在线观看一区| 亚洲一区二区精品免费视频| 精品人妻一区三区蜜桃| 狠狠综合久久av一区二区大宝| 亚洲欧美激情国产综合久久 | 国产欧美成人精品第一区| 中文字幕高清一区二区三区| 欧美一区二区三区情色| 人妻勾引中文字幕在线视频| 国产精品欧美久久久久无| 中文字幕日本乱码精品久久| 免费国产三级在线观看| 黄色av免费无毒网站| 91大神黑丝美女洗澡| 蜜臀av人妻一区二区三区 | 国产三级三级精品久久| 国产精品日韩av一区二区| 日韩在线中文字幕一区| 亚洲天堂男人的天堂狠狠操| 欧美一区二区欧美精品| 最新人妻少妇精品中文字幕视频| 夜夜嗨精品免费视频播放| 最新日韩中文字幕在线播放|