C++11 学习总结

1、static const size_type npos = -1;

这是一个特殊的值等于最大的值表示的类型size_type。依赖于上下文的确切含义,但人们普遍使用,也可以作为字符串的结束指示符期望字符串索引,或者由函数返回一个字符串索引的错误指示器的功能.

示例
#include <iostream>
#include <bitset>
#include <string>

int main()
{
    // string search functions return npos if nothing is found
    std::string s = "test";
    if(s.find('a') == std::string::npos)
        std::cout << "no 'a' in 'test'
";

    // functions that take string subsets as arguments
    // use npos as the "all the way to the end" indicator
    std::string s2(s, 2, std::string::npos);
    std::cout << s2 << '
';

    std::bitset<5> b("aaabb", std::string::npos, 'a', 'b');
    std::cout << b << '
';
}
输出:
no 'a' in 'test'
st
00011

2、ref

3、move

函数原型:    
    template <class T>
    typename remove_reference<T>::type&& move (T&& arg) noexcept;

    Move as rvalue 
    Returns an rvalue reference to arg. 返回一个arg的右值引用
    
    右值引用的出现就让我们可以取得临时对象的控制权,终于可以修改临时对象了!

参考
http://www.cplusplus.com/reference/utility/move/?kw=move
http://www.cnblogs.com/chezxiaoqiang/archive/2012/10/24/2736630.html

4、lambda 表达式

5、weak_ptr、shared_ptr, unique_ptr 的含义和区别

6、std::bind()

7、待续

原文地址:https://www.cnblogs.com/shark-cf/p/5621274.html