Scott Effective C++ C++ C++ Roger Orr OR/2 ISO C++ Effective Modern C++ C++ C++ Scoot 42 Bart Vandewoestyne C++ C++ Scott Effective Modern C++ Damien

Similar documents
CC213

C++ 程式設計

1 C++ 2 Bjarne Stroustrup C++ (system programming) 6 (infrastructure) C++ 7 Herb Sutter 8 C++ (efficiency) (flexibility) 9 (abstraction) (productivity

Microsoft Word - 物件導向編程精要.doc

untitled

新版 明解C++入門編

C C C The Most Beautiful Language and Most Dangerous Language in the Programming World! C 2 C C C 4 C Project 30 C Project 3 60 Project 40

FY.DOC

C++11概要 ライブラリ編

Fun Time (1) What happens in memory? 1 i n t i ; 2 s h o r t j ; 3 double k ; 4 char c = a ; 5 i = 3; j = 2; 6 k = i j ; H.-T. Lin (NTU CSIE) Referenc

Strings

Microsoft Word - ch04三校.doc

c_cpp

1 Framework.NET Framework Microsoft Windows.NET Framework.NET Framework NOTE.NET NET Framework.NET Framework 2.0 ( 3 ).NET Framework 2.0.NET F

Microsoft PowerPoint - plan08.ppt

C 1

第 三 条 基 金 管 理 人 基 金 托 管 人 和 基 金 份 额 持 有 人 的 权 利 义 务, 依 照 本 法 在 基 金 合 同 中 约 定 基 金 管 理 人 基 金 托 管 人 依 照 本 法 和 基 金 合 同 的 约 定, 履 行 受 托 职 责 通 过 公 开 募 集 方 式

(CIP) /. :, ISBN TS CIP (2003) : / : : / 32 : :

untitled

Microsoft Word - chap10.doc

csg(1_29)cs.p65

Important Notice SUNPLUS TECHNOLOGY CO. reserves the right to change this documentation without prior notice. Information provided by SUNPLUS TECHNOLO

int *p int a 0x00C7 0x00C7 0x00C int I[2], *pi = &I[0]; pi++; char C[2], *pc = &C[0]; pc++; float F[2], *pf = &F[0]; pf++;

Microsoft Word - 01.DOC

Microsoft Word - 把时间当作朋友(2011第3版)3.0.b.07.doc

概述

untitled

Microsoft Word - 日治時代臺灣女性的故事(簡報文字檔).doc

ebook8-30

Microsoft PowerPoint - string_kruse [兼容模式]

(procedure-oriented)?? 2

威 福 髮 藝 店 桃 園 市 蘆 竹 區 中 山 里 福 祿 一 街 48 號 地 下 一 樓 50,000 獨 資 李 依 純 105/04/06 府 經 登 字 第 號 宏 品 餐 飲 桃 園 市 桃 園 區 信 光 里 民

ebook39-5

Microsoft PowerPoint - 8. 运算符重载 Operator Overloading.pptx

全国计算机技术与软件专业技术资格(水平)考试

Ps22Pdf

EJB-Programming-4-cn.doc

ebook55-13

untitled

Microsoft Word - 8-柯香君-原稿初修-0516.doc

建筑学院建筑学本科专业建设发展规划.doc

Microsoft Word - 黃玉緞 _民間文學教案設計_民歌擬作舉隅

untitled

untitled

BQY.PS2

书 名 : 额 尔 古 纳 河 右 岸 作 者 : 迟 子 建 出 版 社 : 北 京 十 月 文 艺 出 版 社 出 版 日 期 : 开 本 : 正 16 开 页 数 :262 ISBN:

untitled

Ps22Pdf

)001 (131 ) : ISBN / :

...T.U.p65

书 名 : 作 者 : 出 版 社 : 中 国 电 影 出 版 社 版 权 所 有 : 烨 子 工 作 室 类 别 : 中 国 传 世 情 爱 小 说 出 版 时 间 :2005 年 10 月 字 书 数 :150 千 字 号 :ISBN /B 0030

untitled

ISBN Z

untitled

Ps22Pdf

Ps22Pdf

untitled

: : ISBN /B 007 :

untitled

()001 ( 131 ) : ISBN / I1021 :7.50

untitled

untitled

Ps22Pdf

untitled

untitled

()001 ( 131 ) : ISBN / I1020 :6.50

綜合社會保障援助指引

2

面 試 考 古 題 01 請 你 先 簡 單 做 個 自 我 介 紹 自 我 介 紹 通 常 是 面 試 的 第 一 題 在 雙 方 對 彼 此 都 不 太 熟 悉 的 情 況 下, 由 求 職 者 簡 短 自 我 介 紹 中, 面 試 官 可 快 速 掌 握 求 職 者 的 背 景 資 料, 並

加 值 型 及 非 加 值 型 營 業 稅 法 第 12 條 ( 公 布 ) 特 種 飲 食 業 之 營 業 稅 稅 率 如 下 : 一 夜 總 會 有 娛 樂 節 目 之 餐 飲 店 之 營 業 稅 稅 率 為 百 分 之 十 五 二 酒 家 及 有 陪 侍 服 務 之 茶 室

新・明解C言語入門編『索引』

Ps22Pdf

工程设计资质标准

4 办 公 室 工 作 实 务 ( 第 3 版 ) 第 1 单 元 单 位 组 织 的 有 效 运 作 离 不 开 办 公 室 工 作 情 景 案 例 左 景 被 宏 达 商 业 集 团 公 司 录 用 为 秘 书, 试 用 期 间, 只 能 在 办 公 室 打 杂, 有 时 工 作 稍 有 差 错

Transcription:

Effective Modern C++ C++ C++ C++11/C++14 C++ Scott Meyers Gerhard Kreuzer Siemens AG Effective Modern C++ Effective Modern C++ Andrei Alexandrescu Facebook Modern C++ Design C++ C++ Nevin Liber DRW Trading Group C++ Bjarne Stroustrup C++11 Effective Modern C++ C++11 C++14 Scott Meyers Cassio Neri FX

Scott Effective C++ C++ C++ Roger Orr OR/2 ISO C++ Effective Modern C++ C++ C++ Scoot 42 Bart Vandewoestyne C++ C++ Scott Effective Modern C++ Damien Watkins CSIRO C++ C++11/14 C++98 C++ Rachel Cheng F5 Networks C++98/03 C++11/14 Scott Effective Modern C++ C++11 Scott Rob Stewart Boost Steering boost.org

C++ C++11 C++ auto for lambda rvalue C++ 0 typedef nullptr alias declaration C++11 C++14 有效率 C++ C++11 C++14 條款 auto const std::unique_ptr Pimpl Idiom lambda std::atomic volatile C++ C++11 C++14

2 C++ C++ ISO C++98 C++03 C++11 C++14 C++98 C++03 C++98 C++11 C++11 C++14 C++14 C++11 superset C++14 C++14 C++ 使用的詞彙 C++ C++98 C++11 C++14 代表的語言版本 C++98 C++03 C++11 C++14 C++14 C++ C++98 C++98 C++03 C++11 lambda C++11 C++14 C++14 C++14 C++11 move semantic rvalue lvalue rvalue move operation lvalue rvalue lvalue rvalue rvalue reference lvalue lvalue rvalue lvalue rvalue T T lvalue T rvalue rvalue lvalue class Widget { public: Widget(Widget&& rhs); // rhs lvalue rvalue }; Widget move constructor rhs rhs lvalue rvalue lvalue

3 Widget Widget rhs right-hand side 搬移操作 move operation 複製操作 copy operation rhs Matrix operator+(const Matrix& lhs, const Matrix& rhs); lhs left-hand side Widget rhs rhs lvalue C++11 variadic... template<typename... Ts> void processvals(const Ts&... params) { } // C++ processvals typename class C++ class 複 copy C++ void somefunc(widget w); // somefunc w // Widget wid; somefunc(wid); // wid Widget // somefunc // w // wid

4 somefunc(std::move(wid)); somefunc // w // wid rvalue lvalue somefunc rvalue lvlaue w Widget 引數 argument 參數 parameter somefunc wid std::move(wid) w lvalue rvalue lvalue 完美轉發 perfect forwarding rvalue lvalue 30 例外安全 基本保證 basic guarantee 強保證 strong guarantee 函式物件 function object operator() functionname(arguments) operator() C C++98 C++11 可呼叫物件 callable object C++ lambda closure lambda closure lambda 函式樣板 function template 樣板函式 template function 樣板類別 類別樣板 C++ 宣告

5 extern int x; class Widget; bool func(const Widget& w); enum class Color; // // // enum 10 int x; class Widget { }; // // bool func(const Widget& w) { return w.size() < 10; } // enum class Color { Yellow, Red, Blue }; enum 章 signature func bool(const Widget&) noexcept constexpr noexcept constexpr 14 15 C++ 停用 deprecate C++11 std::unique_ptr std::auto_ptr C++11 std::auto_ptr 未定義行為 undefined behavior std::vector []

6 iterator data race new 原始指標 raw pointer 智慧型指標 smart pointer operator-> operator* 20 std::weak_ptr ctor dtor ISBN Effective Modern C++ by Scott Meyers (O Reilly). Copyright 2015 Scott Meyers, 978-1-491-90399-5. email emc++@aristeia.com http://www.aristeia.com/bookerrata/ emc++-errata.html

第一章 C++98 C++11 auto decltype C++14 auto decltype C++ auto decltype C++14 decltype(auto) C++ auto decltype 1 C++ auto C++ C++98 C++11 auto auto

8 auto void f(paramtype param); f(expr); f expr T ParamType ParamType const reference qualifier void f(const T& param); // ParamType const T& int x = 0; f(x); // int f T int ParamType const int& T T expr x int T int T expr ParamType ParamType reference type universal reference 24 universal reference lvalue rvalue ParamType universal reference ParamType void f(paramtype param); f(expr); // expr T ParamType

9 ParamType universal reference ParamType universal reference 1. expr 2. expr ParamType pattern-match T void f(t& param); // param int x = 27; const int cx = x; const int& rx = x; // x int // cx const int // rx x const int param T f(x); f(cx); f(rx); // T int param int& // T const int // param const int& // T const int // param const int& cx rx const T const int const int& const reference parameter const reference-to-const const T& constness T rx T rx lvalue rvalue rvalue rvalue

10 f T& const T& cx rx const param const T const template<type T> void f(const T& param); // param int x = 27; const int cx = x; const int& rx = x; f(x); f(cx); f(rx); // T int param const int& // T int param const int& // T int param const int& rx reference-ness param const void f(t* param); int x = 27; const int *px = &x; f(&x); f(px); // param // px x x const int // T int param int* // T const int // param const int* C++ ParamType Universal Reference universal reference rvalue T universal reference T&& lvalue 24

11 expr lvalue T ParamType lvalue T ParamType rvalue lvalue expr rvalue void f(t&& param); int x = 27; const int cx = x; const int& rx = x; f(x); f(cx); f(rx); f(27); // param universal reference // x lvalue T int& // param int& // cx lvalue T const int& // param const int& // rx lvalue T const int& // param const int& // 27 rvalue T int // param int&& 24 universal reference lvalue rvalue universal reference lvalue rvalue universal reference ParamType ParamType pass-by-value void f(t param); // param param expr T

12 1. expr 2. expr expr const volatile volatile 40 int x = 27; const int cx = x; const int& rx = x; f(x); f(cx); f(rx); // T param int // T param int // T param int cx rx const param const param cx rx cx rx 複本 cx rx param param const volatile expr const volatile const const expr const expr const const expr param void f(t param); // param const char* const ptr = "Fun with pointers"; f(ptr); // ptr const const // const char * const ptr const ptr const ptr null const ptr const ptr f param 指標本身 ptr 會以傳值的方式傳入 ptr const param const char* const ptr const ptr param ptr const

13 衰退 const char name[] = "J. P. Briggs"; // name // const char[13] const char * ptrtoname = name; // array name const char* ptrtoname name const char[13] const char* const char[13] array-to-pointer void f(t param); f(name); // T param function parameter void myfunc(int param[]); myfunc void myfunc(int* param); C++ C f T const char* f(name); // name T const char*

14 能夠 參考 f void f(t& param); f(name); f T T const char[13] f const char (&)[13] template<typename T, std::size_t N> // constexpr std::size_t arraysize(t (&)[N]) noexcept // constexpr { // noexcept return N; } 15 constexpr int keyvals[] = { 1, 3, 7, 9, 11, 22, 35 }; // keyvals 7 int mappedvals[arraysize(keyvals)]; // mappedvals 7 C++ std::array std::array<int, arraysize(keyvals)> mappedvals; //mappedvals // size 7 arraysize noexcept 14

15 C++ void somefunc(int, double); // somefunc // void(int, double) void f1(t param); void f2(t& param); f1(somefunc); f2(somefunc); // f1 param // f2 param // param // void (*)(int, double) // param // void (&)(int, double) array-to-pointer function-to-pointer auto universal reference lvalue 4 reference-ness universal reference lvalue by-value const volatile const volatile