C++11 中值得关注的几大变化(详解)

酷壳 - CoolShell.cn 2011-08-19 23:00:52 累计浏览 3,819 次
V>
//are all of the elements positive?
all_of(first, first+n, ispositive()); //false
//is there at least one positive element?
any_of(first, first+n, ispositive());//true
// are none of the elements positive?
none_of(first, first+n, ispositive()); //false

使用新的copy_n()算法,你可以很方便地拷贝数组。

1
2
3
4
5
#include <algorithm>
int source[5]={0,12,34,50,80};
int target[5];
//copy 5 elements from source to target
copy_n(source,5,target);

使用 iota() 可以用来创建递增的数列。如下例所示:

1
2
3
4
5
include <numeric>
int a[5]={0};
char c[3]={0};
iota(a, a+5, 10); //changes a to {10,11,12,13,14}
iota(c, c+3, 'a'); //{'a','b','c'}

总之,看下来,C++11 还是很学院派,很多实用的东西还是没有,比如: XML,sockets,reflection,当然还有垃圾回收。看来要等到C++ 20了。呵呵。不过C++ 11在性能上还是很快。参看 Google’s benchmark tests。原文还引用Stroustrup 的观点:C++11 是一门新的语言――一个更好的 C++。

如果把所有的改变都列出来,你会发现真多啊。我估计C++ Primer那本书的厚度要增加至少30%以上。C++的门槛会不会越来越高了呢?我不知道,但我个人觉得这门语言的确是变得越来越令人望而却步了。(想起了某人和我说的一句话――学技术真的是太累了,还是搞方法论好混些?)

(全文完)

同分类推荐文章

  1. NGINX 1.31.7: Native GeoIP2 support, HTTP/2 priorities, and QUIC improvements (2026-11-13 23:40:02)
  2. 说说广场 API 0.31.0 版的调用代码说明 (2026-11-13 19:10:02)
  3. NGINX Routing on HTTP Request Body (2026-10-27 14:10:42)

查看更多 后端 文章 →

建议继续学习

  1. 如何成为Python高手 (累计阅读 55,544)
  2. 为什么Lisp语言如此先进?(译文) (累计阅读 6,770)
  3. 函数式编程很难,这正是你要学习它的原因 (累计阅读 5,649)
  4. Underscore.js-精巧而强大实用功能库 (累计阅读 5,581)
  5. 使用array_reduce降维 (累计阅读 5,362)
  6. stream.js :一个新的JavaScript数据结构 (累计阅读 5,239)
  7. JavaScript的5种调用函数的方法 (累计阅读 4,774)
  8. 看来看去都是看数学书 (累计阅读 4,353)
  9. 为什么我喜欢Lisp语言 (累计阅读 4,269)
  10. 闭包漫谈(从抽象代数及函数式编程角度) (累计阅读 4,072)