惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

B
Blog RSS Feed
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Google Online Security Blog
Google Online Security Blog
Hugging Face - Blog
Hugging Face - Blog
博客园 - Franky
Last Week in AI
Last Week in AI
MongoDB | Blog
MongoDB | Blog
T
Tailwind CSS Blog
云风的 BLOG
云风的 BLOG
Vercel News
Vercel News
博客园 - 三生石上(FineUI控件)
腾讯CDC
The GitHub Blog
The GitHub Blog
V
Visual Studio Blog
N
News | PayPal Newsroom
M
MIT News - Artificial intelligence
C
CERT Recently Published Vulnerability Notes
Apple Machine Learning Research
Apple Machine Learning Research
雷峰网
雷峰网
A
Arctic Wolf
The Cloudflare Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
C
Cyber Attacks, Cyber Crime and Cyber Security
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
AI
AI
S
Security @ Cisco Blogs
aimingoo的专栏
aimingoo的专栏
Cloudbric
Cloudbric
爱范儿
爱范儿
罗磊的独立博客
Y
Y Combinator Blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Attack and Defense Labs
Attack and Defense Labs
Webroot Blog
Webroot Blog
T
Threatpost
T
Threat Research - Cisco Blogs
Cisco Talos Blog
Cisco Talos Blog
Recorded Future
Recorded Future
Security Latest
Security Latest
P
Proofpoint News Feed
www.infosecurity-magazine.com
www.infosecurity-magazine.com
I
Intezer
H
Heimdal Security Blog
Blog — PlanetScale
Blog — PlanetScale
S
Securelist
Forbes - Security
Forbes - Security
Application and Cybersecurity Blog
Application and Cybersecurity Blog
WordPress大学
WordPress大学
Engineering at Meta
Engineering at Meta
H
Hackread – Cybersecurity News, Data Breaches, AI and More

博客园 - bluesoul

删除utorrent广告栏 Win10浏览器Spartan无法全屏 2006,来晚了~哈哈 VC6下使用STL注意:不要让内存分配失败导致您的旧版 STL 应用程序崩溃 [消息]C++ Connections 在拉斯维加斯召开年会 找到一篇有关A*算法文章,不错~收藏 通用SQL数据库查询语句精华使用简介(收藏) 找到几篇有关delphi vcl消息机制的文章,收藏先~ Java的另类工具 【转帖】[推荐][注意]英语赞美30句 [导入]Herb Sutter又有新作《C++ Coding Standards》 【转帖】经常要浏览英文网址[推荐] 【转帖]】C++资源之不完全导引 [上] [下] 原作者:曾毅 陶文 辞职了!为了触摸不到的明天~~~~~~~~ 感谢dudu斑竹的努力!谢谢你添加的界面模板,很漂亮! 个人喜好,无此好者切勿接近!谢先! [导入]Herb Sutter 又要出新书--《Exceptional C++ Style》啦! 建自己的小屋真辛苦啊?!·##¥ 注册了,还不知道怎么样用才好?欢迎大家出点子
Thinking On 《Imperfect C++》--(一)
bluesoul · 2006-01-11 · via 博客园 - bluesoul

最近在看一本C++方面的书,《Imperfect C++: Practical Solutions for Real-Life Programming》作者Matthew Wilson,看得很慢,关键是很多东西以前从未有过深入思考,而现在几乎是把每个细节都再三思索,所以看得很累。此书的中文版已由荣耀先生翻译,可以到荣耀先生的个人主页去看看http://www.royaloo.com/books/books.htm,那儿有很多更详细的内容。
Imperfect C++中文版图片
刚看到第一章第2节:Compile-Time Contracts: Constraints 编译期契约:约束),作者Matthew Wilson列出了C++语言的一个Imperfection。

Imperfection: C++ does not provide direct support for constraints
(C++没有直接支持约束)


紧跟着作者讨论了数个相关例子:
1) must_have_base()

2) must_be_subscriptable()


3) must_be_subscriptable_as_decayable_pointer()
.................

作者列出了一系列的代码片断,涉及到C++ template ,template specialization和partial specialization等一系列的技巧,为的就是在编译期间由编译器充当判断工具,而不损失运行期间的效率。可是遗憾的是编译器产生的错误信息大多让人摸不着头脑,更由于很多编译器没有完全符合C++标准,很多代码无法通过编译,或者产生了错误的,你不想要的信息。

以我个人的观点来讲:
1)因为C++语言没有直接支持约束,所以是否使用库来解决这个问题呢?
2)作者也提到了template meta-programming (TMP) (模板元编程),作者它与Constraints(约束)相比更复杂,而《Mordern C++ Design》一书的作者提出的policy和traits就更是在更高的层次上了,所有这些都有利有弊,并没有一个完美的解决方案,而且代码重用很难,在项目中有多少地方能够用到?到什么层次?解决什么问题?这些都无法预料~
3)相比其他C#,Jave等高级语言,才C++更适合系统级,和对效率很苛刻的环境,是否有必要在代码中加入如此显得混乱的代码,而且为了支持手头的Constraints需求而写的这些代码必须要有详细的解释,否则很难读懂它们到底是干什么的?

个人觉得c++ STL写的的确不错,而且boost库也不错,但并不是所有boost库里的东西都好,在一个项目中如果要使用它们,必须慎重评估,如果不理想,还是保持冷静,不要盲目。毕竟C++ is imperfect!

随手写的,请随意砸