C++11 新特性

    从上个c++版本过去11年了,c11有了更多的特性,使各个模块组装的的更合适。

    “ It now supports lambda expressions, automatic type deduction of objects, uniform initialization syntax(统一初始化语法), delegating constructors(委派构造函数), deleted and defaulted function declarations, nullptr, and most importantly, rvalue references — a feature that augurs a paradigm shift(思考模式的转移) in how one conceives and handles objects(怎样构思和解决类). And that’s just a sample.”

     The C++11 Standard Library was also revamped with new algorithms, new container classes, atomic operations(原子操作数), type traits, regular expressions, new smart pointers(智能指针), async() facility, and of course a multithreading library.

    98版c++时还争辩到下版c++一定要增加GC垃圾回收,并且可能不再支持多线程。but现在看来依然缺少GC功能但是增加包含了一系列的线程库。

    Lambda表达式格式

[capture](parameters)->return-type {body}

举例:

    假设你要计算一个字符串中有多少大写字母。比如“Hello World!”,有2个大写字母,以下的lambda表达式判断哪个字母是大写。每找到一个大写字母,Uppercase自增存放。

int main()
{

   char s[]="Hello World!";

   int Uppercase = 0; //modified by the lambda

   for_each(s, s+sizeof(s), [&Uppercase] (char c) {

    if (isupper(c))

     Uppercase++;

    });

 cout<< Uppercase<<" uppercase letters in: "<< s<<endl;

}

自动类型:

可以应用某些冗长的变量类型替代:vector<int>::const_iterator ci=vi.begin(); 被替代为 

auto ci=vi.begin();
auto x=0; //x has type int because 0 is int
auto c='a'; //char

auto d=0.5; //double

auto national_debt=14400000000000LL;//long long

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值