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

推荐订阅源

酷 壳 – CoolShell
酷 壳 – CoolShell
H
Hacker News: Front Page
P
Palo Alto Networks Blog
T
ThreatConnect
Apple Machine Learning Research
Apple Machine Learning Research
博客园_首页
T
True Tiger Recordings
P
Privacy & Cybersecurity Law Blog
B
Blog
IT之家
IT之家
Last Week in AI
Last Week in AI
F
Full Disclosure
Hacker News: Ask HN
Hacker News: Ask HN
C
Comments on: Blog
Microsoft Azure Blog
Microsoft Azure Blog
C
Cybersecurity and Infrastructure Security Agency CISA
Microsoft Security Blog
Microsoft Security Blog
博客园 - 【当耐特】
N
News and Events Feed by Topic
NISL@THU
NISL@THU
腾讯CDC
雷峰网
雷峰网
Security Latest
Security Latest
李成银的技术随笔
M
Microsoft Research Blog - Microsoft Research
L
LangChain Blog
L
Lohrmann on Cybersecurity
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
C
Check Point Blog
Y
Y Combinator Blog
Recent Announcements
Recent Announcements
博客园 - Franky
N
News | PayPal Newsroom
V
V2EX
A
About on SuperTechFans
The Register - Security
The Register - Security
月光博客
月光博客
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Google Online Security Blog
Google Online Security Blog
MyScale Blog
MyScale Blog
Cisco Talos Blog
Cisco Talos Blog
Vercel News
Vercel News
WordPress大学
WordPress大学
C
Cyber Attacks, Cyber Crime and Cyber Security
The Hacker News
The Hacker News
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
爱范儿
爱范儿
A
Arctic Wolf
L
LINUX DO - 最新话题
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More

博客园 - bluesoul

删除utorrent广告栏 Win10浏览器Spartan无法全屏 - bluesoul 2006,来晚了~哈哈 VC6下使用STL注意:不要让内存分配失败导致您的旧版 STL 应用程序崩溃 [消息]C++ Connections 在拉斯维加斯召开年会 找到一篇有关A*算法文章,不错~收藏 通用SQL数据库查询语句精华使用简介(收藏) 找到几篇有关delphi vcl消息机制的文章,收藏先~ Java的另类工具 【转帖】[推荐][注意]英语赞美30句 [导入]Herb Sutter又有新作《C++ Coding Standards》 - bluesoul 【转帖】经常要浏览英文网址[推荐] 【转帖]】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!

随手写的,请随意砸