IT技术博客大学习 共学习 共进步

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

酷壳 - CoolShell.cn 2011-08-19 23:00:52 浏览 3,483 次
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. C语言中史上最愚蠢的Bug (阅读 7,946)
  2. C的那些事儿 (阅读 6,304)
  3. C 语言的前世今生 (阅读 6,103)
  4. C语言结构体里的成员数组和指针 (阅读 6,083)
  5. 为什么C语言需要函数声明 (阅读 5,625)
  6. C语言的那些个关键字们 (阅读 5,503)
  7. 周末闲谈:C and C++, why use c++? (阅读 4,363)
  8. C#和C++混合编程的一些tips (阅读 4,304)
  9. Effective C++ 3rd 的一点评论 (阅读 3,265)