[1]Use templates to express algorithms that apply to many argument types;
[2]Use templates to express containers;
[3]Provide specializations for containers of pointers to minimize code size;
[4]Always declare the general form of a template before specializations;
[5]Declare a specialization before its use;
[6]Minimize a template definition's dependence on its instantiation contexts;
[7]Define every specialization you declare;
[8]Consider if a template needs specializations for C-style strings and arrays;
[9]Parameterize with a policy object;
[10]USe specialization and overloading to provide a single interface to implementations of the same concept for different types;
[11]Provide a simple interface for simple cases and use overloading and default arguments to express less commom cases;
[12]Debug concrete examples before generalizing to a template;
[13]Remember to export template definitions that need to be accessible from other translation units;
[14]Seperately compile large templates and templates with nontrival context dependencies;
[15]Use templates to express conversions but define those conversions very carefully;
[16]Where necessary,constrain template arguments using a constraint() member function;
[17]Use explicit instantiation to minimize compile time and link time;
[18]Prefer a template over derived classes when run-time efficiency is at a premium;
[19]Prefer derived classes over a template if adding new variants without recompilation is important;
[20]Prefer a template over derived classes when no common base can be defined;
[21]Prefer a template over derived classes when bulit-in types and structures with compatibility constraints are important;
tips on c++
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章
Linux基本操作命令
wbzjacky
2019-02-24 13:12:38
真實的模擬***綜合實驗
wbzjacky
2019-02-24 13:12:37
2020 重学C++ 重构你的C++知识体系
wy53780
2020-04-23 14:13:15
现代C++实战30讲
wy53780
2020-04-23 13:58:44
node遇上c++ --- 愛情來的太快(一) (沒有文章)
sewerganger
2019-02-24 22:55:07
近期前端發展計劃
Ashleysweetie
2019-02-24 22:32:41
Xcode與C++之遊戲開發:Pong遊戲
優惠碼優惠
2019-02-24 19:41:23
如果同事暗中傷害你,應該怎麼辦?
這個饅頭有餡
2019-02-24 13:59:08
職場中,抱怨越多的員工,越被領導瞧不起!
這個饅頭有餡
2019-02-24 13:59:08
老程序員被裁,應屆生卻能月薪 1.3 萬?這你能忍?
前端高達
2019-02-24 13:48:04
遇到到處蹭吃卻從不請客吃飯的主怎麼辦?
樑軍年
2019-02-24 13:26:35
高標準機房綜合配線安裝
wbzjacky
2019-02-24 13:12:38
IPsec ***實驗
wbzjacky
2019-02-24 13:12:37