Upgrade to Pro — share decks privately, control downloads, hide ads and more …

C++ 11

C++ 11

Minqi Pan

March 26, 2015
Tweet

More Decks by Minqi Pan

Other Decks in Technology

Transcript

  1. 放⼼心使⽤用 • gcc 4.8 以后已经完全⽀支持C++11,最新4.9.2 • clang 3.x 已经完全⽀支持C++11,最新3.6.0 •

    VC 2015 Preview ⼏几乎已经完全⽀支持C++11 • kanbox-web-pub.cm3 ⺫⽬目前不⾏行,gcc才4.1 • 10.101.86.86⺫⽬目前不⾏行,同上
  2. 总算添加了Unicode⽀支持! u8"I'm a UTF-8 string." u"This is a UTF-16 string."

    U"This is a UTF-32 string." u8"This is a Unicode Character: \u2018." u"This is a bigger Unicode Character: \u2018." U"This is a Unicode Character: \U00002018." u8R"XXX(I'm a"raw UTF-8" string.)XXX" uR"*(This is a "raw UTF-16" string.)*" UR"(This is a "raw UTF-32"string.)"
  3. 新增nullptr! 可区分0和(void *)0进⾏行函数重载 导致标准库的⼀一些重写 某些⽅方法返回nullptr⽽而不再返回NULL void foo(char *); void foo(int);

    ! char *pc = nullptr; // OK int *pi = nullptr; // OK bool b = nullptr; // OK. b is false. int i = nullptr; // error ! foo(nullptr); // calls foo(nullptr_t), not foo(int);
  4. 新增强类型枚举(enum class) enum class Enumeration { Val1, Val2, Val3 =

    100, Val4 // = 101 }; enum Enum1; // 上⾯面的不合法,没类型 enum Enum2 : unsigned int; // 合法,明确表⽰示是unsigned int类型 enum class Enum3; // 合法,没说,但是默认是int enum class Enum4 : unsigned int; // 合法 enum Enum2 : unsigned short; // 不合法,已经声明过是int怎么⼜又变成short了?!
  5. 新增关键字static_assert! ⽤用于编译时排错 static_assert((GREEKPI > 3.14) && (GREEKPI < 3.15), "GREEKPI

    is inaccurate!”); ! //类级: template<class T> struct Check { static_assert(sizeof(int) <= sizeof(T), "T is not big enough!"); }; ! //⽅方法级: template<class Integral> Integral foo(Integral x, Integral y) { static_assert(std::is_integral<Integral>::value, "foo() parameter must be an integral type."); }
  6. ⾃自定义字⾯面值后缀 OutputType operator "" _suffix(const char * literal_string); ! OutputType

    some_variable = 1234_suffix; ! template<char...> OutputType operator "" _tuffix(); ! OutputType some_variable = 1234_tuffix; // operator "" _tuffix<'1', '2', '3', '4'>() OutputType another_variable = 2.17_tuffix;