现代C++ 教程:高速上手C++11/14/17/20现代 C++ 教程:高速上手 C++11/14/17/20 欧长坤 (hi[at]changkun.de) 最后更新 2023 年 5 月 7 日- ff6ee89 注意 此 PDF 的内容可能过期,请检查本书网站以及 GitHub 仓库以获取最新内容。 版权声明 本书系欧长坤著,采用“知识共享署名-非商业性使用-禁止演绎 4.0 国际许可协议 (CC BY-NC-ND)”进 行许可 . . . . . . . . . . . . . 83 6 序言 序言 引言 C++ 是一个用户群体相当大的语言。从 C++98 的出现到 C++11 的正式定稿经历了长达十年多之 久的积累。C++14/17 则是作为对 C++11 的重要补充和优化,C++20 则将这门语言领进了现代化的大 门,所有这些新标准中扩充的特性,给 C++ 这门语言注入了新的活力。那些还在坚持使用传统 C++ 特性均称之为传统 C++)而未接触过现代 C++ 的 C++ 程序员在 见到诸如 Lambda 表达式这类全新特性时,甚至会流露出『学的不是同一门语言』的惊叹之情。 现代 C++ (本书中均指 C++11/14/17/20) 为传统 C++ 注入的大量特性使得整个 C++ 变得更加 像一门现代化的语言。现代 C++ 不仅仅增强了 C++ 语言自身的可用性,auto 关键字语义的修改使得我 们更0 码力 | 83 页 | 2.42 MB | 1 年前3
C++高性能并行编程与优化 - 课件 - 05 C++11 开始的多线程编程C++11 开始的多线程编 程 by 彭于斌( @archibate ) 往期录播: https://www.bilibili.com/video/BV1fa411r7zp 课程 PPT 和代码: https://github.com/parallel101/course 高性能并行编程与优化 - 课程大纲 • 分为前半段和后半段,前半段主要介绍现代 C++ ,后半段主要介绍并行编程与优化。 GitHub ) CUDA Toolkit 10.0 以上( GPU 专题) 温馨提示: 1. 会用到第二讲( RAII 与智能指针)里的知识 2. 课件中一部分代码是基于 C++17 的 个人认为, C++11 中很多特性, 其实可以看做是为了支持多线程而 顺带引入的……如 chrono 、移动 、 lambda 、 RAII…… 第 0 章:时间 C 语言如何处理时间: time.h • long ,没有类型区分,导致很容易弄错单位,混淆时间点和时间段。 • 比如 t0 * 3 ,乘法对时间点而言根本是个无意义的计算,然而 C 语言把他们看做一样的 long 类型,从而容易让程序员犯错。 C++11 引入的时间标准库: std::chrono • 利用 C++ 强类型的特点,明确区分时间点与时间段,明确区分不同的时间单位。 • 时间点例子: 2022 年 1 月 8 日 13 点 07 分0 码力 | 79 页 | 14.11 MB | 1 年前3
C++高性能并行编程与优化 - 课件 - 02 现代 C++ 入门:RAII 内存管理C 语言 近代: C++98 引入 STL 容器库 近现代: C++11 引入了 {} 初始化表达式 近现代: C++11 引入了 range-based for-loop 如果想使用 for_each 这个算法模板呢? 我知道可以用 accumulate 啦!但是为了引出 lambda 表达式…… 近现代: C++11 引入了 lambda 表达式 现代: C++14 的 lambda *p{nullptr}; • 等价,都会零初始化。但是你不写那个空括号就会 变成内存中随机的值。 • 再比如: std::cout << int{}; 会打印出 0 编译器默认生成的构造函数:初始化列表(感谢 C++11 ) • 当一个类(和他的基类)没有定义任何构造函 数,这时编译器会自动生成一个参数个数和成 员一样的构造函数。 • 他会将 {} 内的内容,会按顺序赋值给对象的每 一个成员。 • 目的是为了方便程序员不必手写冗长的构造函 一旦我们定义了自己的构造函数,编译器就不会再生成默认的无参构造函数。 有自定义构造函数时仍想用默认构造函数: = default (续) • 如果还想让编译器自动生成默认的无参构造函数,可以用 C++11 新增的这个语法: 不过,据我所知,初始化列表 的那个构造函数就没办法通过 = default 语法恢复…… 编译器默认生成的构造函数:拷贝构造函数 • 除了无参和初始化列表构造函数外,编0 码力 | 96 页 | 16.28 MB | 1 年前3
C++高性能并行编程与优化 - 课件 - 13 C++ STL 容器全解之 vectorint const &operator[](size_t i) const noexcept; vector 容器:构造函数 • 除了先指定大小再一个个构造之外,还可 以直接利用初始化列表( C++11 新特性) 在构造时就初始化其中元素的值。 • 例如创建具有 6, 1, 7, 4 四个元素的 vector : • vectora = {6, 1, 7, 4}; • 和刚刚先创建再赋值的方法相比更直观。 • vector a = {1, 2, 3}; • void push_back(int const &val); • void push_back(int &&val); // C++11 新增 vector 容器: pop_back • 而 pop_back 函数则是和 push_back 唱 反调,他是在数组的末尾删除一个数。例 如: • vector a = insert(const_iterator pos, int const &val); • iterator insert(const_iterator pos, int &&val); // C++11 vector 容器: insert 函数,插入位置是倒数第 2 个 • a.begin() 可以插入到开头位置。 • a.begin() + 1 可以插入到第二个元素位置。 • a.end() 0 码力 | 90 页 | 4.93 MB | 1 年前3
C++高性能并行编程与优化 - 课件 - Zeno 中的现代 C++ 最佳实践 初始化依然保证是原子的( C++11 起)。 • 这就是函数静态初始化 (func-static-init) 大法。 函数静态初始化可用于“懒汉单例模式” • 如右图。 • getMyClassInstance() 会在第一次调用时创 建 MyClass 对象,并返回指向他的引用。 • 根据 C++ 函数静态变量初始化的规则,之后 的调用不会再重复创建。 • 并且 C++11 也保证了不会多线程的危险, 在参数类型已经确定的情况下,例如: • void func(Descriptor const &desc); • 则 func(Descriptor(...)); • 与 func({...}); • 等价( C++11 起)。 Zeno 中一切节点的基类 • 输入输出全部存储在节点的 inputs 和 outputs 成员变量上。 • inputBounds 表示他连接在哪个节点的哪 个端口上,比如0 码力 | 54 页 | 3.94 MB | 1 年前3
Krita 4.x 官方文档中文版 2021-08-06Athe support of it will be removed soon. description: bg.. meta:: Guide to using features from C++11, C++14 and beyond in Krita’s codebase. Modern C++ usage guidelines for the Krita codebase ⽬录 Modern references) C++11 features mostly for template programming Other C++11 features that will not be useful General links about using Modern C++ in Qt There have been a few links discussing mixing C++11 with Qt Qt, and starting with Qt 5.6 C++11 support will be default. Note: there is a lot of hype about C++11, and although many of its new features are quite welcome, often the trade-offs from these changes get0 码力 | 1594 页 | 110.95 MB | 1 年前3
Krita 4.x 官方文档中文版 2021-08-06Athe support of it will be removed soon. description: bg.. meta:: Guide to using features from C++11, C++14 and beyond in Krita’s codebase. Modern C++ usage guidelines for the Krita codebase 目录 Modern references) C++11 features mostly for template programming Other C++11 features that will not be useful General links about using Modern C++ in Qt There have been a few links discussing mixing C++11 with Qt Qt, and starting with Qt 5.6 C++11 support will be default. Note: there is a lot of hype about C++11, and although many of its new features are quite welcome, often the trade-offs from these changes get0 码力 | 1373 页 | 74.74 MB | 1 年前3
Krita 5.2 中文手册the support of it will be removed soon. bg.. meta:: description: Guide to using features from C++11, C++14 and beyond in Krita’s codebase. Modern C++ usage guidelines for the Krita codebase 目录 Modern references) C++11 features mostly for template programming Other C++11 features that will not be useful General links about using Modern C++ in Qt There have been a few links discussing mixing C++11 with Qt Qt, and starting with Qt 5.6 C++11 support will be default. Note: there is a lot of hype about C++11, and although many of its new features are quite welcome, often the trade-offs from these changes get0 码力 | 1594 页 | 79.20 MB | 1 年前3
Krita 5.2 官方文档中文版 2023-12-08Athe support of it will be removed soon. description:: bg.. meta:: Guide to using features from C++11, C++14 and beyond in Kritaʼs codebase. Modern C++ usage guidelines for the Krita codebase 目录 Modern references) C++11 features mostly for template programming Other C++11 features that will not be useful General links about using Modern C++ in Qt There have been a few links discussing mixing C++11 with Qt Qt, and starting with Qt 5.6 C++11 support will be default. Note: there is a lot of hype about C++11, and although many of its new features are quite welcome, often the trade-offs from these changes get0 码力 | 1685 页 | 91.87 MB | 1 年前3
Krita 5.2 官方文档中文版 2023-12-08Athe support of it will be removed soon. description:: bg.. meta:: Guide to using features from C++11, C++14 and beyond in Krita’s codebase. Modern C++ usage guidelines for the Krita codebase 目录 Modern references) C++11 features mostly for template programming Other C++11 features that will not be useful General links about using Modern C++ in Qt There have been a few links discussing mixing C++11 with Qt Qt, and starting with Qt 5.6 C++11 support will be default. Note: there is a lot of hype about C++11, and although many of its new features are quite welcome, often the trade-offs from these changes get0 码力 | 1562 页 | 79.19 MB | 1 年前3
共 23 条
- 1
- 2
- 3













