• [C++]C++11新特性


    0. C++11 compiler support shootout

    http://cpprocks.com/c11-compiler-support-shootout-visual-studio-gcc-clang-intel/
    http://msdn.microsoft.com/en-us/library/vstudio/hh567368.aspx

    1. Important Minor Syntax Cleanups

    //Spaces in Template Expressions
    std::vector<std::list<int>>;
    
    //nullptr and std::nullptr_t
    f(0); //calls f(int)
    f(NULL); //calls f(int) if NULL is 0,ambiguous otherwise
    f(nullptr); //calls f(void*)

    2. Automatic Type Deduction with auto

    auto i = 42; // i has type int
    //
    std::vector<std::string> v;
    auto pos = v.begin(); // std::vector<std::string>::iterator
    //
    auto func = [](int x)->bool {
        //....
    }; // the type of lambda taking an int and returnin a bool

    3. Uniform Initialization and Initializer Lists

    /* not support in vs2012 */
    int values[] { 1, 2,3 };
    std::vector<int> v {2, 3, 5, 7,11, 13, 17};
    std::vector<std::string> cities {
    "Berlin", "New York", "London", "Braunschweig", "Cairo", "Cologne"
    };
    
    //std::initializer_list<>
    class P {
    public:
        P(int,int);
        P(std::initializer_list<int>);
    };
    //
    P p(77,5); //calls P::P(int,int)
    P q{77,5}; //calls P::P(initializer_list)
    P r{77,5,42}; //calls P::P(initializer_list)
    P s={77,5}; //calls P::P(initializer_list)

    4. Range-Based for Loops

    /*
    for ( decl :coll ){
        statement
    }
    */
    std::vector<int> v;
    for(auto& item : v) {
        //....
    }

  • 相关阅读:
    TP6|TP5.1 PHPoffice导出|导入
    centOS 7 环境搭建之安装 Redis
    centOS 7 环境搭建之安装 MySQL
    双向循环链表(DoubleLoopLinkList)
    双向链表(DoubleLinkList)
    可执行程序的编译过程
    C语言文件操作
    C语言跨平台时间操作计算时间差
    C语言线程安全问题
    C++类型双关
  • 原文地址:https://www.cnblogs.com/lambdatea/p/3377986.html
Copyright © 2020-2023  润新知