注册 | 登录 忘记密码? 51cto首页 | 博客 | 论坛 | 招聘
热点文章 用了十年的QQ号,第二次被..
 帮助

tips on c++


2007-06-10 22:56:26
 标签:c++   [推送到技术圈]

[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



    文章评论
 
 

发表评论

昵   称:
验证码:  点击图片可刷新验证码  博客过2级,无需填写验证码
内   容: