1 / 170

次期規格 解禁目前!

C++0x 総復習 Boost . 勉強会 #5 名古屋. 次期規格 解禁目前!. ※ この資料の末尾に簡単な補足情報をまとめていますので 、 用語 等が不明な場合などはそちらを参照してください。. Boost. 勉強会 #5 名古屋 ( 2011-05-14 ). C++0x 総復習. C++0x 正式リリース目前!. C++0x と呼 称されてきた次期 C++ の国際規格 (ISO/IEC 14882) も最終草案 (FDIS) が作成され、いよいよ正式リリースの日が迫ってまいりました。. C++0x という名 の 終わり.

beulah
Télécharger la présentation

次期規格 解禁目前!

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. C++0x総復習 Boost.勉強会 #5 名古屋 次期規格解禁目前! ※この資料の末尾に簡単な補足情報をまとめていますので、 用語等が不明な場合などはそちらを参照してください。

  2. Boost.勉強会 #5 名古屋 (2011-05-14 ) C++0x総復習

  3. C++0x正式リリース目前! • C++0xと呼称されてきた次期C++の国際規格(ISO/IEC 14882)も最終草案(FDIS)が作成され、いよいよ正式リリースの日が迫ってまいりました。 C++0x総復習 Boost.勉強会 #5 名古屋

  4. C++0x という名の終わり • 正式リリースされればC++0xは旧名となり、そしておそらくはC++11と呼称されるようになります。 C++0x総復習 Boost.勉強会 #5 名古屋

  5. C++0xの最新かつ最期の復習 • 細かな typo の修正等を除けば原則的に正式版とほぼ同一内容(※)となるFDIS(N3290)をベースにC++0xをおさらいしましょう! C++0x総復習 Boost.勉強会 #5 名古屋

  6. お断り • FDISと正式版は原則的にほぼ同一の内容になるといは言え、その保証があるわけではなく、正式版と差異があったらごめんなさい。 • この資料でのセクション(§)およびパラグラフ(¶)の表記はその機能の主要な記述がある箇所であって、実際には他のいくつもの箇所にその機能の記述が散らばっていることが多々あります。 C++0x総復習 Boost.勉強会 #5 名古屋

  7. C++0x総復習 §1General

  8. §1.10 Multi-threaded executions and data races • マルチスレッド実行が言語仕様上、意識されるようになり、マルチスレッドで動作する際の挙動が定義されました。 • 参考情報: • C++0x Memory Model 第0回 - メモリモデルとは何かhttp://d.hatena.ne.jp/Cryolite/20101226#p1 • C++0x Memory Model 第1回 - 1.9 Program executionhttp://d.hatena.ne.jp/Cryolite/20101228#p1 C++0x総復習 Boost.勉強会 #5 名古屋

  9. C++0x総復習 §2Lexical conventions

  10. §2.3 Character sets • ユニバーサルキャラクタ名の制限緩和 const char16_t * str16 = u"\u9053\u5316\u5E2B"; // 道化師 const char32_t * str32 = U"\U00009053\U00005316\U00005E2B"; // 道化師 C++0x総復習 Boost.勉強会 #5 名古屋

  11. §2.11 Identifiers • 処理系定義の文字を識別子として使うことが許されるようになりました。 • これにより処理系によっては日本語識別子が使えるようになります。 C++0x総復習 Boost.勉強会 #5 名古屋

  12. §2.11 Identifiers • 特別な意味を持つ識別子が予約されました。 • override • オーバーライド関数であることの明示。 • final • [クラスの継承禁止]および[関数のオーバーライド禁止]。 • ※特別な識別子であって予約語ではない点に注意。 C++0x総復習 Boost.勉強会 #5 名古屋

  13. §2.12 Keywords • 予約語が増えました。 • 予約語一覧(橙色が新しい予約語) • alignasalignof asm auto bool break case catch char char16_tchar32_t class const const_cast constexpr continue decltype default delete do double dynamic_cast else enum explicit export extern false float for friend goto if inline int long mutable namespace new noexceptnullptr operator private protected public register reinterpret_cast return short signed sizeof static static_assert static_cast struct switch template this thread_local throw true try typedef typeid typename union unsigned using virtual void volatile wchar_t while C++0x総復習 Boost.勉強会 #5 名古屋

  14. §2.12 Keywords • alignas • アライメントの指定 • alignof • アライメントの取得 • char16_t • UNICODE(UTF-16)用の文字型 • char32_t • UNICODE(UTF-32)用の文字型 • constexpr • 定数式 C++0x総復習 Boost.勉強会 #5 名古屋

  15. §2.12 Keywords • decltype • 式から型を取得/指定 • noexcept • 例外送出しないことの明示(指定)と判定(operator) • nullptr • ナルポインタリテラル • static_assert • コンパイル時assert • thread_local • スレッドローカルストレージ C++0x総復習 Boost.勉強会 #5 名古屋

  16. §2.14 Literals • 追加されたサフィックスとプレフィックス • long long 型用の LLサフィックス • cha16_t 型用の uプレフィックス • cha32_t 型用の Uプレフィックス • UTF-8な文字列用の u8プレフィックス • cha16_t 型な文字列用の uプレフィックス • cha32_t 型な文字列用の Uプレフィックス • raw 文字列用の Rプレフィックス C++0x総復習 Boost.勉強会 #5 名古屋

  17. §2.14.5 String literals • raw文字列リテラル const char *p = R"(a\ b c)"; // == "a\\\nb\nc" R"a( )\ a" )a" // == "\n)\\\na\"\n" R"(??)" // == "\?\?" C++0x総復習 Boost.勉強会 #5 名古屋

  18. §2.14.5 String literals • raw文字列リテラル • 詳細なかなり珍妙な仕様になっているので要注意。 • 初期の提案では ( ) でなく [ ] が使われることになっていた為、Web上の多くのraw文字列リテラルに関する情報は[ ]のままになっているので注意。 • 参考情報: • http://d.hatena.ne.jp/haru-s/20081205 C++0x総復習 Boost.勉強会 #5 名古屋

  19. §2.14.5 String literals • 型の異なる文字列リテラルのコンパイル時の結合規則が定義されました。 • 片方にエンコーディングプレフィックスがついていない場合、もう片方のエンコーディングプレフィックスに従う。 • UTF-8文字列リテラルがワイド文字列リテラルと結合するのは不適格。 • それ以外の組み合わせは処理系依存。 C++0x総復習 Boost.勉強会 #5 名古屋

  20. §2.14.7 Pointer literals • ポインタリテラル • std::nullptr_t 型の nullptr • 今後は NULL より nullptrを使いましょう! C++0x総復習 Boost.勉強会 #5 名古屋

  21. §2.14.8 User-Defined literals • ユーザー定義リテラル long double operator ""_w(long double); std::string operator ""_w(const char16_t*, size_t); unsigned operator ""_w(const char*); int main() { 1.2_w; // calls operator "" _w(1.2L) u"one"_w; // calls operator "" _w(u"one", 3) 12_w; // calls operator "" _w("12") "two"_w; // error: no applicable literal operator } C++0x総復習 Boost.勉強会 #5 名古屋

  22. §2.14.8 User-Defined literals • ユーザー定義リテラル • 日時リテラル、位置情報リテラル、2進整数リテラル等々、自由にリテラルをユーザー定義できます。 • …constexpr で十分じゃないか!という声もありますがw C++0x総復習 Boost.勉強会 #5 名古屋

  23. C++0x総復習 §3Basic concepts

  24. §3.9.1 Fundamental types • 最大の整数型として long long int型が導入されました。 • 例によって規格上は最大の整数型としか定義されておらず何バイト(何ビット)の値なのかは処理系定義となります。 • short intや long intと同様に signed/unsigned 修飾したり int を省略したりできます。 C++0x総復習 Boost.勉強会 #5 名古屋

  25. §3.10 Lvalues and rvalues • 右辺値/左辺値の定義がより詳細になりました。 式 expression ※便宜上の訳語で正式な訳語でも一般的な訳語でもありません。 汎左辺値※ glvalue 右辺値 rvalue 左辺値 lvalue 純右辺値※ prvalue 末期値※ xvalue C++0x総復習 Boost.勉強会 #5 名古屋

  26. §3.10 Lvalues and rvalues • 左辺値 lvalue ( “left-hand” value ) • 関数あるいはオブジェクト。 • 末期値 xvalue ( “eXpiring” value ) • 生存期間の終了するオブジェクトの参照。 • 右辺値参照の結果。 • 汎左辺値 glvalue ( “generalized” lvalue ) • 左辺値(lvalue)あるいは末期値(xvalue)。 • 右辺値 rvalue ( “right-hand” value ) • 末期値(xvalue)、一時オブジェクトあるいはそのサブオブジェクト、オブジェクトに関連づいていない値。 • 純右辺値 prvalue ( “pure” rvalue ) • 末期値(xvalue)でない右辺値(rvalue)。 C++0x総復習 Boost.勉強会 #5 名古屋

  27. §3.11 Alignment • アライメントがより詳細に定義されました。 • 処理系がサポートする最大のアライメント: alignof(std::max_align_t) • アライメントは std::size_t 型の値で示される。 C++0x総復習 Boost.勉強会 #5 名古屋

  28. C++0x総復習 §4Standard conversions

  29. §4Standard conversions • 主に右辺値/左辺値、char16_t/char32_t、std::nullptr_t、unscoped enumeration 型に関連した trivial な修正。 • std::nullptr_t 型の値をboolに変換した場合はfalseになる。(§4.12) • Integer conversion rankの定義(§4.13) C++0x総復習 Boost.勉強会 #5 名古屋

  30. C++0x総復習 §5Expressions

  31. §5.1.2 Lambda expressions • ラムダ式が導入されました。 #include <algorithm> #include <cmath> void abssort(float *x, unsigned N) { std::sort(x, x + N, [](float a, float b) { return std::abs(a) < std::abs(b); }); } C++0x総復習 Boost.勉強会 #5 名古屋

  32. §5.1.2 Lambda expressions int a = 42; auto b = [a](){ return a; }; // b 内の a はコピー auto c = [=](){ return a; }; // b と等価 int d = b(); // → 42 int e = [a](int x){ return a +x; }(d); // そのまま呼び出し auto f = [&a](){ return a; }; // b と違い f 内の a は参照 auto g = [&](){ return a; }; // f と等価 a = 24; int h = b(); // → 42 int i = f(); // → 24 auto j = [a,&d](int x){ return a +d +x; }; auto k = [=,&d](int x){return a +d +x; }; // j と等価 auto l = [&]()->int{return a; }; // g と等価(戻り型の明示) C++0x総復習 Boost.勉強会 #5 名古屋

  33. §5.3.6 Alignof • 型からアライメントを取得できる alignof が導入されました。 std::size_t int_alignment = alignof(int); C++0x総復習 Boost.勉強会 #5 名古屋

  34. §5.3.7 noexcept operator • 式が例外を送出し得るかどうかを取得できる noexcept operator が導入されました。 bool is_noexcept_expr = noexcept(a.swap(b)); C++0x総復習 Boost.勉強会 #5 名古屋

  35. §5.19 Constant expressions • constexpr が導入されました。 constexpr const int* addr(const int& ir) { return &ir; } // OK static const int x = 5; constexpr const int* xp = addr(x); // OK: (const int*)&(const int&)x is an // address constant expression constexpr const int* tp = addr(5); // error, initializer for constexpr variable not a constant // expression; (const int*)&(const int&)5 is not a constant // expression because it takes the address of a temporary C++0x総復習 Boost.勉強会 #5 名古屋

  36. §5.19 Constant expressions int x; // not constant struct A { constexpr A(bool b) : m(b?42:x) { } int m; }; constexpr int v = A(true).m; // OK: constructor call initializes // m with the value 42 after substitution constexpr int w = A(false).m; // error: initializer for m is // x, which is non-constant C++0x総復習 Boost.勉強会 #5 名古屋

  37. C++0x総復習 §6Statements

  38. §6.5.4 The range-based for statement • 範囲ベースfor文が導入されました。 int array[5] = { 1, 2, 3, 4, 5 }; for(int& x : array) x *= 2; C++0x総復習 Boost.勉強会 #5 名古屋

  39. §6.7 Declaration statement ¶4 • マルチスレッド実行時のグローバル変数およびstatic変数の初期化ルールが定義され、ユーザーコーディングによる初期化の排他処理は不要になりました。 C++0x総復習 Boost.勉強会 #5 名古屋

  40. C++0x総復習 §7Declarations

  41. §7 Declarations¶4 • static_assert が導入されました。 static_assert(sizeof(long) >= 8, "64-bit code generation required for this library."); C++0x総復習 Boost.勉強会 #5 名古屋

  42. §7.1.1 Storage class specifiers • 記憶域種別指定子としての autoが削除されました。 • 型推論の機能として使う為。 • 概念としての§3.7.3 Automatic storage duration が無くなったわけではないので注意。 C++0x総復習 Boost.勉強会 #5 名古屋

  43. §7.1.1 Storage class specifiers • 記憶域種別指定子としての thread_localが導入されました。 • この記憶域種が指定された変数はスレッドローカルストレージに格納される値となり、スレッド別に固有の値を持つことができます。 C++0x総復習 Boost.勉強会 #5 名古屋

  44. §7.1.6.2 Simple type specifiers • 式から型を指定できるdecltypeが導入されました。 const int&& foo(); int i; struct A { double x; }; const A* a = new A(); decltype(foo()) x1 = i; // type is const int&& decltype(i) x2; // type is int decltype(a->x) x3; // type is double decltype((a->x)) x4 = x3; // type is const double& C++0x総復習 Boost.勉強会 #5 名古屋

  45. §7.1.6.4 auto specifier • 型を推論してくれるauto型識別子が導入されました。 auto x = 5; // OK: x has type int const auto *v = &x, u = 6; // OK: v has type const int*, u has type const int static auto y = 0.0; // OK: y has type double auto int r; // error: auto is not a storage-class-specifier C++0x総復習 Boost.勉強会 #5 名古屋

  46. §7.2 Enumeration declarations • 正式に最後の列挙子の末尾にカンマをつけてもいいことになりました。 • C++03の規格上は許されてなかったようです。 enum number { zero, one, two, // ←このカンマ }; C++0x総復習 Boost.勉強会 #5 名古屋

  47. §7.2 Enumeration declarations • scoped enumeration が導入され従来の enum は unscoped enumeration と呼ばれるようになりました。 • 名前の通り、 scoped enumeration はスコープを持ち列挙子はそのscoped enumeration 型のスコープに所属し、名前空間を汚しません。 • int 固定だった enum の内部表現型に任意の整数型を指定できるようになりました。 • enum先行宣言ができるようになりました。 • この場合、内部表現型の指定は必須となる。 C++0x総復習 Boost.勉強会 #5 名古屋

  48. §7.2 Enumeration declarations // unscoped enumeration enum color { red, yellow, green=20, blue }; // scoped enumeration enumclassscoped_color { red, yellow, green=20, blue }; // opaque-enum-declaration enumcolor_byte:unsigned char; // base type is unsigned char enumcolor_byte:unsigned char { red, yellow, green=20, blue }; C++0x総復習 Boost.勉強会 #5 名古屋

  49. §7.2 Enumeration declarations • scoped enumerationの値と整数値は比較できません。 • scoped enumeration の値を整数型の変数に代入することは可能です。 • scoped enumeration の変数に整数値を代入することできません。 • 異なる scoped enumeration 型の値を比較、代入等をすることはできません。 C++0x総復習 Boost.勉強会 #5 名古屋

  50. §7.3.1 Namespace definition • inline namespace が導入されました。 namespace a { inline namespace b { int c; } } int d = a::b::c; int e = a::c; C++0x総復習 Boost.勉強会 #5 名古屋

More Related