├── 24lambda表达式 └── 24lambda表达式 │ ├── .txt │ ├── lambda.js │ ├── coroutine.js │ ├── closure.js │ ├── 24lambda表达式.vcxproj.filters │ └── 24lambda表达式.cpp ├── 34Unicode支持 └── 34Unicode支持 │ ├── 字面量-utf8.txt │ ├── 34Unicode支持.cpp │ └── 34Unicode支持.vcxproj.filters ├── LICENSE ├── 31chrono库 └── 31chrono库 │ ├── time.js │ ├── 31chrono库.cpp │ └── 31chrono库.vcxproj.filters ├── 00前言&工具 └── vs2022安装.docx ├── 20外部模板 └── 20外部模板 │ ├── extern_tmpl.cpp │ ├── extern_tmpl.h │ ├── 20外部模板.cpp │ └── 20外部模板.vcxproj.filters ├── 综合实践c++11实现chrome的线程模型 ├── base │ ├── ReadMe.txt │ ├── thread.cpp │ ├── event.h │ ├── message_pump_default.h │ ├── time.cpp │ ├── pending_task.h │ ├── event.cpp │ ├── message_pump_default.cpp │ ├── thread.h │ ├── base.vcxproj.filters │ ├── message_loop.h │ ├── message_pump.h │ ├── pending_task.cpp │ ├── time.h │ └── message_loop.cpp ├── .gitignore └── sample │ ├── sample.vcxproj.filters │ └── sample.cpp ├── 14_Pragma操作符 └── 14_Pragma操作符 │ ├── cpp.hint │ ├── 14_Pragma操作符.cpp │ └── 14_Pragma操作符.vcxproj.filters ├── 18非静态成员的sizeof └── 18非静态成员的sizeof │ ├── 18非静态成员的sizeof.cpp │ └── 18非静态成员的sizeof.vcxproj.filters ├── 15变长参数的宏定义 └── 15变长参数的宏定义 │ ├── 15变长参数的宏定义.cpp │ ├── 15变长参数的宏定义.vcxproj.filters │ └── 15变长参数的宏定义.vcxproj ├── 29default&delete └── 29default delete │ ├── 29default delete.cpp │ └── 29default delete.vcxproj.filters ├── 07右尖括号 └── 07右尖括号 │ ├── 07右尖括号.cpp │ ├── 07右尖括号.vcxproj.filters │ └── 07右尖括号.vcxproj ├── 17类定义里面初始化成员变量 └── 17类定义里面初始化成员变量 │ ├── 17类定义里面初始化成员变量.cpp │ └── 17类定义里面初始化成员变量.vcxproj.filters ├── 04函数默认模板参数 └── 04函数默认模板参数 │ ├── 04函数默认模板参数.cpp │ ├── 04函数默认模板参数.vcxproj.filters │ └── 04函数默认模板参数.vcxproj ├── 13__func__返回函数名字 └── 13__func__返回函数名字 │ ├── 13__func__返回函数名字.cpp │ └── 13__func__返回函数名字.vcxproj.filters ├── 02static_assert&__cplusplus宏 └── static_assert │ ├── static_assert.cpp │ └── static_assert.vcxproj.filters ├── .gitignore ├── 28nullptr └── 28nullptr │ ├── 28nullptr.cpp │ ├── 28nullptr.vcxproj.filters │ └── 28nullptr.vcxproj ├── 03long long关键字 └── 03long long关键字 │ ├── 03long long关键字.cpp │ └── 03long long关键字.vcxproj.filters ├── 10auto与decltype关键字 └── 10auto与decltype关键字 │ ├── 10auto decltype关键字.cpp │ └── 10auto decltype关键字.vcxproj.filters ├── 10auto&decltype关键字 └── 10auto decltype关键字 │ ├── 10auto decltype关键字.cpp │ └── 10auto decltype关键字.vcxproj.filters ├── 37通用属性 └── 37通用属性 │ ├── 37通用属性.cpp │ ├── 37通用属性.vcxproj.filters │ └── 37通用属性.vcxproj ├── 16noexcept关键字 └── 16noexcept关键字 │ ├── 16noexcept关键字.cpp │ └── 16noexcept关键字.vcxproj.filters ├── 05委托构造函数 └── 05委托构造函数 │ ├── 05委托构造函数.cpp │ ├── 05委托构造函数.vcxproj.filters │ └── 05委托构造函数.vcxproj ├── 19friend友元改进 └── 19friend友元改进 │ ├── 19friend友元改进.cpp │ └── 19friend友元改进.vcxproj.filters ├── 36列表初始化&类型收窄 └── 36列表初始化 类型收窄 │ ├── 36列表初始化 类型收窄.cpp │ └── 36列表初始化 类型收窄.vcxproj.filters ├── 36列表初始化与类型收窄 └── 36列表初始化 类型收窄 │ ├── 36列表初始化 类型收窄.cpp │ └── 36列表初始化 类型收窄.vcxproj.filters ├── 12强枚举类型 └── 12强枚举类型 │ ├── 12强枚举类型.cpp │ ├── 12强枚举类型.vcxproj.filters │ └── 12强枚举类型.vcxproj ├── README_zh.md ├── 32继承构造函数&using用法 └── 32继承构造函数 using用法 │ ├── 32继承构造函数 using用法.cpp │ └── 32继承构造函数 using用法.vcxproj.filters ├── 08基于范围的for语句 └── 08基于范围的for语句 │ ├── 08基于范围的for语句.cpp │ └── 08基于范围的for语句.vcxproj.filters ├── 06override与final关键字 └── 06override与final关键字 │ ├── 06override与final关键字.cpp │ └── 06override与final关键字.vcxproj.filters ├── 01thread_local关键字 └── tls │ ├── tls.vcxproj.filters │ └── tls.cpp ├── 27智能指针 └── 27智能指针 │ ├── 27智能指针.vcxproj.filters │ ├── 27智能指针.cpp │ └── 27智能指针.vcxproj ├── 38文件系统 └── 38文件系统 │ ├── 38文件系统.vcxproj.filters │ └── 38文件系统.cpp ├── 26多线程&同步 └── 26多线程 同步 │ ├── 26多线程 同步.vcxproj.filters │ └── 26多线程 同步.cpp ├── 30POD类型 └── 30POD类型 │ ├── 30POD类型.vcxproj.filters │ ├── 30POD类型.cpp │ └── 30POD类型.vcxproj ├── 33变长模板参数 └── 33变长模板参数 │ ├── 33变长模板参数.vcxproj.filters │ └── 33变长模板参数.cpp ├── 23可执行对象封装器 └── 23可执行对象封装器 │ ├── 23可执行对象封装器.vcxproj.filters │ ├── 23可执行对象封装器.cpp │ └── 23可执行对象封装器.vcxproj ├── 35用户自定义字面量 └── 35用户自定义字面量 │ ├── 35用户自定义字面量.vcxproj.filters │ ├── 35用户自定义字面量.cpp │ └── 35用户自定义字面量.vcxproj ├── 21右值引用&移动语义 └── 21右值引用 移动语义 │ ├── 21右值引用 移动语义.vcxproj.filters │ ├── 21右值引用 移动语义.cpp │ └── 21右值引用 移动语义.vcxproj ├── 22右值引用&完美转发 └── 22右值引用 完美转发 │ ├── 22右值引用 完美转发.vcxproj.filters │ └── 22右值引用 完美转发.cpp ├── 25原子类型&内存模型 └── 25原子类型 内存模型 │ ├── 25原子类型 内存模型.vcxproj.filters │ └── 25原子类型 内存模型.cpp ├── 09constexpr关键字 └── 09constexpr关键字 │ ├── 09constexpr关键字.vcxproj.filters │ └── 09constexpr关键字.cpp ├── 11RTTI&typeid&dynamic_cast └── 11RTTI typeid dynamic_cast │ ├── 11RTTI typeid dynamic_cast.vcxproj.filters │ └── 11RTTI typeid dynamic_cast.cpp ├── README.md └── chrome的多线程模型_vs2022.sln /24lambda表达式/24lambda表达式/.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /34Unicode支持/34Unicode支持/字面量-utf8.txt: -------------------------------------------------------------------------------- 1 | 我爱北京天安门 -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 本项目遵从《GPLv2开源协议》 2 | 我给你源代码,你给我你对它的修改,我们就扯平了 -------------------------------------------------------------------------------- /31chrono库/31chrono库/time.js: -------------------------------------------------------------------------------- 1 | console.log(Date.now()) 2 | console.log(Math.floor(Date.now() / 1000)) 3 | -------------------------------------------------------------------------------- /00前言&工具/vs2022安装.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sinajia/38-code-examples-for-cpp11/HEAD/00前言&工具/vs2022安装.docx -------------------------------------------------------------------------------- /20外部模板/20外部模板/extern_tmpl.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sinajia/38-code-examples-for-cpp11/HEAD/20外部模板/20外部模板/extern_tmpl.cpp -------------------------------------------------------------------------------- /20外部模板/20外部模板/extern_tmpl.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | template 4 | void gen(T t) { 5 | std::cout << t << std::endl; 6 | } 7 | -------------------------------------------------------------------------------- /综合实践c++11实现chrome的线程模型/base/ReadMe.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sinajia/38-code-examples-for-cpp11/HEAD/综合实践c++11实现chrome的线程模型/base/ReadMe.txt -------------------------------------------------------------------------------- /综合实践c++11实现chrome的线程模型/base/thread.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sinajia/38-code-examples-for-cpp11/HEAD/综合实践c++11实现chrome的线程模型/base/thread.cpp -------------------------------------------------------------------------------- /24lambda表达式/24lambda表达式/lambda.js: -------------------------------------------------------------------------------- 1 | const fs = require('fs') 2 | 3 | fs.readFile('./lambda.js', function (err, data) { 4 | console.log(data.toString()); 5 | }) 6 | -------------------------------------------------------------------------------- /14_Pragma操作符/14_Pragma操作符/cpp.hint: -------------------------------------------------------------------------------- 1 | // 提示文件帮助 Visual Studio IDE 解释 Visual C++ 标识符, 2 | // 如函数和宏的名称。 3 | // 有关详细信息,请参见 https://go.microsoft.com/fwlink/?linkid=865984 4 | #define PRAGPOP _Pragma("pack (pop)") 5 | -------------------------------------------------------------------------------- /24lambda表达式/24lambda表达式/coroutine.js: -------------------------------------------------------------------------------- 1 | const fs = require('fs/promises') 2 | 3 | async function read() { 4 | const l = await fs.readdir('./') 5 | console.log(l) 6 | } 7 | 8 | read() 9 | console.log('更早运行到这里') 10 | -------------------------------------------------------------------------------- /24lambda表达式/24lambda表达式/closure.js: -------------------------------------------------------------------------------- 1 | function a (x) { 2 | var i = 1 3 | var d = 0.15 4 | return (y) => { 5 | return i + d + x + y; 6 | } 7 | } 8 | 9 | var fun = a(100) 10 | 11 | const v = fun(110) 12 | 13 | console.log(v) 14 | -------------------------------------------------------------------------------- /20外部模板/20外部模板/20外部模板.cpp: -------------------------------------------------------------------------------- 1 | // 20外部模板.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。 2 | // 3 | 4 | #include 5 | #include "./extern_tmpl.h" 6 | 7 | using namespace std; 8 | 9 | extern template void gen(int); // extern声明外部模板,减少重复代码编译,提升编译效率 10 | 11 | int main() 12 | { 13 | gen(100); 14 | } 15 | -------------------------------------------------------------------------------- /18非静态成员的sizeof/18非静态成员的sizeof/18非静态成员的sizeof.cpp: -------------------------------------------------------------------------------- 1 | // 18非静态成员的sizeof.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。 2 | // 3 | 4 | #include 5 | 6 | using namespace std; 7 | 8 | class A { 9 | public: 10 | int i_; 11 | }; 12 | 13 | int main() 14 | { 15 | cout << sizeof(A::i_) << endl; // C++11开始支持 16 | } 17 | -------------------------------------------------------------------------------- /15变长参数的宏定义/15变长参数的宏定义/15变长参数的宏定义.cpp: -------------------------------------------------------------------------------- 1 | // 15变长参数的宏定义.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。 2 | // 3 | 4 | #include 5 | 6 | using namespace std; 7 | 8 | #define LOG(...) { \ 9 | fprintf(stderr,"%s:line %d:\t", "15变长参数的宏定义.cpp", __LINE__);\ 10 | fprintf(stderr, __VA_ARGS__);\ 11 | } 12 | int main() 13 | { 14 | LOG("%s\n", "hello world"); 15 | } 16 | -------------------------------------------------------------------------------- /29default&delete/29default delete/29default delete.cpp: -------------------------------------------------------------------------------- 1 | // 29default delete.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。 2 | // 3 | 4 | #include 5 | 6 | class A { 7 | public: 8 | A() = default; 9 | A(int) {} 10 | // A(const A&) = delete; // delete声明不产生拷贝构造函数 11 | }; 12 | 13 | int main() 14 | { 15 | A* ptr = new A(); 16 | A a{ *ptr }; 17 | } 18 | -------------------------------------------------------------------------------- /07右尖括号/07右尖括号/07右尖括号.cpp: -------------------------------------------------------------------------------- 1 | // 07右尖括号.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。 2 | // 3 | 4 | #include 5 | #include 6 | 7 | using namespace std; 8 | 9 | template 10 | struct item { 11 | T t_; 12 | }; 13 | 14 | int main() 15 | { 16 | // vs2008编译不过,必须多敲一个空格,小优化,本该如此 17 | vector> v; 18 | std::cout << "Hello World!\n"; 19 | } 20 | -------------------------------------------------------------------------------- /17类定义里面初始化成员变量/17类定义里面初始化成员变量/17类定义里面初始化成员变量.cpp: -------------------------------------------------------------------------------- 1 | // 17类定义里面初始化成员变量.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。 2 | // 3 | 4 | #include 5 | 6 | using namespace std; 7 | 8 | class A { 9 | public: 10 | A() : i_(1) { 11 | i_ = 2; 12 | } 13 | int i_ = 0; // 构造对象时,最早执行 14 | }; 15 | 16 | int main() 17 | { 18 | A a; 19 | cout << a.i_ << endl; 20 | } 21 | -------------------------------------------------------------------------------- /04函数默认模板参数/04函数默认模板参数/04函数默认模板参数.cpp: -------------------------------------------------------------------------------- 1 | // 04函数默认模板参数.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。 2 | // 3 | 4 | #include 5 | 6 | using namespace std; 7 | 8 | template // 类的默认模板参数本来就支持,C++11增加了函数的 9 | S func(T t) { 10 | cout << t << endl; 11 | return sizeof(S); 12 | } 13 | 14 | int main() { 15 | cout << (func(5.5)); 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /13__func__返回函数名字/13__func__返回函数名字/13__func__返回函数名字.cpp: -------------------------------------------------------------------------------- 1 | // 13__func__返回函数名字.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。 2 | // 3 | 4 | #include 5 | 6 | using namespace std; 7 | 8 | class A { 9 | public: 10 | A() { 11 | cout << __FILE__ << endl; 12 | cout << __LINE__ << endl; 13 | cout << __func__ << endl; 14 | cout << __TIME__ << endl; 15 | } 16 | }; 17 | 18 | int main() 19 | { 20 | A a; 21 | } 22 | -------------------------------------------------------------------------------- /02static_assert&__cplusplus宏/static_assert/static_assert.cpp: -------------------------------------------------------------------------------- 1 | // static_assert.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。 2 | // 3 | 4 | #include 5 | 6 | template 7 | class A { 8 | public: 9 | A() { 10 | static_assert(sizeof(T) == 4, "sizeof(T) != 4"); // 编译期决议,编译器检查 11 | } 12 | }; 13 | 14 | int main() 15 | { 16 | static_assert(__cplusplus >= 199711LL, ""); 17 | A a; 18 | std::cout << "Hello World!\n"; 19 | } 20 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files 2 | *.slo 3 | *.lo 4 | *.o 5 | 6 | # Compiled Dynamic libraries 7 | *.so 8 | *.sdf 9 | *.ncb 10 | *.suo 11 | *.pch 12 | *.pdb 13 | *.idb 14 | *.exp 15 | *.map 16 | 17 | # Compiled Static libraries 18 | *.lai 19 | *.la 20 | *.lib 21 | *.a 22 | *.user 23 | *.exe 24 | *.VC.db 25 | .vs/ 26 | x64/ 27 | build/ 28 | Debug/ 29 | Release/ 30 | dist/ 31 | ipch/ 32 | 33 | # xmake 34 | .xmake 35 | .DS_Store 36 | .idea 37 | .vs 38 | .vscode 39 | -------------------------------------------------------------------------------- /28nullptr/28nullptr/28nullptr.cpp: -------------------------------------------------------------------------------- 1 | // 28nullptr.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。 2 | // 3 | 4 | #include 5 | 6 | using namespace std; 7 | 8 | void func(int) { 9 | cout << "func(int)" << endl; 10 | } 11 | 12 | void func(char*) { 13 | cout << "func(char*)" << endl; 14 | } 15 | 16 | int main() 17 | { 18 | func(NULL); 19 | func((char*)NULL); 20 | func(nullptr); 21 | cout << (nullptr == 0) << endl; 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /03long long关键字/03long long关键字/03long long关键字.cpp: -------------------------------------------------------------------------------- 1 | // 03long long关键字.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。 2 | // 3 | 4 | #include 5 | #include 6 | 7 | int main() 8 | { 9 | std::cout << sizeof(long long) << std::endl; 10 | std::cout << sizeof(__int64) << std::endl; 11 | std::cout << sizeof(void *) << std::endl; 12 | 13 | std::cout << LLONG_MIN << std::endl; 14 | std::cout << LLONG_MAX << std::endl; 15 | std::cout << ULLONG_MAX << std::endl; 16 | } 17 | -------------------------------------------------------------------------------- /10auto与decltype关键字/10auto与decltype关键字/10auto decltype关键字.cpp: -------------------------------------------------------------------------------- 1 | // 10auto decltype关键字.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。 2 | // 3 | 4 | #include 5 | 6 | using namespace std; 7 | 8 | auto func(int i) { 9 | if (i > 0) { 10 | return i; 11 | } 12 | else { 13 | return 9; 14 | } 15 | } 16 | 17 | int main() 18 | { 19 | // auto代替类型 20 | auto i = func(5); 21 | // 推到类型 22 | decltype(i) i1; 23 | i1 = 100; 24 | cout << i1 << endl; 25 | } 26 | -------------------------------------------------------------------------------- /综合实践c++11实现chrome的线程模型/.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files 2 | *.slo 3 | *.lo 4 | *.o 5 | 6 | # Compiled Dynamic libraries 7 | *.so 8 | *.sdf 9 | *.ncb 10 | *.suo 11 | *.pch 12 | *.pdb 13 | *.idb 14 | *.exp 15 | *.map 16 | 17 | # Compiled Static libraries 18 | *.lai 19 | *.la 20 | *.lib 21 | *.a 22 | *.user 23 | *.exe 24 | *.VC.db 25 | .vs/ 26 | x64/ 27 | build/ 28 | Debug/ 29 | Release/ 30 | dist/ 31 | ipch/ 32 | 33 | # xmake 34 | .xmake 35 | .DS_Store 36 | .idea 37 | .vs 38 | .vscode 39 | 40 | cmake-build-debug -------------------------------------------------------------------------------- /10auto&decltype关键字/10auto decltype关键字/10auto decltype关键字.cpp: -------------------------------------------------------------------------------- 1 | // 10auto decltype关键字.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。 2 | // 3 | 4 | #include 5 | 6 | using namespace std; 7 | 8 | auto func(int i) { 9 | if (i > 0) { 10 | return i; 11 | } 12 | else { 13 | return 9; 14 | } 15 | } 16 | 17 | int main() 18 | { 19 | // auto代替类型 20 | auto i = func(5); 21 | // 推导类型 22 | decltype(func(1)) i1; 23 | decltype(i) i2; 24 | i1 = 100; 25 | cout << i1 << endl; 26 | } 27 | -------------------------------------------------------------------------------- /37通用属性/37通用属性/37通用属性.cpp: -------------------------------------------------------------------------------- 1 | // 37通用属性.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。 2 | // 3 | 4 | #include 5 | #include 6 | 7 | using namespace std; 8 | 9 | class __declspec(novtable) A { 10 | public: 11 | virtual void func() = 0; 12 | }; 13 | 14 | // 函数不会返回 15 | [[noreturn]] void throwAway() { 16 | throw ""; 17 | } 18 | 19 | void func() { 20 | throwAway(); 21 | cout << "不会执行到这里"; 22 | } 23 | 24 | // 返回值不应该被丢弃 25 | [[nodiscard]] int func2() { 26 | return 0; 27 | } 28 | 29 | int main() { 30 | func2(); // 编译器会发出相关warning 31 | abort(); 32 | } 33 | 34 | -------------------------------------------------------------------------------- /16noexcept关键字/16noexcept关键字/16noexcept关键字.cpp: -------------------------------------------------------------------------------- 1 | // 16noexcept关键字.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。 2 | // 3 | 4 | #include 5 | 6 | using namespace std; 7 | 8 | void func() noexcept { // 表示函数不抛出异常,与noexcept(true)意思一样 9 | throw exception(); // 编译通过,在程序执行过程中,程序会调用terminate以确保遵守不在运行时抛出异常的承诺 10 | } 11 | 12 | int main() { 13 | try { 14 | func(); 15 | } 16 | catch (int e) { 17 | cout << "catch" << endl; 18 | } 19 | 20 | cout << noexcept(func()) << endl; // 如果func不抛出异常,则为true,否则为false 21 | 22 | } 23 | 24 | // 析构函数应该声明为noexcept 25 | -------------------------------------------------------------------------------- /05委托构造函数/05委托构造函数/05委托构造函数.cpp: -------------------------------------------------------------------------------- 1 | // 05委托构造函数.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。 2 | // 3 | 4 | #include 5 | 6 | class A { 7 | public: 8 | // 在构造函数里面调用另外一个构造函数,这是提高编码效率,减少冗余的设计 9 | A() : A(0, 0, 0) {}; 10 | A(int hour, int min, int sec) : hour_(hour), min_(min), sec_(sec) {} 11 | 12 | std::ostream& operator<<(std::ostream& os) { 13 | os << hour_ << min_ << sec_; 14 | return os; 15 | } 16 | 17 | int hour_; 18 | int min_; 19 | int sec_; 20 | }; 21 | 22 | int main() 23 | { 24 | A a; 25 | a << std::cout << std::endl; 26 | } 27 | -------------------------------------------------------------------------------- /19friend友元改进/19friend友元改进/19friend友元改进.cpp: -------------------------------------------------------------------------------- 1 | // 19friend友元改进.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。 2 | // 3 | 4 | #include 5 | 6 | using namespace std; 7 | 8 | class B; 9 | 10 | template 11 | class A { 12 | private: 13 | friend T; // 可以是类,也可以是基本类型,基本类型编译器自动忽略friend,用于泛型编程 14 | void func() { 15 | cout << typeid(T).name() << endl; 16 | } 17 | }; 18 | 19 | class B { 20 | public: 21 | void func(A a) { 22 | a.func(); 23 | } 24 | }; 25 | 26 | int main() 27 | { 28 | A a; 29 | B b; 30 | b.func(a); 31 | 32 | //A a1; 33 | 34 | } 35 | -------------------------------------------------------------------------------- /31chrono库/31chrono库/31chrono库.cpp: -------------------------------------------------------------------------------- 1 | // 31chrono库.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。 2 | // 3 | 4 | #include 5 | #include 6 | 7 | using namespace std; 8 | int main() { 9 | const auto millisec_since_epoch = 10 | std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()); 11 | auto sec_since_epoch = std::chrono::duration_cast(millisec_since_epoch); 12 | cout << millisec_since_epoch.count() << endl; // Unix时间戳,单位毫秒 13 | cout << sec_since_epoch.count() << endl; // Unix时间戳 秒 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /36列表初始化&类型收窄/36列表初始化 类型收窄/36列表初始化 类型收窄.cpp: -------------------------------------------------------------------------------- 1 | // 36列表初始化 类型收窄.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。 2 | // 3 | 4 | #include 5 | 6 | using namespace std; 7 | 8 | class A { 9 | public: 10 | A(int i) : i_(i) { 11 | 12 | } 13 | 14 | int i_; 15 | 16 | }; 17 | 18 | int main() 19 | { 20 | int i1 = 0.5; 21 | int i2(0.6); 22 | int i3 = { 1 }; 23 | int i4{ 2 }; 24 | A a = { 0 }; 25 | 26 | short si = 10; 27 | __int64 i64{ si }; 28 | 29 | cout << i1 << endl; 30 | cout << i2 << endl; 31 | 32 | // 防止隐式类型转换 33 | // int i3{ 0.9 }; 34 | // int i4 = { 0.9 }; 35 | // A a = { 0.0 }; 36 | 37 | 38 | } 39 | -------------------------------------------------------------------------------- /36列表初始化与类型收窄/36列表初始化 类型收窄/36列表初始化 类型收窄.cpp: -------------------------------------------------------------------------------- 1 | // 36列表初始化 类型收窄.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。 2 | // 3 | 4 | #include 5 | 6 | using namespace std; 7 | 8 | class A { 9 | public: 10 | A(int i) : i_(i) { 11 | 12 | } 13 | 14 | int i_; 15 | 16 | }; 17 | 18 | int main() 19 | { 20 | int i1 = 0.5; 21 | int i2(0.6); 22 | int i3 = { 1 }; 23 | int i4{ 2 }; 24 | A a = { 0 }; 25 | 26 | short si = 10; 27 | __int64 i64{ si }; 28 | 29 | cout << i1 << endl; 30 | cout << i2 << endl; 31 | 32 | // 防止隐式类型转换 33 | // int i3{ 0.9 }; 34 | // int i4 = { 0.9 }; 35 | // A a = { 0.0 }; 36 | 37 | 38 | } 39 | -------------------------------------------------------------------------------- /12强枚举类型/12强枚举类型/12强枚举类型.cpp: -------------------------------------------------------------------------------- 1 | // 12强枚举类型.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。 2 | // 3 | 4 | #include 5 | 6 | using namespace std; 7 | 8 | class A { 9 | public: 10 | enum { 11 | WX, 12 | QQ 13 | }; 14 | }; 15 | 16 | class B { 17 | public: 18 | enum class Type : int 19 | { 20 | WX, 21 | QQ 22 | }; 23 | }; 24 | 25 | int main() 26 | { 27 | cout << A::WX << endl; 28 | 29 | cout << (__int64)B::Type::WX << endl; 30 | 31 | cout << sizeof(B::Type::WX) << endl; 32 | 33 | long i = A::WX; 34 | 35 | // i = B::Type::WX; // 报错 36 | i = (int)B::Type::WX; 37 | } 38 | -------------------------------------------------------------------------------- /README_zh.md: -------------------------------------------------------------------------------- 1 | ## 目录 2 | 3 | ### Part1 4 | 5 | TLS 6 | 7 | static_assert 8 | 9 | long long 10 | 11 | 函数默认模板参数 12 | 13 | 委托构造 14 | 15 | override与final 16 | 17 | 右尖括号 18 | 19 | 改进的for循环 20 | 21 | constexpr 22 | 23 | auto与decltype 24 | 25 | RTTI 26 | 27 | 强枚举 28 | 29 | \_\_func\_\_ 30 | 31 | _Pragma操作符 32 | 33 | 变长参数宏定义 34 | 35 | noexcept 36 | 37 | friend改进 38 | 39 | 外部模板 40 | 41 | 右值引用移动语义 42 | 43 | 右值引用完美转发 44 | 45 | 可执行对象封装器 46 | 47 | lambda表达式、C++闭包 48 | 49 | 原子类型、内存模型 50 | 51 | 多线程 52 | 53 | 智能指针 54 | 55 | nullptr 56 | 57 | POD类型 58 | 59 | chrono库 60 | 61 | 继承构造、using用法 62 | 63 | 变长模板 64 | 65 | Unicode支持 66 | 67 | 用户自定义字面量 68 | 69 | 列表初始化类型收窄 70 | 71 | 通用属性 72 | 73 | 文件系统支持库 74 | 75 | ### Part2 76 | 77 | C++11实现Chrome的多线程模型 78 | -------------------------------------------------------------------------------- /32继承构造函数&using用法/32继承构造函数 using用法/32继承构造函数 using用法.cpp: -------------------------------------------------------------------------------- 1 | // 32继承构造函数 using用法.cpp : 此文件包含 "main" 2 | // 函数。程序执行将在此处开始并结束。 3 | // 4 | 5 | #include 6 | 7 | using namespace std; 8 | 9 | class A { 10 | public: 11 | A(int i) {} 12 | 13 | protected: 14 | void func() { 15 | cout << this << endl; 16 | using INT = int; 17 | // typedef int INT; 18 | INT i = 100; 19 | } 20 | }; 21 | 22 | class A1 { 23 | public: 24 | int i_; 25 | }; 26 | 27 | class B1 : public A { 28 | public: 29 | B1(int i) : A(i) {} 30 | }; 31 | 32 | class B2 : public A1, public A { 33 | public: 34 | using A::A; // 如果B2的构造函数就是为了给A传值 35 | using A::func; // 实际调用仍然是A::func,编译器不会写一个新函数 36 | }; 37 | 38 | int main() { 39 | B2 b2(100); 40 | cout << &b2 << endl; 41 | b2.func(); 42 | cout << static_cast(&b2) << endl; 43 | } 44 | -------------------------------------------------------------------------------- /08基于范围的for语句/08基于范围的for语句/08基于范围的for语句.cpp: -------------------------------------------------------------------------------- 1 | // 08基于范围的for语句.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。 2 | // 3 | 4 | #include 5 | #include 6 | #include 7 | using namespace std; 8 | 9 | // 脚本语言都可以这么用,C++在不断进化 10 | 11 | int main() 12 | { 13 | int arr[] = { 0,1,2,3,4,5,6,7,8,9 }; 14 | 15 | for (auto v : arr) { 16 | cout << v << endl; 17 | } 18 | 19 | string s = "abc"; 20 | for (char& c : s) { 21 | ++c; 22 | } 23 | cout << s << endl; 24 | 25 | list l = { 0,1,2,3,4,5,6,7,8,9 }; 26 | for (auto& v : l) { 27 | ++v; 28 | } 29 | 30 | for (const auto &v : l) { 31 | cout << v << endl; 32 | } 33 | 34 | for (list::iterator it = l.begin(); it != l.end(); ++it) { 35 | (*it)++; 36 | } 37 | 38 | for (list::const_iterator it = l.begin(); it != l.end(); ++it) { 39 | cout << *it << endl; 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /06override与final关键字/06override与final关键字/06override与final关键字.cpp: -------------------------------------------------------------------------------- 1 | // 06override与final关键字.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。 2 | // 3 | 4 | #include 5 | 6 | using namespace std; 7 | 8 | /* 9 | override,final 用于接口,虚函数 10 | final 也可用于声明类 11 | */ 12 | 13 | class Base { 14 | public: 15 | virtual void func() = 0; 16 | virtual void gen() = 0; 17 | }; 18 | 19 | class Derived : public Base { 20 | public: 21 | // 看到override,就知道是重载 22 | virtual void func() override { 23 | cout << "Derived::func()" << endl; 24 | } 25 | virtual void gen() final { 26 | cout << "Derived::gen()" << endl; 27 | } 28 | }; 29 | 30 | class A final : public Derived { 31 | public: 32 | // 表示重载的最终版本 33 | virtual void func() final { 34 | cout << "A::func" << endl; 35 | } 36 | }; 37 | 38 | //class A2 : public A { 39 | // 40 | //}; 41 | 42 | int main() 43 | { 44 | A* a = new A; 45 | Base* ptr = a; 46 | ptr->func(); 47 | ptr->gen(); 48 | } 49 | -------------------------------------------------------------------------------- /34Unicode支持/34Unicode支持/34Unicode支持.cpp: -------------------------------------------------------------------------------- 1 | // 34Unicode支持.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。 2 | // 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | using namespace std; 9 | 10 | int main() 11 | { 12 | std::locale::global(std::locale("zh_CN")); 13 | 14 | wchar_t gbk[] = L"我爱北京天安门"; 15 | 16 | cout << wcslen(gbk) * sizeof(wchar_t) << endl; 17 | 18 | wcout << gbk << endl; 19 | 20 | std::wstring_convert> conv; 21 | std::string utf8 = conv.to_bytes(gbk); 22 | 23 | cout << utf8.length() << endl; 24 | 25 | cout << setiosflags(ios::uppercase) << std::hex; 26 | 27 | for (char c : utf8) { 28 | cout << (unsigned)((unsigned char)c); 29 | } 30 | 31 | cout << endl; 32 | 33 | std::wstring wideStr = conv.from_bytes(utf8); 34 | 35 | // http://www.mytju.com/classcode/tools/encode_gb2312.asp 36 | for (wchar_t wc : wideStr) { 37 | cout << (unsigned)wc; 38 | } 39 | 40 | return 0; 41 | 42 | } 43 | -------------------------------------------------------------------------------- /01thread_local关键字/tls/tls.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 源文件 20 | 21 | 22 | -------------------------------------------------------------------------------- /07右尖括号/07右尖括号/07右尖括号.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 源文件 20 | 21 | 22 | -------------------------------------------------------------------------------- /27智能指针/27智能指针/27智能指针.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 源文件 20 | 21 | 22 | -------------------------------------------------------------------------------- /37通用属性/37通用属性/37通用属性.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 源文件 20 | 21 | 22 | -------------------------------------------------------------------------------- /38文件系统/38文件系统/38文件系统.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 源文件 20 | 21 | 22 | -------------------------------------------------------------------------------- /05委托构造函数/05委托构造函数/05委托构造函数.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 源文件 20 | 21 | 22 | -------------------------------------------------------------------------------- /12强枚举类型/12强枚举类型/12强枚举类型.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 源文件 20 | 21 | 22 | -------------------------------------------------------------------------------- /26多线程&同步/26多线程 同步/26多线程 同步.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 源文件 20 | 21 | 22 | -------------------------------------------------------------------------------- /30POD类型/30POD类型/30POD类型.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 源文件 20 | 21 | 22 | -------------------------------------------------------------------------------- /33变长模板参数/33变长模板参数/33变长模板参数.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 源文件 20 | 21 | 22 | -------------------------------------------------------------------------------- /28nullptr/28nullptr/28nullptr.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 源文件 20 | 21 | 22 | -------------------------------------------------------------------------------- /04函数默认模板参数/04函数默认模板参数/04函数默认模板参数.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 源文件 20 | 21 | 22 | -------------------------------------------------------------------------------- /15变长参数的宏定义/15变长参数的宏定义/15变长参数的宏定义.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 源文件 20 | 21 | 22 | -------------------------------------------------------------------------------- /23可执行对象封装器/23可执行对象封装器/23可执行对象封装器.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 源文件 20 | 21 | 22 | -------------------------------------------------------------------------------- /35用户自定义字面量/35用户自定义字面量/35用户自定义字面量.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 源文件 20 | 21 | 22 | -------------------------------------------------------------------------------- /综合实践c++11实现chrome的线程模型/sample/sample.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 源文件 20 | 21 | 22 | -------------------------------------------------------------------------------- /21右值引用&移动语义/21右值引用 移动语义/21右值引用 移动语义.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 源文件 20 | 21 | 22 | -------------------------------------------------------------------------------- /22右值引用&完美转发/22右值引用 完美转发/22右值引用 完美转发.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 源文件 20 | 21 | 22 | -------------------------------------------------------------------------------- /25原子类型&内存模型/25原子类型 内存模型/25原子类型 内存模型.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 源文件 20 | 21 | 22 | -------------------------------------------------------------------------------- /34Unicode支持/34Unicode支持/34Unicode支持.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 源文件 20 | 21 | 22 | -------------------------------------------------------------------------------- /08基于范围的for语句/08基于范围的for语句/08基于范围的for语句.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 源文件 20 | 21 | 22 | -------------------------------------------------------------------------------- /16noexcept关键字/16noexcept关键字/16noexcept关键字.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 源文件 20 | 21 | 22 | -------------------------------------------------------------------------------- /19friend友元改进/19friend友元改进/19friend友元改进.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 源文件 20 | 21 | 22 | -------------------------------------------------------------------------------- /36列表初始化&类型收窄/36列表初始化 类型收窄/36列表初始化 类型收窄.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 源文件 20 | 21 | 22 | -------------------------------------------------------------------------------- /36列表初始化与类型收窄/36列表初始化 类型收窄/36列表初始化 类型收窄.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 源文件 20 | 21 | 22 | -------------------------------------------------------------------------------- /03long long关键字/03long long关键字/03long long关键字.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 源文件 20 | 21 | 22 | -------------------------------------------------------------------------------- /09constexpr关键字/09constexpr关键字/09constexpr关键字.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 源文件 20 | 21 | 22 | -------------------------------------------------------------------------------- /17类定义里面初始化成员变量/17类定义里面初始化成员变量/17类定义里面初始化成员变量.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 源文件 20 | 21 | 22 | -------------------------------------------------------------------------------- /18非静态成员的sizeof/18非静态成员的sizeof/18非静态成员的sizeof.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 源文件 20 | 21 | 22 | -------------------------------------------------------------------------------- /02static_assert&__cplusplus宏/static_assert/static_assert.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 源文件 20 | 21 | 22 | -------------------------------------------------------------------------------- /13__func__返回函数名字/13__func__返回函数名字/13__func__返回函数名字.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 源文件 20 | 21 | 22 | -------------------------------------------------------------------------------- /29default&delete/29default delete/29default delete.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 源文件 20 | 21 | 22 | -------------------------------------------------------------------------------- /32继承构造函数&using用法/32继承构造函数 using用法/32继承构造函数 using用法.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 源文件 20 | 21 | 22 | -------------------------------------------------------------------------------- /10auto&decltype关键字/10auto decltype关键字/10auto decltype关键字.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 源文件 20 | 21 | 22 | -------------------------------------------------------------------------------- /10auto与decltype关键字/10auto与decltype关键字/10auto decltype关键字.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 源文件 20 | 21 | 22 | -------------------------------------------------------------------------------- /06override与final关键字/06override与final关键字/06override与final关键字.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 源文件 20 | 21 | 22 | -------------------------------------------------------------------------------- /14_Pragma操作符/14_Pragma操作符/14_Pragma操作符.cpp: -------------------------------------------------------------------------------- 1 | // 14_Pragma操作符.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。 2 | // 3 | // https://docs.microsoft.com/zh-cn/cpp/preprocessor/pragma-directives-and-the-pragma-keyword?view=msvc-170 4 | 5 | #pragma once 6 | _Pragma("once") 7 | 8 | #pragma pack(push, 1) 9 | struct MyStruct1 10 | { 11 | char c; 12 | int i; 13 | }; 14 | #pragma pack(pop) 15 | 16 | _Pragma("pack(push, 1)") 17 | struct MyStruct2 18 | { 19 | char c; 20 | int i; 21 | }; 22 | _Pragma("pack(pop)") 23 | 24 | #define PRAGPUSH(x) PRAGMA(pack(push, x)) // _Pragma 的好处是支持宏语法 25 | #define PRAGMA(x) _Pragma(#x) 26 | #define PRAGPOP _Pragma("pack(pop)") 27 | 28 | PRAGPUSH(1) 29 | struct MyStruct3 30 | { 31 | char c; 32 | int i; 33 | }; 34 | PRAGPOP 35 | 36 | struct MyStruct4 37 | { 38 | char c; 39 | int i; 40 | }; 41 | 42 | #include 43 | 44 | using namespace std; 45 | 46 | int main() 47 | { 48 | cout << sizeof(MyStruct1) << endl; 49 | cout << sizeof(MyStruct2) << endl; 50 | cout << sizeof(MyStruct3) << endl; 51 | cout << sizeof(MyStruct4) << endl; 52 | } 53 | -------------------------------------------------------------------------------- /11RTTI&typeid&dynamic_cast/11RTTI typeid dynamic_cast/11RTTI typeid dynamic_cast.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 源文件 20 | 21 | 22 | -------------------------------------------------------------------------------- /14_Pragma操作符/14_Pragma操作符/14_Pragma操作符.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 源文件 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /09constexpr关键字/09constexpr关键字/09constexpr关键字.cpp: -------------------------------------------------------------------------------- 1 | // 09constexpr关键字.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。 2 | // 3 | 4 | #include 5 | #include 6 | 7 | using namespace std; 8 | 9 | unsigned int func() { 10 | default_random_engine e; 11 | return e(); 12 | } 13 | 14 | // 函数返回值是常量,编译期可决议出来 15 | template 16 | constexpr T clone(const T& t) { 17 | return t; 18 | } 19 | 20 | int main() 21 | { 22 | const int i = 0; 23 | { 24 | constexpr int i = 0; 25 | } 26 | // 运行期间初始化后不能再赋值 27 | const unsigned int b = func(); 28 | { 29 | // 无法编译 30 | // constexpr unsigned int b = func(); 31 | } 32 | 33 | cout << b << endl; 34 | 35 | { 36 | constexpr int a = 100; 37 | cout << clone(a); cout <<" " << 100 << endl; 38 | } 39 | 40 | { 41 | random_device rd; 42 | default_random_engine e { rd() }; 43 | // 尽可能编译过不报错,退化为 44 | /* 45 | template 46 | T clone(const T& t) { 47 | return t; 48 | } 49 | */ 50 | cout << clone(e()); 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /31chrono库/31chrono库/31chrono库.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 源文件 20 | 21 | 22 | 23 | 24 | 资源文件 25 | 26 | 27 | -------------------------------------------------------------------------------- /23可执行对象封装器/23可执行对象封装器/23可执行对象封装器.cpp: -------------------------------------------------------------------------------- 1 | // 23可执行对象封装器.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。 2 | // 3 | 4 | #include 5 | #include 6 | 7 | using namespace std; 8 | 9 | class A { 10 | public: 11 | A() = default; 12 | A(int i) : m_i(i) { 13 | std::cout << "A(int i)" << std::endl; 14 | } 15 | void func(double d) { 16 | std::cout << d - m_i << std::endl; 17 | } 18 | ~A() { 19 | std::cout << "~A()" << std::endl; 20 | } 21 | private: 22 | int m_i; 23 | }; 24 | 25 | int func(int i) { 26 | cout << i << endl; 27 | return i; 28 | } 29 | 30 | std::function obtain() { 31 | return std::bind(&A::func, std::make_shared(100), std::placeholders::_1); 32 | } 33 | int main() { 34 | { 35 | auto func = obtain(); 36 | func(100.5); 37 | } 38 | 39 | { 40 | std::function funcc = std::bind(&func, 101); 41 | int r = funcc(); 42 | cout << r << endl; 43 | } 44 | 45 | { 46 | std::function funcc = std::bind(&func, std::placeholders::_1); 47 | funcc(101); 48 | } 49 | 50 | 51 | return 0; 52 | 53 | } 54 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Table of contents 2 | 3 | [中文目录](./README_zh.md) 4 | 5 | ### Part1 6 | 7 | TLS 8 | 9 | static_assert 10 | 11 | long long 12 | 13 | Function default template parameters 14 | 15 | Delegate construct 16 | 17 | override and final 18 | 19 | right angle bracket 20 | 21 | Improved for loop 22 | 23 | constexpr 24 | 25 | auto and decltype 26 | 27 | RTTI 28 | 29 | strong enumeration 30 | 31 | \_\_func\_\_ 32 | 33 | _Pragma operator 34 | 35 | Variable length parameter macro definition 36 | 37 | noexcept 38 | 39 | friend improvements 40 | 41 | external template 42 | 43 | rvalue reference move semantics 44 | 45 | rvalue reference perfect forwarding 46 | 47 | Executable object wrapper 48 | 49 | lambda expression, C++ closure 50 | 51 | Atomic types, memory models 52 | 53 | Multithreading 54 | 55 | smart pointer 56 | 57 | nullptr 58 | 59 | POD type 60 | 61 | chrono library 62 | 63 | Inheritance construction, using usage 64 | 65 | variable length template 66 | 67 | Unicode support 68 | 69 | User-defined literal 70 | 71 | List initialization type narrowing 72 | 73 | Common properties 74 | 75 | File system support library 76 | 77 | ### Part2 78 | 79 | C++11 implements Chrome’s multi-threading model 80 | -------------------------------------------------------------------------------- /综合实践c++11实现chrome的线程模型/base/event.h: -------------------------------------------------------------------------------- 1 | _Pragma("once"); 2 | 3 | #ifdef _WIN32 4 | #include 5 | #else 6 | 7 | #endif 8 | 9 | #include "./time.h" 10 | 11 | namespace base { 12 | 13 | #ifdef _WIN32 14 | class WaitableEvent { 15 | public: 16 | explicit WaitableEvent(bool manual_reset, bool initially_signaled); 17 | explicit WaitableEvent(HANDLE event_handle); 18 | 19 | WaitableEvent(const WaitableEvent&) = delete; 20 | WaitableEvent(WaitableEvent&&) = delete; 21 | void operator=(const WaitableEvent&) = delete; 22 | 23 | ~WaitableEvent(); 24 | 25 | HANDLE Release(); 26 | HANDLE handle() const { return handle_; } 27 | 28 | // Put the event in the un-signaled state. 29 | void Reset(); 30 | 31 | // Put the event in the signaled state. Causing any thread blocked on Wait 32 | // to be woken up. 33 | void Signal(); 34 | 35 | // Wait indefinitely for the event to be signaled. 36 | void Wait(); 37 | 38 | bool TimedWait(const std::chrono::milliseconds& max_time); 39 | 40 | private: 41 | HANDLE handle_ = 0; 42 | }; 43 | 44 | #else 45 | 46 | #endif 47 | 48 | 49 | 50 | } // end base 51 | -------------------------------------------------------------------------------- /20外部模板/20外部模板/20外部模板.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 源文件 20 | 21 | 22 | 源文件 23 | 24 | 25 | 26 | 27 | 头文件 28 | 29 | 30 | -------------------------------------------------------------------------------- /综合实践c++11实现chrome的线程模型/base/message_pump_default.h: -------------------------------------------------------------------------------- 1 | _Pragma("once") 2 | 3 | #include "./message_pump.h" 4 | #include "./event.h" 5 | 6 | namespace base { 7 | class MessagePumpDefault : public MessagePump { 8 | public: 9 | explicit MessagePumpDefault(); 10 | virtual ~MessagePumpDefault(); 11 | 12 | MessagePumpDefault(const MessagePumpDefault&) = delete; 13 | MessagePumpDefault(MessagePumpDefault&&) = delete; 14 | void operator=(const MessagePumpDefault&) = delete; 15 | void operator=(MessagePumpDefault&&) = delete; 16 | 17 | // MessagePump methods: 18 | virtual void Run(Delegate* delegate) final; 19 | virtual void Quit() final; 20 | virtual void ScheduleWork() final; 21 | virtual void ScheduleDelayedWork(const TimeTicks& delayed_work_time) final; 22 | 23 | private: 24 | // This flag is set to false when Run should return. 25 | bool keep_running_; 26 | 27 | // Used to sleep until there is more work to do. 28 | WaitableEvent event_; 29 | 30 | // The time at which we should call DoDelayedWork. 31 | TimeTicks delayed_work_time_; 32 | 33 | }; 34 | 35 | } // end base 36 | -------------------------------------------------------------------------------- /30POD类型/30POD类型/30POD类型.cpp: -------------------------------------------------------------------------------- 1 | // 30POD类型.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。 2 | // 3 | 4 | #include 5 | 6 | using namespace std; 7 | 8 | class A { 9 | A() = default; 10 | int a_; 11 | int b_; 12 | }; 13 | 14 | struct B { 15 | B() {} 16 | int b_; 17 | }; 18 | 19 | class C { 20 | public: 21 | C() = default; 22 | C(int i) : c_(0) { i_ = i; } 23 | int i_; 24 | 25 | private: 26 | char c_; 27 | }; 28 | 29 | int main() { 30 | std::cout << std::boolalpha; 31 | 32 | #pragma region 平凡类型(trivial),可靠的复制 33 | { 34 | // 有默认构造函数 35 | std::cout << std::is_trivial::value << '\n'; 36 | std::cout << std::is_trivial::value << '\n'; 37 | std::cout << std::is_trivial::value << '\n'; 38 | } 39 | #pragma endregion 40 | cout << endl; 41 | #pragma region 标准布局类型,C语言安全的访问 42 | { 43 | // 成员变量访问权限一致 44 | std::cout << std::is_standard_layout::value << '\n'; 45 | std::cout << std::is_standard_layout::value << '\n'; 46 | std::cout << std::is_standard_layout::value << '\n'; 47 | } 48 | #pragma endregion 49 | cout << endl; 50 | #pragma region 简单旧数据类型,POD 51 | { 52 | std::cout << std::is_pod::value << '\n'; 53 | std::cout << std::is_pod::value << '\n'; 54 | std::cout << std::is_pod::value << '\n'; 55 | } 56 | #pragma endregion 57 | } 58 | -------------------------------------------------------------------------------- /24lambda表达式/24lambda表达式/24lambda表达式.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 源文件 20 | 21 | 22 | 23 | 24 | 资源文件 25 | 26 | 27 | 资源文件 28 | 29 | 30 | 资源文件 31 | 32 | 33 | -------------------------------------------------------------------------------- /35用户自定义字面量/35用户自定义字面量/35用户自定义字面量.cpp: -------------------------------------------------------------------------------- 1 | // 35用户自定义字面量.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。 2 | // 3 | 4 | #include 5 | #include 6 | 7 | using namespace std; 8 | 9 | class RGB { 10 | public: 11 | RGB(char const* v, size_t n) { 12 | const char* r = v, * g = nullptr, * b = nullptr, * p = nullptr; 13 | for (p = v; p != v + n; ++p) { 14 | if (*p == ',') { 15 | if (!g) { 16 | r_ = atoi(string(r, p - r).c_str()); 17 | g = p + 1; 18 | continue; 19 | } 20 | if (!b) { 21 | g_ = atoi(string(g, p - g).c_str()); 22 | b = p + 1; 23 | b_ = atoi(string(b, v + strlen(v) - b).c_str()); 24 | break; 25 | } 26 | } 27 | } 28 | } 29 | void func() { 30 | cout << "R=" << r_ << ",G=" << g_ << ",B=" << b_ << endl; 31 | } 32 | 33 | unsigned int r_ = 0; 34 | unsigned int g_ = 0; 35 | unsigned int b_ = 0; 36 | 37 | }; 38 | 39 | RGB operator""_rgb(const char * v, size_t n) { 40 | return RGB(v, n); 41 | } 42 | 43 | int main() 44 | { 45 | std::this_thread::sleep_for(100ms); 46 | // std::this_thread::sleep_for(std::chrono::milliseconds(100)); 47 | 48 | RGB lrgb = "25,255,55"_rgb; 49 | 50 | lrgb.func(); 51 | 52 | return 0; 53 | 54 | } 55 | -------------------------------------------------------------------------------- /38文件系统/38文件系统/38文件系统.cpp: -------------------------------------------------------------------------------- 1 | // 38文件系统.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | // C++17 支持 filesystem 9 | namespace fs = std::filesystem; 10 | 11 | // 读文件到string 12 | std::string ReadFileIntoString(const fs::path& path) { 13 | std::ifstream ifile(path); 14 | std::ostringstream buf; 15 | char ch; 16 | while (buf && ifile.get(ch)) { 17 | buf.put(ch); 18 | } 19 | return buf.str(); 20 | } 21 | 22 | int main() { 23 | // 返回当前工作路径 24 | std::cout << "Current path is: " << fs::current_path() << '\n'; 25 | // 若存在则返回路径的根路径 26 | std::cout << "Current path is: " << fs::current_path().root_path() << '\n'; 27 | // 若存在则返回路径的根名 28 | std::cout << "Current path is: " << fs::current_path().root_name() << '\n'; 29 | 30 | fs::path path = fs::current_path(); 31 | // 转换到字符串的原生路径名格式 32 | std::cout << path.string() << "\n"; 33 | // 转换到字符串的通用路径名格式 34 | std::cout << path.generic_string() << "\n"; 35 | 36 | // 连接路径,添加路径分隔符 37 | path /= "abc.txt"; 38 | std::cout << path.string() << "\n"; 39 | // 移除路径中的文件名 40 | path = path.remove_filename(); 41 | std::cout << path.string() << "\n"; 42 | // 创建新目录 43 | fs::create_directories(path); 44 | 45 | path /= "abc.txt"; 46 | // 移除一个文件或空目录 47 | fs::remove(path); 48 | 49 | system("pause"); 50 | return 0; 51 | 52 | } 53 | -------------------------------------------------------------------------------- /综合实践c++11实现chrome的线程模型/sample/sample.cpp: -------------------------------------------------------------------------------- 1 | // sample.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。 2 | // 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include "../base/thread.h" 10 | #include "../base/time.h" 11 | 12 | using namespace std; 13 | 14 | class A { 15 | public: 16 | void func1(int i, double d) { 17 | std::cout << "func1" << " i= " << i << " d=" << d << std::endl; 18 | } 19 | 20 | void func2() { 21 | std::cout << "func2 i_=" << i_++ << std::endl; 22 | } 23 | static int i_; 24 | }; 25 | 26 | int A::i_ = 0; 27 | 28 | int main() 29 | { 30 | using namespace std::chrono_literals; 31 | 32 | base::Thread thread; 33 | thread.StartWithOptions(base::Thread::Options()); 34 | 35 | std::shared_ptr ptr = std::make_shared(); 36 | 37 | int i = 0; 38 | double d = 3.0; 39 | 40 | for (;;) { 41 | ++i; 42 | thread.message_loop()->PostTask(std::bind(&A::func1, ptr, i, ++d)); 43 | thread.message_loop()->PostDelayedTask(std::bind(&A::func2, ptr), 10ms); 44 | 45 | if (i > 100) { 46 | break; 47 | } 48 | } 49 | 50 | while ((!_kbhit() || _getch() != 27)) { 51 | std::cout << static_cast(base::TimeTicks::Now().ToInternalValue() / 1000) << std::endl; 52 | std::this_thread::sleep_for(2s); 53 | } 54 | 55 | thread.Stop(); 56 | 57 | return 0; 58 | 59 | } 60 | -------------------------------------------------------------------------------- /综合实践c++11实现chrome的线程模型/base/time.cpp: -------------------------------------------------------------------------------- 1 | #include "./time.h" 2 | 3 | namespace base { 4 | 5 | bool TimeTicks::is_null() const { 6 | return ( 0 == ticks_.time_since_epoch().count() ); 7 | } 8 | 9 | // static 10 | TimeTicks TimeTicks::Now() { 11 | return TimeTicks(std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch())); 12 | } 13 | 14 | std::chrono::milliseconds TimeTicks::FromDays(int days) { 15 | return std::chrono::duration_cast(std::chrono::duration >(days)); 16 | } 17 | 18 | std::chrono::milliseconds TimeTicks::FromHours(int hours) { 19 | return std::chrono::duration_cast(std::chrono::hours(hours)); 20 | } 21 | 22 | std::chrono::milliseconds TimeTicks::FromMinutes(int minutes) { 23 | return std::chrono::duration_cast(std::chrono::minutes(minutes)); 24 | } 25 | 26 | std::chrono::milliseconds TimeTicks::FromSeconds(long long secs) { 27 | return std::chrono::duration_cast(std::chrono::seconds(secs)); 28 | } 29 | 30 | std::chrono::milliseconds TimeTicks::FromMilliseconds(long long ms) { 31 | return std::chrono::milliseconds(ms); 32 | } 33 | 34 | std::chrono::milliseconds TimeTicks::FromMicroseconds(long long us) { 35 | return std::chrono::duration_cast(std::chrono::microseconds(us)); 36 | } 37 | 38 | } // end base 39 | -------------------------------------------------------------------------------- /21右值引用&移动语义/21右值引用 移动语义/21右值引用 移动语义.cpp: -------------------------------------------------------------------------------- 1 | // 21右值引用 移动语义.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。 2 | // 3 | 4 | #include 5 | #include 6 | 7 | using namespace std; 8 | 9 | class A { 10 | public: 11 | A() { 12 | i_ = 101; 13 | } 14 | 15 | ~A() { 16 | delete ptr_; 17 | } 18 | 19 | A(const A& a); 20 | 21 | A(A&& a) noexcept { 22 | if (ptr_) { 23 | delete ptr_; 24 | } 25 | ptr_ = a.ptr_; 26 | a.ptr_ = nullptr; 27 | }; 28 | 29 | A& operator=(const A& a) { 30 | 31 | } 32 | 33 | A& operator=(A&& a) { 34 | 35 | } 36 | 37 | int i_ = 100; 38 | int* ptr_ = nullptr; 39 | }; 40 | 41 | A::A(const A& a) { 42 | i_ = a.i_; 43 | if (a.ptr_) { 44 | ptr_ = new int{ *a.ptr_ }; 45 | } 46 | 47 | } 48 | 49 | A func() { 50 | A a; 51 | return a; 52 | } 53 | 54 | string func1() { 55 | string s = "abc"; 56 | // 请勿使用std::move返回局部变量 57 | // return std::move(s); 58 | return s; 59 | } 60 | 61 | int main() 62 | { 63 | { 64 | // 语法作用:提升性能 65 | A a = func(); 66 | //cout << a.i_ << endl; 67 | 68 | string r = func1(); 69 | 70 | } 71 | 72 | { 73 | string s1 = "abc..."; 74 | string s2 = std::move(s1); // 移动构造,执行完成后,s1就不再使用了 75 | } 76 | 77 | { 78 | A a; 79 | a.ptr_ = new int{ 100 }; 80 | cout << a.ptr_ << " " << *a.ptr_ << endl; 81 | A a1{ a }; 82 | 83 | cout << a.ptr_ << endl; 84 | 85 | cout << a1.ptr_ << " " << *a1.ptr_ << endl; 86 | 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /01thread_local关键字/tls/tls.cpp: -------------------------------------------------------------------------------- 1 | // tls.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。 2 | // 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | using namespace std; 9 | 10 | // 线程内部的全局变量 11 | 12 | DWORD slot_ = TlsAlloc(); 13 | 14 | //int i = 0; 15 | thread_local int i = 0; // 可以理解为对不同操作系统相关一组TLS API的封装,以提供统一使用界面 16 | 17 | class A { 18 | public: 19 | thread_local static int i; 20 | }; 21 | 22 | thread_local int A::i = 0; 23 | 24 | void func() { 25 | for (;;) { 26 | int i = (int)TlsGetValue(slot_); 27 | TlsSetValue(slot_, (LPVOID)++i); 28 | cout << i << endl; 29 | if (i > 10) 30 | break; 31 | } 32 | } 33 | 34 | void func1() { 35 | for (;;) { 36 | ++A::i; 37 | cout << "func1 " << A::i << endl; 38 | if (A::i > 10) 39 | break; 40 | } 41 | } 42 | 43 | void func2() { 44 | for (;;) { 45 | ++A::i; 46 | cout << "func2 " << A::i << endl; 47 | if (A::i > 10) 48 | break; 49 | } 50 | } 51 | 52 | void func3() { 53 | thread_local int i = 1; // 编译器按照static处理 54 | for (;;) { 55 | cout << ++i << endl; 56 | if (i > 10) 57 | break; 58 | } 59 | } 60 | 61 | int main() 62 | { 63 | { 64 | thread t1(func); 65 | this_thread::sleep_for(500ms); 66 | thread t2(func); 67 | 68 | t1.join(); 69 | t2.join(); 70 | } 71 | 72 | 73 | { 74 | //thread t1(func3); 75 | //this_thread::sleep_for(500ms); 76 | //thread t2(func3); 77 | 78 | //t1.join(); 79 | //t2.join(); 80 | } 81 | 82 | } 83 | -------------------------------------------------------------------------------- /33变长模板参数/33变长模板参数/33变长模板参数.cpp: -------------------------------------------------------------------------------- 1 | // 33变长模板参数.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。 2 | // 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | using namespace std; 9 | 10 | template 11 | void tfunc(T t) { 12 | cout << t << endl; 13 | } 14 | 15 | template 16 | void tfunc(T t, Types... args) { 17 | cout << t << endl; 18 | tfunc(args...); 19 | } 20 | 21 | template 22 | class A1 { 23 | public: 24 | A1() { 25 | // 打印模板参数个数 26 | cout << sizeof...(Types) << endl; 27 | } 28 | }; 29 | 30 | template class Tuple; 31 | 32 | template 33 | class Tuple : public Tuple { 34 | public: 35 | Tuple(T t, Types... args) : Tuple(args...) { 36 | t_ = t; 37 | } 38 | T t_; 39 | void output() { 40 | cout << t_ << endl; 41 | Tuple::output(); 42 | } 43 | }; 44 | 45 | template<> 46 | class Tuple <> { 47 | public: 48 | void output() {} 49 | }; 50 | 51 | int main() 52 | { 53 | tfunc(1, 2, 3); 54 | 55 | A1 ta1; 56 | 57 | cout << endl; 58 | 59 | { 60 | std::tuple tuple3 = std::make_tuple(0.1, 1, "hello"); 61 | cout << std::get<0>(tuple3) << endl; 62 | cout << std::get<1>(tuple3) << endl; 63 | cout << std::get<2>(tuple3) << endl; 64 | } 65 | 66 | cout << endl; 67 | 68 | { 69 | Tuple tple(1, 1.3, "hello"); 70 | tple.output(); 71 | } 72 | 73 | return 0; 74 | } 75 | -------------------------------------------------------------------------------- /27智能指针/27智能指针/27智能指针.cpp: -------------------------------------------------------------------------------- 1 | // 27智能指针.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。 2 | // 3 | 4 | #include 5 | #include 6 | 7 | using namespace std; 8 | 9 | class A : public std::enable_shared_from_this { 10 | public: 11 | A() = default; 12 | ~A() { 13 | cout << "~A()" << endl; 14 | } 15 | void func(int i) { 16 | cout << "A::func(" << i << ")" << endl; 17 | } 18 | }; 19 | 20 | int main() 21 | { 22 | { 23 | std::unique_ptr ptr = std::make_unique(); // unique_ptr 24 | std::unique_ptr ptr2 = std::move(ptr); 25 | ptr2->func(0); 26 | } 27 | 28 | cout< ptr = std::make_shared(); // shared_ptr 32 | std::shared_ptr ptr2 = ptr; 33 | ptr->func(0); 34 | ptr2->func(1); 35 | } 36 | 37 | cout << endl; 38 | 39 | { 40 | // 管理数组 41 | std::shared_ptr tmpcbuf{ new char[4096], std::default_delete() }; 42 | } 43 | 44 | { 45 | A* ptmp = new A(); 46 | { 47 | std::shared_ptr ptr(ptmp); 48 | std::shared_ptr ptr2 = ptmp->shared_from_this(); // 类从继承enable_shared_from_this 49 | cout << ptr2 << endl; 50 | } 51 | 52 | // std::shared_ptr ptr2 = ptmp->shared_from_this(); // ptmp已经析构,不能再调用 53 | 54 | } 55 | 56 | cout << endl; 57 | 58 | { 59 | std::shared_ptr ptr = std::make_shared(); 60 | std::weak_ptr weakptr{ ptr }; // 弱指针 61 | { 62 | weakptr.lock()->func(1); 63 | } 64 | ptr.reset(); 65 | cout << weakptr.lock().get() << endl; 66 | } 67 | 68 | } 69 | -------------------------------------------------------------------------------- /24lambda表达式/24lambda表达式/24lambda表达式.cpp: -------------------------------------------------------------------------------- 1 | // 24lambda表达式.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。 2 | // 3 | 4 | #include 5 | #include 6 | 7 | using namespace std; 8 | 9 | class A { 10 | public: 11 | A() { 12 | cout << "A()" << endl; 13 | }; 14 | A(const A& a) { 15 | cout << "A(const A&)" << endl; 16 | } 17 | A(A&& a) noexcept { 18 | cout << "A(A&&) noexcept" << endl; 19 | } 20 | A& operator=(const A& a) { 21 | cout << "operator=(const A& a)" << endl; 22 | return *this; 23 | } 24 | 25 | A& operator=(A&& a) noexcept { 26 | cout << "operator=(A&& a) noexcept" << endl; 27 | return *this; 28 | } 29 | 30 | int i_ = 100; 31 | 32 | }; 33 | 34 | auto func() { 35 | A a; 36 | auto f = ( 37 | [=]() { // = 表示复制一份a,调用的是拷贝构造函数 38 | cout << "a.i_=" << a.i_ << endl; 39 | } 40 | ); 41 | 42 | return f; 43 | } 44 | 45 | int main() 46 | { 47 | { 48 | A a; 49 | auto f = ( 50 | [&]() { // 以引用的方式使用a 51 | cout << "a.i_=" << a.i_ << endl; 52 | } 53 | ); 54 | f(); 55 | 56 | cout << endl; 57 | } 58 | 59 | { 60 | std::function f = func(); 61 | f(); 62 | cout << endl; 63 | } 64 | 65 | { 66 | A a; 67 | auto lam = [=](int i) mutable -> int { // 使用mutable表示可以改变变量a的值 68 | a.i_ = 101; // 修改a的值 69 | cout << "a.i_=" << a.i_ << endl; 70 | cout << "i=" << i << endl; 71 | return 103; 72 | }; 73 | auto r = lam(102); 74 | cout << "r=" << r << endl; 75 | } 76 | 77 | } 78 | -------------------------------------------------------------------------------- /25原子类型&内存模型/25原子类型 内存模型/25原子类型 内存模型.cpp: -------------------------------------------------------------------------------- 1 | // 25原子类型 内存模型.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。 2 | // 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | using namespace std; 9 | 10 | int main() { 11 | { 12 | // long、int、long long、short、char、wchar_t 13 | // 编译器保证原子类型在多线程间互斥的访问 14 | std::atomic a; 15 | a = 0; 16 | a.store(0); 17 | a = 1; 18 | cout << a.load() << endl; 19 | cout << a << endl; 20 | std::cout << a.fetch_add(1) << std::endl; 21 | cout << a.load() << std::endl; 22 | // CAS(compare and set) 23 | cout << "测试compare_exchange" << endl; 24 | { 25 | int i = 2; 26 | cout << "a=" << a << ",i=" << i << endl; 27 | bool r = a.compare_exchange_strong(i, 10); // 原子地比较原子对象与非原子参数的值,若相等则进行交换,若不相等则进行加载 28 | cout << "a.compare_exchange_strong(i, 10)的返回值是" << r << ",a = " << a << ",i = " << i << endl; 29 | } 30 | { 31 | a = 2; 32 | int i = 1; 33 | cout << "a=" << a << ",i=" << i << endl; 34 | bool r = a.compare_exchange_strong(i, 10); 35 | cout << "a.compare_exchange_strong(i, 10)的返回值是" << r << ",a = " << a << ",i = " << i << endl; 36 | } 37 | // 原子交换 38 | { 39 | cout << "测试原子交换exchange" << endl; 40 | cout << "a=" << a << endl; 41 | cout << "a.exchange(100)的返回值是" << a.exchange(100) << endl; 42 | cout << "a=" << a << endl; 43 | } 44 | 45 | } 46 | 47 | { 48 | int a = 0; 49 | int b = 0; 50 | _ReadWriteBarrier(); // 内存栅栏 51 | int c = 0; 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /综合实践c++11实现chrome的线程模型/base/pending_task.h: -------------------------------------------------------------------------------- 1 | _Pragma("once") 2 | 3 | #include 4 | #include 5 | #include "./time.h" 6 | 7 | namespace base { 8 | 9 | class PendingTask { 10 | public: 11 | using closure = std::function; 12 | 13 | PendingTask(); 14 | 15 | PendingTask(const PendingTask& other); 16 | 17 | PendingTask(PendingTask&& other) noexcept; 18 | 19 | PendingTask(const closure& task); 20 | 21 | PendingTask(closure&& task) noexcept; 22 | 23 | PendingTask(const closure& task, const TimeTicks& delayed_run_time); 24 | 25 | PendingTask(closure&& task, const TimeTicks& delayed_run_time) noexcept; 26 | 27 | PendingTask& operator=(const PendingTask& other); 28 | 29 | PendingTask& operator=(PendingTask&& other) noexcept; 30 | 31 | bool Equals(const PendingTask& other) const; 32 | 33 | inline bool callable(); 34 | 35 | void Run(); 36 | 37 | bool operator<(const PendingTask& other) const; 38 | 39 | TimeTicks delayed_run_time_; 40 | mutable unsigned int sequence_num_ = 0; 41 | 42 | private: 43 | std::function task_; 44 | }; 45 | 46 | // Queue of PendingTask 47 | class TaskQueue { 48 | public: 49 | TaskQueue() : sequence_num_(0) { 50 | _val.clear(); 51 | } 52 | ~TaskQueue() { 53 | _val.clear(); 54 | } 55 | bool empty(); 56 | void emplace_back(const PendingTask& task); 57 | PendingTask pick_front() noexcept ; 58 | const PendingTask& front(); 59 | void swap(TaskQueue& val); 60 | 61 | private: 62 | std::list _val; 63 | unsigned int sequence_num_ = 0; 64 | 65 | }; 66 | 67 | 68 | } // end base 69 | -------------------------------------------------------------------------------- /综合实践c++11实现chrome的线程模型/base/event.cpp: -------------------------------------------------------------------------------- 1 | #include "./event.h" 2 | #include 3 | 4 | namespace base { 5 | #ifdef _WIN32 6 | 7 | WaitableEvent::WaitableEvent(bool manual_reset, bool signaled) 8 | : handle_(CreateEvent(NULL, manual_reset, signaled, NULL)) { 9 | // We're probably going to crash anyways if this is ever NULL, so we might as 10 | // well make our stack reports more informative by crashing here. 11 | assert(handle_); 12 | } 13 | 14 | WaitableEvent::WaitableEvent(HANDLE event_handle) 15 | : handle_(event_handle) { 16 | assert(handle_ != INVALID_HANDLE_VALUE); 17 | } 18 | 19 | HANDLE WaitableEvent::Release() { 20 | HANDLE rv = handle_; 21 | handle_ = NULL; 22 | return rv; 23 | } 24 | 25 | WaitableEvent::~WaitableEvent() { 26 | assert(handle_); 27 | CloseHandle(handle_); 28 | handle_ = NULL; 29 | } 30 | 31 | void WaitableEvent::Reset() { 32 | ResetEvent(handle_); 33 | } 34 | 35 | void WaitableEvent::Signal() { 36 | SetEvent(handle_); 37 | } 38 | 39 | // Wait indefinitely for the event to be signaled. 40 | void WaitableEvent::Wait() { 41 | DWORD result = WaitForSingleObject(handle_, INFINITE); 42 | } 43 | 44 | bool WaitableEvent::TimedWait(const std::chrono::milliseconds& max_time) { 45 | DWORD result = WaitForSingleObject(handle_, static_cast(max_time.count())); 46 | switch (result) { 47 | case WAIT_OBJECT_0: 48 | return true; 49 | case WAIT_TIMEOUT: 50 | return false; 51 | } 52 | // It is most unexpected that this should ever fail. Help consumers learn 53 | // about it if it should ever fail. 54 | assert(0); 55 | return false; 56 | } 57 | 58 | #else 59 | 60 | 61 | 62 | 63 | 64 | 65 | #endif 66 | 67 | 68 | } // end base 69 | -------------------------------------------------------------------------------- /22右值引用&完美转发/22右值引用 完美转发/22右值引用 完美转发.cpp: -------------------------------------------------------------------------------- 1 | // 22右值引用 完美转发.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。 2 | // 3 | 4 | #include 5 | #include 6 | 7 | using namespace std; 8 | 9 | void print(string& s) { 10 | cout << "print(string& s)" << endl; 11 | } 12 | 13 | void print(string&& s) { 14 | cout << "print(string&& s)" << endl; 15 | } 16 | 17 | template 18 | void func(Ty&& s) { 19 | std::cout << "is_lvalue_reference:" << std::is_lvalue_reference::value << endl; // C++11新增语法,用来进行左右值判断 20 | std::cout << "is_rvalue_reference:" << std::is_rvalue_reference::value << endl; 21 | //print(s); 22 | print(std::forward(s)); // 完美转发。如果是左值,按照左值传递;如果是右值,按照右值传递。新增了一个规则:引用折叠 23 | } 24 | 25 | int main() 26 | { 27 | std::cout << std::boolalpha; 28 | { 29 | std::cout << "is_lvalue_reference:" << std::endl; 30 | std::cout << "int: " << std::is_lvalue_reference::value << std::endl; 31 | std::cout << "int&: " << std::is_lvalue_reference::value << std::endl; 32 | std::cout << "int&&: " << std::is_lvalue_reference::value << std::endl; 33 | std::cout << "is_rvalue_reference:" << std::endl; 34 | std::cout << "int&&: " << std::is_rvalue_reference::value << std::endl; 35 | } 36 | string s1{ "hello world" }; 37 | string& s1_lr = s1; 38 | { 39 | std::cout << std::is_lvalue_reference::value << std::endl; 40 | std::cout << std::is_lvalue_reference::value << std::endl; 41 | } 42 | cout << endl; 43 | 44 | string&& s1_rr = static_cast(s1); 45 | //string&& s1_rr = s1; 46 | std::cout << std::is_rvalue_reference::value << std::endl; 47 | 48 | func(s1); 49 | func(s1_lr); 50 | func(s1_rr); 51 | func(static_cast(s1)); 52 | /* 53 | 左值->左值引用 54 | 右值引用->右值引用 55 | */ 56 | 57 | } 58 | -------------------------------------------------------------------------------- /11RTTI&typeid&dynamic_cast/11RTTI typeid dynamic_cast/11RTTI typeid dynamic_cast.cpp: -------------------------------------------------------------------------------- 1 | // 11RTTI typeid dynamic_cast.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。 2 | // 3 | 4 | #include 5 | #include 6 | 7 | using namespace std; 8 | 9 | class Base1 { 10 | public: 11 | int i1_; 12 | virtual void func1() {} 13 | }; 14 | 15 | class Base2 { 16 | public: 17 | int i2_; 18 | virtual void func2() = 0; 19 | }; 20 | 21 | class Derived : public Base2, public Base1 { 22 | public: 23 | int d_; 24 | 25 | virtual void func2() override {} 26 | 27 | }; 28 | 29 | int main() 30 | { 31 | { 32 | int a; 33 | assert(typeid(a).name() == typeid(int).name()); // typeid 运行时求值 34 | // static_assert(typeid(a).name() == typeid(int).name(), ""); // 编译不过 35 | } 36 | // dynamic_cast 作用于多态类型 37 | { 38 | Base1* pb1 = new Base1{}; 39 | Derived* pd = static_cast(pb1); // 编译期决议,不会报错 40 | 41 | cout << pb1 << endl; 42 | cout << pd << endl; 43 | 44 | pd = dynamic_cast(pb1); // 没有继承关系,返回0 45 | 46 | cout << pd << endl; 47 | 48 | Base2* pb2 = nullptr; 49 | 50 | pb2 = dynamic_cast(pb1); // 实际没有继承关系,返回0 51 | 52 | { 53 | // pb2 = static_cast(pb1); // 编译报错 54 | } 55 | 56 | cout << pb2 << endl; 57 | 58 | cout << endl; 59 | 60 | 61 | } 62 | 63 | { 64 | Derived* pd = new Derived(); 65 | Base1* pb1 = pd; 66 | Base2 * pb2 = pd; 67 | 68 | cout << pd << " " << pb1 << " " << pb2 << endl; 69 | 70 | { 71 | pb2 = dynamic_cast(pb1); 72 | 73 | { 74 | // pb2 = static_cast(pb1); // 编译报错 75 | } 76 | 77 | cout << pb2 << endl; 78 | } 79 | 80 | { 81 | pb1 = dynamic_cast(pb2); 82 | cout << pb1 << endl; 83 | } 84 | 85 | } 86 | 87 | 88 | } 89 | -------------------------------------------------------------------------------- /综合实践c++11实现chrome的线程模型/base/message_pump_default.cpp: -------------------------------------------------------------------------------- 1 | #include "./message_pump_default.h" 2 | 3 | namespace base { 4 | 5 | MessagePumpDefault::MessagePumpDefault() : keep_running_(true), event_(false, false) {} 6 | 7 | MessagePumpDefault::~MessagePumpDefault() {} 8 | 9 | void MessagePumpDefault::Run(Delegate* delegate) { 10 | for (;;) { 11 | bool did_work = delegate->DoWork(); 12 | if (false == keep_running_) 13 | break; 14 | 15 | did_work |= delegate->DoDelayedWork(delayed_work_time_); 16 | if (false == keep_running_) 17 | break; 18 | 19 | if (did_work) 20 | continue; 21 | 22 | did_work = delegate->DoIdleWork(); 23 | if (false == keep_running_) 24 | break; 25 | 26 | if (did_work) 27 | continue; 28 | 29 | if (delayed_work_time_.is_null()) { 30 | event_.Wait(); 31 | } 32 | else { 33 | std::chrono::milliseconds delay = (delayed_work_time_ - TimeTicks::Now()); 34 | if (delay.count() > 0) { 35 | event_.TimedWait(delay); 36 | } 37 | else { 38 | // It looks like delayed_work_time_ indicates a time in the past, so we 39 | // need to call DoDelayedWork now. 40 | delayed_work_time_ = TimeTicks(); 41 | } 42 | } 43 | } 44 | keep_running_ = true; 45 | } 46 | 47 | void MessagePumpDefault::Quit() { 48 | keep_running_ = false; 49 | } 50 | 51 | void MessagePumpDefault::ScheduleWork() { 52 | event_.Signal(); 53 | } 54 | 55 | void MessagePumpDefault::ScheduleDelayedWork(const TimeTicks& delayed_work_time) { 56 | // We know that we can't be blocked on Wait right now since this method can 57 | // only be called on the same thread as Run, so we only need to update our 58 | // record of how long to sleep when we do sleep. 59 | delayed_work_time_ = delayed_work_time; 60 | } 61 | 62 | 63 | } // end base 64 | -------------------------------------------------------------------------------- /综合实践c++11实现chrome的线程模型/base/thread.h: -------------------------------------------------------------------------------- 1 | _Pragma("once") 2 | 3 | #include 4 | #include 5 | #include "./message_loop.h" 6 | #include "./event.h" 7 | 8 | namespace base { 9 | 10 | class Thread { 11 | public: 12 | 13 | struct Options { 14 | Options(); 15 | Options(MessageLoop::Type type, unsigned int size); 16 | 17 | unsigned int stack_size_; 18 | MessageLoop::Type message_loop_type_; 19 | }; 20 | 21 | struct StartupData { 22 | const Options& options_; 23 | WaitableEvent event_; 24 | 25 | explicit StartupData(const Options& options) : 26 | options_(options), event_(false, false) {} 27 | }; 28 | 29 | class ScopedCOMInitializer { 30 | public: 31 | ScopedCOMInitializer(); 32 | ~ScopedCOMInitializer(); 33 | }; 34 | 35 | explicit Thread(); 36 | virtual ~Thread(); 37 | 38 | void Init(); 39 | bool StartWithOptions(const Options& options); 40 | void Stop(); 41 | 42 | MessageLoop* message_loop() const { return message_loop_.get(); } 43 | std::thread::id thread_id() const { return thread_.get_id(); } 44 | bool IsRunning() const { return running_; } 45 | 46 | virtual void ThreadMain(); 47 | //static 48 | static bool CreateThreadInternal(Thread * ptr); 49 | 50 | Thread(const Thread&) = delete; 51 | Thread(Thread&&) = delete; 52 | void operator=(const Thread&) = delete; 53 | void operator=(Thread&&) = delete; 54 | 55 | protected: 56 | virtual void CleanUp(); 57 | 58 | private: 59 | void Run(MessageLoop* message_loop); 60 | 61 | std::unique_ptr message_loop_; 62 | 63 | StartupData* startup_data_; 64 | 65 | // Whether we successfully started the thread. 66 | bool started_; 67 | 68 | // If true, we're in the middle of stopping, and shouldn't access 69 | // |message_loop_|. It may non-NULL and invalid. 70 | bool stopping_; 71 | 72 | // True while inside of Run(). 73 | bool running_; 74 | 75 | std::thread thread_; 76 | 77 | }; 78 | 79 | 80 | } // end base 81 | -------------------------------------------------------------------------------- /综合实践c++11实现chrome的线程模型/base/base.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 头文件 20 | 21 | 22 | 头文件 23 | 24 | 25 | 头文件 26 | 27 | 28 | 头文件 29 | 30 | 31 | 头文件 32 | 33 | 34 | 头文件 35 | 36 | 37 | 头文件 38 | 39 | 40 | 41 | 42 | 源文件 43 | 44 | 45 | 源文件 46 | 47 | 48 | 源文件 49 | 50 | 51 | 源文件 52 | 53 | 54 | 源文件 55 | 56 | 57 | 源文件 58 | 59 | 60 | 61 | 62 | 63 | -------------------------------------------------------------------------------- /综合实践c++11实现chrome的线程模型/base/message_loop.h: -------------------------------------------------------------------------------- 1 | _Pragma("once") 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include "./message_pump_default.h" 8 | #include "./pending_task.h" 9 | 10 | namespace base { 11 | 12 | class MessageLoop : public MessagePump::Delegate { 13 | public: 14 | enum Type { 15 | TYPE_DEFAULT = 0, 16 | TYPE_UI, 17 | TYPE_IO, 18 | }; 19 | 20 | explicit MessageLoop(Type type = TYPE_DEFAULT); 21 | virtual ~MessageLoop(); 22 | 23 | //static 24 | static MessageLoop* current(); 25 | 26 | void PostTask(const PendingTask::closure& task); 27 | void PostDelayedTask(const PendingTask::closure& task, const std::chrono::milliseconds& delay); 28 | 29 | void Run(); 30 | void Quit(); 31 | Type type() const; 32 | 33 | bool is_running() const; 34 | //static 35 | static MessagePump* CreateMessagePumpForType(Type type); 36 | 37 | MessageLoop(const MessageLoop&) = delete; 38 | MessageLoop(MessageLoop&&) = delete; 39 | void operator=(const MessageLoop&) = delete; 40 | void operator=(MessageLoop&&) = delete; 41 | 42 | private: 43 | using DelayedTaskQueue = std::priority_queue; 44 | 45 | void Init(); 46 | void AddToDelayedWorkQueue(const PendingTask& pending_task); 47 | TimeTicks CalculateDelayedRuntime(const std::chrono::milliseconds& delay); 48 | void QuitInternal(); 49 | void AppendTask(const PendingTask& task); 50 | bool RunPendingTask(PendingTask& pending_task); 51 | void ReloadWorkQueue(); 52 | 53 | // MessagePump::Delegate methods: 54 | virtual bool DoWork() override; 55 | virtual bool DoDelayedWork(TimeTicks& next_delayed_work_time) override; 56 | virtual bool DoIdleWork() override; 57 | 58 | Type type_; 59 | bool running_; 60 | std::unique_ptr pump_; 61 | TaskQueue incoming_queue_; 62 | TaskQueue working_queue_; 63 | DelayedTaskQueue delayed_work_queue_; 64 | std::mutex mutex_; 65 | TimeTicks recent_time_; 66 | thread_local static MessageLoop* thisptr_; 67 | 68 | }; 69 | 70 | } // end base 71 | -------------------------------------------------------------------------------- /chrome的多线程模型_vs2022.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.1.32228.430 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "base", "综合实践c++11实现chrome的线程模型\base\base.vcxproj", "{45393762-59DC-44A6-9C0B-788C07E6EEBC}" 7 | EndProject 8 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "综合实践c++11实现chrome的线程模型", "综合实践c++11实现chrome的线程模型\sample\sample.vcxproj", "{E0342AFB-8784-4B87-BFA2-E54D4FDE1764}" 9 | EndProject 10 | Global 11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 12 | Debug|x64 = Debug|x64 13 | Debug|x86 = Debug|x86 14 | Release|x64 = Release|x64 15 | Release|x86 = Release|x86 16 | EndGlobalSection 17 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 18 | {45393762-59DC-44A6-9C0B-788C07E6EEBC}.Debug|x64.ActiveCfg = Debug|x64 19 | {45393762-59DC-44A6-9C0B-788C07E6EEBC}.Debug|x64.Build.0 = Debug|x64 20 | {45393762-59DC-44A6-9C0B-788C07E6EEBC}.Debug|x86.ActiveCfg = Debug|Win32 21 | {45393762-59DC-44A6-9C0B-788C07E6EEBC}.Debug|x86.Build.0 = Debug|Win32 22 | {45393762-59DC-44A6-9C0B-788C07E6EEBC}.Release|x64.ActiveCfg = Release|x64 23 | {45393762-59DC-44A6-9C0B-788C07E6EEBC}.Release|x64.Build.0 = Release|x64 24 | {45393762-59DC-44A6-9C0B-788C07E6EEBC}.Release|x86.ActiveCfg = Release|Win32 25 | {45393762-59DC-44A6-9C0B-788C07E6EEBC}.Release|x86.Build.0 = Release|Win32 26 | {E0342AFB-8784-4B87-BFA2-E54D4FDE1764}.Debug|x64.ActiveCfg = Debug|x64 27 | {E0342AFB-8784-4B87-BFA2-E54D4FDE1764}.Debug|x64.Build.0 = Debug|x64 28 | {E0342AFB-8784-4B87-BFA2-E54D4FDE1764}.Debug|x86.ActiveCfg = Debug|Win32 29 | {E0342AFB-8784-4B87-BFA2-E54D4FDE1764}.Debug|x86.Build.0 = Debug|Win32 30 | {E0342AFB-8784-4B87-BFA2-E54D4FDE1764}.Release|x64.ActiveCfg = Release|x64 31 | {E0342AFB-8784-4B87-BFA2-E54D4FDE1764}.Release|x64.Build.0 = Release|x64 32 | {E0342AFB-8784-4B87-BFA2-E54D4FDE1764}.Release|x86.ActiveCfg = Release|Win32 33 | {E0342AFB-8784-4B87-BFA2-E54D4FDE1764}.Release|x86.Build.0 = Release|Win32 34 | EndGlobalSection 35 | GlobalSection(SolutionProperties) = preSolution 36 | HideSolutionNode = FALSE 37 | EndGlobalSection 38 | GlobalSection(ExtensibilityGlobals) = postSolution 39 | SolutionGuid = {96B37A8B-704B-4843-B523-8FD845ABC012} 40 | EndGlobalSection 41 | EndGlobal 42 | -------------------------------------------------------------------------------- /26多线程&同步/26多线程 同步/26多线程 同步.cpp: -------------------------------------------------------------------------------- 1 | // 26多线程 同步.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。 2 | // 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | using namespace std; 13 | 14 | int a_ = 0; 15 | std::mutex mutex_; // lock,unlock,try_lock 16 | /* 17 | std::time_mutex 18 | + try_lock_for() // 阻塞直到超过指定的 timeout_duration 或得到锁,取决于何者先到来。成功获得锁时返回 true,否则返回false 19 | + try_lock_until() // 阻塞直至到指定的timeout_time或得到锁,取决于何者先到来。成功获得锁时返回 true,否则返回false 20 | */ 21 | std::mutex mutex2_; 22 | std::condition_variable producer, consumer; // 条件变量 23 | std::list data_; 24 | 25 | void func(string id) { 26 | std::unique_lock lk(mutex_, std::defer_lock); 27 | cout << "threadId = " << id; 28 | this_thread::sleep_for(100ms); 29 | lk.lock(); 30 | cout << " " << ++a_ << endl; 31 | } 32 | 33 | class A { 34 | public: 35 | A() = default; 36 | void func(int i) { 37 | this_thread::sleep_for(1000ms); 38 | cout << "A::func(" << i << ")" << endl; 39 | } 40 | }; 41 | 42 | void produce() { 43 | while (true) { 44 | this_thread::sleep_for(200ms); 45 | std::unique_lock lk(mutex2_); 46 | while (data_.size() > 0) { 47 | producer.wait(lk); 48 | } 49 | 50 | srand(time(0)); 51 | data_.push_back(rand()); 52 | lk.unlock(); 53 | consumer.notify_one(); 54 | } 55 | } 56 | 57 | void consume() { 58 | while (true) { 59 | this_thread::sleep_for(190ms); 60 | std::unique_lock lk(mutex2_); 61 | while (data_.size() == 0) { 62 | consumer.wait(lk); 63 | } 64 | std::cout << data_.front() << std::endl; 65 | data_.pop_back(); 66 | lk.unlock(); 67 | producer.notify_one(); 68 | } 69 | } 70 | 71 | int main() { 72 | { 73 | std::thread t1{func, "1"}; 74 | this_thread::yield(); 75 | std::thread t2{func, "2"}; 76 | 77 | t1.join(); 78 | t2.join(); 79 | } 80 | 81 | { 82 | std::shared_ptr ptr = std::make_shared(); 83 | auto funcobj = std::bind(&A::func, ptr, std::placeholders::_1); 84 | std::thread t{funcobj, 101}; 85 | t.join(); 86 | } 87 | 88 | std::thread consumers[10], producers[10]; 89 | for (int i = 0; i < 10; ++i) { 90 | consumers[i] = std::thread(consume); 91 | producers[i] = std::thread(produce); 92 | 93 | consumers[i].join(); 94 | producers[i].join(); 95 | } 96 | 97 | return 0; 98 | } 99 | -------------------------------------------------------------------------------- /综合实践c++11实现chrome的线程模型/base/message_pump.h: -------------------------------------------------------------------------------- 1 | _Pragma("once") 2 | 3 | #include "./time.h" 4 | 5 | #ifdef _WIN32 6 | #define NOVTABLE __declspec(novtable) 7 | #endif 8 | 9 | namespace base { 10 | class NOVTABLE MessagePump { 11 | public: 12 | class NOVTABLE Delegate { 13 | 14 | public: 15 | // Called from within Run in response to ScheduleWork or when the message 16 | // pump would otherwise call DoDelayedWork. Returns true to indicate that 17 | // work was done. DoDelayedWork will still be called if DoWork returns 18 | // true, but DoIdleWork will not. 19 | virtual bool DoWork() = 0; 20 | 21 | // Called from within Run in response to ScheduleDelayedWork or when the 22 | // message pump would otherwise sleep waiting for more work. Returns true 23 | // to indicate that delayed work was done. DoIdleWork will not be called 24 | // if DoDelayedWork returns true. Upon return |next_delayed_work_time| 25 | // indicates the time when DoDelayedWork should be called again. If 26 | // |next_delayed_work_time| is null (per Time::is_null), then the queue of 27 | // future delayed work (timer events) is currently empty, and no additional 28 | // calls to this function need to be scheduled. 29 | virtual bool DoDelayedWork(TimeTicks& next_delayed_work_time) = 0; 30 | 31 | // Called from within Run just before the message pump goes to sleep. 32 | // Returns true to indicate that idle work was done. Returning false means 33 | // the pump will now wait. 34 | virtual bool DoIdleWork() = 0; 35 | }; 36 | 37 | virtual void Run(Delegate* delegate) = 0; 38 | 39 | // Quit immediately from the most recently entered run loop. This method may 40 | // only be used on the thread that called Run. 41 | virtual void Quit() = 0; 42 | 43 | // Schedule a DoWork callback to happen reasonably soon. Does nothing if a 44 | // DoWork callback is already scheduled. This method may be called from any 45 | // thread. Once this call is made, DoWork should not be "starved" at least 46 | // until it returns a value of false. 47 | virtual void ScheduleWork() = 0; 48 | 49 | // Schedule a DoDelayedWork callback to happen at the specified time, 50 | // cancelling any pending DoDelayedWork callback. This method may only be 51 | // used on the thread that called Run. 52 | virtual void ScheduleDelayedWork(const TimeTicks& delayed_work_time) = 0; 53 | }; 54 | } 55 | -------------------------------------------------------------------------------- /综合实践c++11实现chrome的线程模型/base/pending_task.cpp: -------------------------------------------------------------------------------- 1 | #include "./pending_task.h" 2 | 3 | namespace base { 4 | 5 | PendingTask::PendingTask() : sequence_num_(0) {} 6 | 7 | PendingTask::PendingTask(const PendingTask& other) { 8 | task_ = other.task_; 9 | sequence_num_ = other.sequence_num_; 10 | delayed_run_time_ = other.delayed_run_time_; 11 | } 12 | 13 | PendingTask::PendingTask(PendingTask&& other) noexcept { 14 | sequence_num_ = other.sequence_num_; 15 | delayed_run_time_ = other.delayed_run_time_; 16 | task_ = std::move(other.task_); 17 | } 18 | 19 | PendingTask::PendingTask(const closure& task) : sequence_num_(0) { 20 | task_ = task; 21 | } 22 | 23 | PendingTask::PendingTask(closure&& task) noexcept : sequence_num_(0) { 24 | task_ = std::move(task); 25 | } 26 | 27 | PendingTask::PendingTask(const closure& task, const TimeTicks& delayed_run_time) : sequence_num_(0) { 28 | task_ = task; 29 | delayed_run_time_ = delayed_run_time; 30 | } 31 | 32 | PendingTask::PendingTask(closure&& task, const TimeTicks& delayed_run_time) noexcept { 33 | task_ = std::move(task); 34 | delayed_run_time_ = delayed_run_time; 35 | } 36 | 37 | PendingTask& PendingTask::operator=(const PendingTask& other) { 38 | task_ = other.task_; 39 | sequence_num_ = other.sequence_num_; 40 | delayed_run_time_ = other.delayed_run_time_; 41 | return *this; 42 | } 43 | 44 | PendingTask& PendingTask::operator=(PendingTask&& other) noexcept { 45 | sequence_num_ = other.sequence_num_; 46 | delayed_run_time_ = other.delayed_run_time_; 47 | task_ = std::move(other.task_); 48 | return *this; 49 | } 50 | 51 | bool PendingTask::Equals(const PendingTask& other) const { 52 | return (this->sequence_num_ == other.sequence_num_); 53 | } 54 | 55 | bool PendingTask::callable() { 56 | return static_cast(task_); 57 | } 58 | 59 | void PendingTask::Run() { 60 | if (callable()) { 61 | task_(); 62 | } 63 | } 64 | 65 | bool PendingTask::operator<(const PendingTask& other) const { 66 | // Since the top of a priority queue is defined as the "greatest" element, we 67 | // need to invert the comparison here. We want the smaller time to be at the 68 | // top of the heap. 69 | 70 | if (delayed_run_time_ < other.delayed_run_time_) 71 | return false; 72 | 73 | if (delayed_run_time_ > other.delayed_run_time_) 74 | return true; 75 | 76 | // If the times happen to match, then we use the sequence number to decide. 77 | // Compare the difference to support integer roll-over. 78 | return (sequence_num_ > other.sequence_num_); 79 | } 80 | 81 | // TaskQueue 82 | bool TaskQueue::empty() { 83 | return _val.empty(); 84 | } 85 | 86 | void TaskQueue::emplace_back(const PendingTask& task) { 87 | task.sequence_num_ = ++(this->sequence_num_); 88 | _val.emplace_back(task); 89 | } 90 | 91 | PendingTask TaskQueue::pick_front() noexcept { 92 | PendingTask o((_val.front())); 93 | _val.pop_front(); 94 | return (o); 95 | } 96 | 97 | const PendingTask& TaskQueue::front() { 98 | return _val.front(); 99 | } 100 | 101 | void TaskQueue::swap(TaskQueue& val) { 102 | _val.swap(val._val); 103 | } 104 | 105 | } // end base 106 | -------------------------------------------------------------------------------- /综合实践c++11实现chrome的线程模型/base/time.h: -------------------------------------------------------------------------------- 1 | _Pragma("once") 2 | 3 | #include 4 | 5 | namespace base { 6 | 7 | class TimeTicks { 8 | public: 9 | using time_point = std::chrono::time_point; 10 | 11 | explicit TimeTicks() = default; 12 | 13 | explicit TimeTicks(const std::chrono::milliseconds& ticks) : ticks_(ticks) {} 14 | 15 | explicit TimeTicks(const time_point& point) : ticks_(point) {} 16 | 17 | bool is_null() const; 18 | 19 | // Returns the internal numeric value of the TimeTicks object (milliseconds) 20 | long long ToInternalValue() const { 21 | return ticks_.time_since_epoch().count(); 22 | } 23 | 24 | // Now 25 | static TimeTicks Now(); 26 | 27 | TimeTicks& operator=(const TimeTicks& other) { 28 | ticks_ = other.ticks_; 29 | return *this; 30 | } 31 | 32 | // Compute the difference between two times. 33 | std::chrono::milliseconds operator-(const TimeTicks& other) const { 34 | return (ticks_ - other.ticks_); 35 | } 36 | 37 | // Modify by some time delta. 38 | TimeTicks& operator+=(const std::chrono::milliseconds& delta) { 39 | ticks_ += delta; 40 | return *this; 41 | } 42 | 43 | TimeTicks& operator-=(const std::chrono::milliseconds& delta) { 44 | ticks_ -= delta; 45 | return *this; 46 | } 47 | 48 | // Return a new TimeTicks modified by some delta. 49 | TimeTicks operator+(const std::chrono::milliseconds& delta) const { 50 | return TimeTicks(ticks_ + delta); 51 | } 52 | 53 | TimeTicks operator-(const std::chrono::milliseconds& delta) const { 54 | return TimeTicks(ticks_ - delta); 55 | } 56 | 57 | // Return a new TimeTicks modified by some delta. 58 | TimeTicks operator+(long long delta) const { 59 | return TimeTicks(ticks_ + std::chrono::milliseconds(delta)); 60 | } 61 | 62 | TimeTicks operator-(long long delta) const { 63 | return TimeTicks(ticks_ - std::chrono::milliseconds(delta) ); 64 | } 65 | 66 | // Comparison operators 67 | bool operator==(const TimeTicks& other) const { 68 | return ticks_ == other.ticks_; 69 | } 70 | 71 | bool operator!=(const TimeTicks& other) const { 72 | return ticks_ != other.ticks_; 73 | } 74 | 75 | bool operator<(const TimeTicks& other) const { 76 | return ticks_ < other.ticks_; 77 | } 78 | 79 | bool operator<=(const TimeTicks& other) const { 80 | return ticks_ <= other.ticks_; 81 | } 82 | 83 | bool operator>(const TimeTicks& other) const { 84 | return ticks_ > other.ticks_; 85 | } 86 | 87 | bool operator>=(const TimeTicks& other) const { 88 | return ticks_ >= other.ticks_; 89 | } 90 | 91 | static std::chrono::milliseconds FromDays(int days); 92 | static std::chrono::milliseconds FromHours(int hours); 93 | static std::chrono::milliseconds FromMinutes(int minutes); 94 | static std::chrono::milliseconds FromSeconds(long long secs); 95 | static std::chrono::milliseconds FromMilliseconds(long long ms); 96 | static std::chrono::milliseconds FromMicroseconds(long long us); 97 | 98 | private: 99 | time_point ticks_; 100 | }; 101 | 102 | } // end base 103 | -------------------------------------------------------------------------------- /综合实践c++11实现chrome的线程模型/base/message_loop.cpp: -------------------------------------------------------------------------------- 1 | #include "./message_loop.h" 2 | 3 | namespace base { 4 | 5 | thread_local MessageLoop* MessageLoop::thisptr_ = nullptr; 6 | 7 | MessageLoop::MessageLoop(Type type) : type_(type), running_(false) { 8 | Init(); 9 | pump_.reset(CreateMessagePumpForType(type)); 10 | } 11 | 12 | MessageLoop::~MessageLoop() { 13 | thisptr_ = nullptr; 14 | } 15 | 16 | MessageLoop* MessageLoop::current() { 17 | return thisptr_; 18 | } 19 | 20 | void MessageLoop::PostTask(const PendingTask::closure& task) { 21 | PostDelayedTask(task, std::chrono::milliseconds::zero()); 22 | } 23 | 24 | void MessageLoop::PostDelayedTask(const PendingTask::closure& task, const std::chrono::milliseconds& delay) { 25 | if (0 == delay.count()) { 26 | PendingTask t(task); 27 | AppendTask(t); 28 | } 29 | else { 30 | PendingTask t(task, CalculateDelayedRuntime(delay)); 31 | AppendTask(t); 32 | } 33 | 34 | pump_->ScheduleWork(); 35 | } 36 | 37 | void MessageLoop::Run() { 38 | running_ = true; 39 | pump_->Run(this); 40 | running_ = false; 41 | } 42 | 43 | void MessageLoop::Quit() { 44 | auto task = std::bind(&MessageLoop::QuitInternal, this); 45 | PostTask(task); 46 | } 47 | 48 | MessageLoop::Type MessageLoop::type() const { return type_; } 49 | 50 | bool MessageLoop::is_running() const { 51 | return running_; 52 | } 53 | 54 | //static 55 | MessagePump* MessageLoop::CreateMessagePumpForType(Type type) { 56 | if (MessageLoop::TYPE_DEFAULT == type) { 57 | return new MessagePumpDefault(); 58 | } 59 | // todo 60 | return nullptr; 61 | } 62 | 63 | void MessageLoop::Init() { 64 | thisptr_ = this; 65 | } 66 | 67 | void MessageLoop::AddToDelayedWorkQueue(const PendingTask& pending_task) { 68 | delayed_work_queue_.emplace(pending_task); 69 | } 70 | 71 | TimeTicks MessageLoop::CalculateDelayedRuntime(const std::chrono::milliseconds& delay) { 72 | TimeTicks delayed_run_time = TimeTicks::Now() + delay; 73 | return delayed_run_time; 74 | } 75 | 76 | void MessageLoop::QuitInternal() { 77 | pump_->Quit(); 78 | } 79 | 80 | void MessageLoop::AppendTask(const PendingTask& task) { 81 | std::lock_guard guard(mutex_); 82 | incoming_queue_.emplace_back(task); 83 | } 84 | 85 | bool MessageLoop::RunPendingTask(PendingTask& pending_task) { 86 | pending_task.Run(); 87 | return true; 88 | } 89 | 90 | void MessageLoop::ReloadWorkQueue() { 91 | if (!working_queue_.empty()) 92 | return; 93 | 94 | std::lock_guard guard(mutex_); 95 | if (!incoming_queue_.empty()) { 96 | incoming_queue_.swap(working_queue_); 97 | } 98 | } 99 | 100 | bool MessageLoop::DoWork() { 101 | for (;;) { 102 | ReloadWorkQueue(); 103 | if (working_queue_.empty()) 104 | break; 105 | 106 | //Execute oldest task. 107 | do { 108 | PendingTask pending_task = working_queue_.pick_front(); 109 | if (!pending_task.delayed_run_time_.is_null()) { 110 | AddToDelayedWorkQueue(pending_task); 111 | // If we changed the topmost task, then it is time to reschedule. 112 | if (delayed_work_queue_.top().Equals(pending_task)) 113 | pump_->ScheduleDelayedWork(pending_task.delayed_run_time_); 114 | } 115 | else { 116 | if (RunPendingTask(pending_task)) 117 | return true; 118 | } 119 | } while (!working_queue_.empty()); 120 | } 121 | //Nothing runned. 122 | return false; 123 | } 124 | 125 | bool MessageLoop::DoDelayedWork(TimeTicks& next_delayed_work_time) { 126 | if (delayed_work_queue_.empty()) { 127 | recent_time_ = next_delayed_work_time = TimeTicks(); 128 | return false; 129 | } 130 | 131 | TimeTicks next_run_time = delayed_work_queue_.top().delayed_run_time_; 132 | if (next_run_time > recent_time_) { 133 | recent_time_ = TimeTicks::Now(); 134 | if (next_run_time > recent_time_) { 135 | next_delayed_work_time = next_run_time; 136 | return false; 137 | } 138 | } 139 | 140 | PendingTask pending_task = delayed_work_queue_.top(); 141 | delayed_work_queue_.pop(); 142 | 143 | if (!delayed_work_queue_.empty()) { 144 | next_delayed_work_time = delayed_work_queue_.top().delayed_run_time_; 145 | } 146 | 147 | RunPendingTask(pending_task); 148 | return true; 149 | } 150 | 151 | bool MessageLoop::DoIdleWork() { 152 | return false; 153 | } 154 | 155 | 156 | } // end base 157 | -------------------------------------------------------------------------------- /07右尖括号/07右尖括号/07右尖括号.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | Debug 14 | x64 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | 16.0 23 | Win32Proj 24 | {d86b3523-a02e-430f-bb0b-68cfc51a76af} 25 | My07右尖括号 26 | 10.0 27 | 28 | 29 | 30 | Application 31 | true 32 | v143 33 | Unicode 34 | 35 | 36 | Application 37 | false 38 | v143 39 | true 40 | Unicode 41 | 42 | 43 | Application 44 | true 45 | v143 46 | Unicode 47 | 48 | 49 | Application 50 | false 51 | v143 52 | true 53 | Unicode 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | true 75 | 76 | 77 | false 78 | 79 | 80 | true 81 | 82 | 83 | false 84 | 85 | 86 | 87 | Level3 88 | true 89 | WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) 90 | true 91 | 92 | 93 | Console 94 | true 95 | 96 | 97 | 98 | 99 | Level3 100 | true 101 | true 102 | true 103 | WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 104 | true 105 | 106 | 107 | Console 108 | true 109 | true 110 | true 111 | 112 | 113 | 114 | 115 | Level3 116 | true 117 | _DEBUG;_CONSOLE;%(PreprocessorDefinitions) 118 | true 119 | 120 | 121 | Console 122 | true 123 | 124 | 125 | 126 | 127 | Level3 128 | true 129 | true 130 | true 131 | NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 132 | true 133 | 134 | 135 | Console 136 | true 137 | true 138 | true 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | -------------------------------------------------------------------------------- /27智能指针/27智能指针/27智能指针.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | Debug 14 | x64 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | 16.0 23 | Win32Proj 24 | {a3d0a3da-7ed0-4fa4-bf41-2249a88cfd73} 25 | My27智能指针 26 | 10.0 27 | 28 | 29 | 30 | Application 31 | true 32 | v143 33 | Unicode 34 | 35 | 36 | Application 37 | false 38 | v143 39 | true 40 | Unicode 41 | 42 | 43 | Application 44 | true 45 | v143 46 | Unicode 47 | 48 | 49 | Application 50 | false 51 | v143 52 | true 53 | Unicode 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | true 75 | 76 | 77 | false 78 | 79 | 80 | true 81 | 82 | 83 | false 84 | 85 | 86 | 87 | Level3 88 | true 89 | WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) 90 | true 91 | 92 | 93 | Console 94 | true 95 | 96 | 97 | 98 | 99 | Level3 100 | true 101 | true 102 | true 103 | WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 104 | true 105 | 106 | 107 | Console 108 | true 109 | true 110 | true 111 | 112 | 113 | 114 | 115 | Level3 116 | true 117 | _DEBUG;_CONSOLE;%(PreprocessorDefinitions) 118 | true 119 | 120 | 121 | Console 122 | true 123 | 124 | 125 | 126 | 127 | Level3 128 | true 129 | true 130 | true 131 | NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 132 | true 133 | 134 | 135 | Console 136 | true 137 | true 138 | true 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | -------------------------------------------------------------------------------- /37通用属性/37通用属性/37通用属性.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | Debug 14 | x64 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | 16.0 23 | Win32Proj 24 | {4bf291c8-fb5e-4240-aca0-27a45a5d7009} 25 | My37通用属性 26 | 10.0 27 | 28 | 29 | 30 | Application 31 | true 32 | v143 33 | Unicode 34 | 35 | 36 | Application 37 | false 38 | v143 39 | true 40 | Unicode 41 | 42 | 43 | Application 44 | true 45 | v143 46 | Unicode 47 | 48 | 49 | Application 50 | false 51 | v143 52 | true 53 | Unicode 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | true 75 | 76 | 77 | false 78 | 79 | 80 | true 81 | 82 | 83 | false 84 | 85 | 86 | 87 | Level3 88 | true 89 | WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) 90 | true 91 | 92 | 93 | Console 94 | true 95 | 96 | 97 | 98 | 99 | Level3 100 | true 101 | true 102 | true 103 | WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 104 | true 105 | 106 | 107 | Console 108 | true 109 | true 110 | true 111 | 112 | 113 | 114 | 115 | Level3 116 | true 117 | _DEBUG;_CONSOLE;%(PreprocessorDefinitions) 118 | true 119 | 120 | 121 | Console 122 | true 123 | 124 | 125 | 126 | 127 | Level3 128 | true 129 | true 130 | true 131 | NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 132 | true 133 | 134 | 135 | Console 136 | true 137 | true 138 | true 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | -------------------------------------------------------------------------------- /12强枚举类型/12强枚举类型/12强枚举类型.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | Debug 14 | x64 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | 16.0 23 | Win32Proj 24 | {48072a60-4e03-4fa9-9fbb-92cd476edd03} 25 | My12强枚举类型 26 | 10.0 27 | 28 | 29 | 30 | Application 31 | true 32 | v143 33 | Unicode 34 | 35 | 36 | Application 37 | false 38 | v143 39 | true 40 | Unicode 41 | 42 | 43 | Application 44 | true 45 | v143 46 | Unicode 47 | 48 | 49 | Application 50 | false 51 | v143 52 | true 53 | Unicode 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | true 75 | 76 | 77 | false 78 | 79 | 80 | true 81 | 82 | 83 | false 84 | 85 | 86 | 87 | Level3 88 | true 89 | WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) 90 | true 91 | 92 | 93 | Console 94 | true 95 | 96 | 97 | 98 | 99 | Level3 100 | true 101 | true 102 | true 103 | WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 104 | true 105 | 106 | 107 | Console 108 | true 109 | true 110 | true 111 | 112 | 113 | 114 | 115 | Level3 116 | true 117 | _DEBUG;_CONSOLE;%(PreprocessorDefinitions) 118 | true 119 | 120 | 121 | Console 122 | true 123 | 124 | 125 | 126 | 127 | Level3 128 | true 129 | true 130 | true 131 | NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 132 | true 133 | 134 | 135 | Console 136 | true 137 | true 138 | true 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | -------------------------------------------------------------------------------- /30POD类型/30POD类型/30POD类型.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | Debug 14 | x64 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | 16.0 23 | Win32Proj 24 | {fc343815-d32c-4b3f-a8e2-0a868e9b1c21} 25 | My30POD类型 26 | 10.0 27 | 28 | 29 | 30 | Application 31 | true 32 | v143 33 | Unicode 34 | 35 | 36 | Application 37 | false 38 | v143 39 | true 40 | Unicode 41 | 42 | 43 | Application 44 | true 45 | v143 46 | Unicode 47 | 48 | 49 | Application 50 | false 51 | v143 52 | true 53 | Unicode 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | true 75 | 76 | 77 | false 78 | 79 | 80 | true 81 | 82 | 83 | false 84 | 85 | 86 | 87 | Level3 88 | true 89 | WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) 90 | true 91 | 92 | 93 | Console 94 | true 95 | 96 | 97 | 98 | 99 | Level3 100 | true 101 | true 102 | true 103 | WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 104 | true 105 | 106 | 107 | Console 108 | true 109 | true 110 | true 111 | 112 | 113 | 114 | 115 | Level3 116 | true 117 | _DEBUG;_CONSOLE;%(PreprocessorDefinitions) 118 | true 119 | 120 | 121 | Console 122 | true 123 | 124 | 125 | 126 | 127 | Level3 128 | true 129 | true 130 | true 131 | NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 132 | true 133 | 134 | 135 | Console 136 | true 137 | true 138 | true 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | -------------------------------------------------------------------------------- /05委托构造函数/05委托构造函数/05委托构造函数.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | Debug 14 | x64 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | 16.0 23 | Win32Proj 24 | {4616113a-0c0b-449d-87b8-de612d3c13a1} 25 | My05委托构造函数 26 | 10.0 27 | 28 | 29 | 30 | Application 31 | true 32 | v143 33 | Unicode 34 | 35 | 36 | Application 37 | false 38 | v143 39 | true 40 | Unicode 41 | 42 | 43 | Application 44 | true 45 | v143 46 | Unicode 47 | 48 | 49 | Application 50 | false 51 | v143 52 | true 53 | Unicode 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | true 75 | 76 | 77 | false 78 | 79 | 80 | true 81 | 82 | 83 | false 84 | 85 | 86 | 87 | Level3 88 | true 89 | WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) 90 | true 91 | 92 | 93 | Console 94 | true 95 | 96 | 97 | 98 | 99 | Level3 100 | true 101 | true 102 | true 103 | WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 104 | true 105 | 106 | 107 | Console 108 | true 109 | true 110 | true 111 | 112 | 113 | 114 | 115 | Level3 116 | true 117 | _DEBUG;_CONSOLE;%(PreprocessorDefinitions) 118 | true 119 | 120 | 121 | Console 122 | true 123 | 124 | 125 | 126 | 127 | Level3 128 | true 129 | true 130 | true 131 | NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 132 | true 133 | 134 | 135 | Console 136 | true 137 | true 138 | true 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | -------------------------------------------------------------------------------- /28nullptr/28nullptr/28nullptr.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | Debug 14 | x64 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | 16.0 23 | Win32Proj 24 | {934d5a35-139a-4d5d-9168-7eee513b1b5f} 25 | My28nullptr 26 | 10.0 27 | 28 | 29 | 30 | Application 31 | true 32 | v143 33 | Unicode 34 | 35 | 36 | Application 37 | false 38 | v143 39 | true 40 | Unicode 41 | 42 | 43 | Application 44 | true 45 | v143 46 | Unicode 47 | 48 | 49 | Application 50 | false 51 | v143 52 | true 53 | Unicode 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | true 75 | 76 | 77 | false 78 | 79 | 80 | true 81 | 82 | 83 | false 84 | 85 | 86 | 87 | Level3 88 | true 89 | WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) 90 | true 91 | 92 | 93 | Console 94 | true 95 | 96 | 97 | 98 | 99 | Level3 100 | true 101 | true 102 | true 103 | WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 104 | true 105 | 106 | 107 | Console 108 | true 109 | true 110 | true 111 | 112 | 113 | 114 | 115 | Level3 116 | true 117 | _DEBUG;_CONSOLE;%(PreprocessorDefinitions) 118 | true 119 | 120 | 121 | Console 122 | true 123 | 124 | 125 | 126 | 127 | Level3 128 | true 129 | true 130 | true 131 | NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 132 | true 133 | 134 | 135 | Console 136 | true 137 | true 138 | true 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | -------------------------------------------------------------------------------- /04函数默认模板参数/04函数默认模板参数/04函数默认模板参数.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | Debug 14 | x64 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | 16.0 23 | Win32Proj 24 | {264015c4-c526-4a6d-9174-328c4f2aa65d} 25 | My04函数默认模板参数 26 | 10.0 27 | 28 | 29 | 30 | Application 31 | true 32 | v143 33 | Unicode 34 | 35 | 36 | Application 37 | false 38 | v143 39 | true 40 | Unicode 41 | 42 | 43 | Application 44 | true 45 | v143 46 | Unicode 47 | 48 | 49 | Application 50 | false 51 | v143 52 | true 53 | Unicode 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | true 75 | 76 | 77 | false 78 | 79 | 80 | true 81 | 82 | 83 | false 84 | 85 | 86 | 87 | Level3 88 | true 89 | WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) 90 | true 91 | 92 | 93 | Console 94 | true 95 | 96 | 97 | 98 | 99 | Level3 100 | true 101 | true 102 | true 103 | WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 104 | true 105 | 106 | 107 | Console 108 | true 109 | true 110 | true 111 | 112 | 113 | 114 | 115 | Level3 116 | true 117 | _DEBUG;_CONSOLE;%(PreprocessorDefinitions) 118 | true 119 | 120 | 121 | Console 122 | true 123 | 124 | 125 | 126 | 127 | Level3 128 | true 129 | true 130 | true 131 | NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 132 | true 133 | 134 | 135 | Console 136 | true 137 | true 138 | true 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | -------------------------------------------------------------------------------- /15变长参数的宏定义/15变长参数的宏定义/15变长参数的宏定义.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | Debug 14 | x64 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | 16.0 23 | Win32Proj 24 | {f8f0904f-4533-4e43-952e-0f35aaf1cdd6} 25 | My15变长参数的宏定义 26 | 10.0 27 | 28 | 29 | 30 | Application 31 | true 32 | v143 33 | Unicode 34 | 35 | 36 | Application 37 | false 38 | v143 39 | true 40 | Unicode 41 | 42 | 43 | Application 44 | true 45 | v143 46 | Unicode 47 | 48 | 49 | Application 50 | false 51 | v143 52 | true 53 | Unicode 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | true 75 | 76 | 77 | false 78 | 79 | 80 | true 81 | 82 | 83 | false 84 | 85 | 86 | 87 | Level3 88 | true 89 | WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) 90 | true 91 | 92 | 93 | Console 94 | true 95 | 96 | 97 | 98 | 99 | Level3 100 | true 101 | true 102 | true 103 | WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 104 | true 105 | 106 | 107 | Console 108 | true 109 | true 110 | true 111 | 112 | 113 | 114 | 115 | Level3 116 | true 117 | _DEBUG;_CONSOLE;%(PreprocessorDefinitions) 118 | true 119 | 120 | 121 | Console 122 | true 123 | 124 | 125 | 126 | 127 | Level3 128 | true 129 | true 130 | true 131 | NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 132 | true 133 | 134 | 135 | Console 136 | true 137 | true 138 | true 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | -------------------------------------------------------------------------------- /23可执行对象封装器/23可执行对象封装器/23可执行对象封装器.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | Debug 14 | x64 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | 16.0 23 | Win32Proj 24 | {2d949375-7b9b-4a1f-8eba-1f8472e3fb83} 25 | My23可执行对象封装器 26 | 10.0 27 | 28 | 29 | 30 | Application 31 | true 32 | v143 33 | Unicode 34 | 35 | 36 | Application 37 | false 38 | v143 39 | true 40 | Unicode 41 | 42 | 43 | Application 44 | true 45 | v143 46 | Unicode 47 | 48 | 49 | Application 50 | false 51 | v143 52 | true 53 | Unicode 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | true 75 | 76 | 77 | false 78 | 79 | 80 | true 81 | 82 | 83 | false 84 | 85 | 86 | 87 | Level3 88 | true 89 | WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) 90 | true 91 | 92 | 93 | Console 94 | true 95 | 96 | 97 | 98 | 99 | Level3 100 | true 101 | true 102 | true 103 | WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 104 | true 105 | 106 | 107 | Console 108 | true 109 | true 110 | true 111 | 112 | 113 | 114 | 115 | Level3 116 | true 117 | _DEBUG;_CONSOLE;%(PreprocessorDefinitions) 118 | true 119 | 120 | 121 | Console 122 | true 123 | 124 | 125 | 126 | 127 | Level3 128 | true 129 | true 130 | true 131 | NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 132 | true 133 | 134 | 135 | Console 136 | true 137 | true 138 | true 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | -------------------------------------------------------------------------------- /35用户自定义字面量/35用户自定义字面量/35用户自定义字面量.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | Debug 14 | x64 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | 16.0 23 | Win32Proj 24 | {bcd1f3f6-a56c-443f-adba-732b41e71ba1} 25 | My35用户自定义字面量 26 | 10.0 27 | 28 | 29 | 30 | Application 31 | true 32 | v143 33 | Unicode 34 | 35 | 36 | Application 37 | false 38 | v143 39 | true 40 | Unicode 41 | 42 | 43 | Application 44 | true 45 | v143 46 | Unicode 47 | 48 | 49 | Application 50 | false 51 | v143 52 | true 53 | Unicode 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | true 75 | 76 | 77 | false 78 | 79 | 80 | true 81 | 82 | 83 | false 84 | 85 | 86 | 87 | Level3 88 | true 89 | WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) 90 | true 91 | 92 | 93 | Console 94 | true 95 | 96 | 97 | 98 | 99 | Level3 100 | true 101 | true 102 | true 103 | WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 104 | true 105 | 106 | 107 | Console 108 | true 109 | true 110 | true 111 | 112 | 113 | 114 | 115 | Level3 116 | true 117 | _DEBUG;_CONSOLE;%(PreprocessorDefinitions) 118 | true 119 | 120 | 121 | Console 122 | true 123 | 124 | 125 | 126 | 127 | Level3 128 | true 129 | true 130 | true 131 | NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 132 | true 133 | 134 | 135 | Console 136 | true 137 | true 138 | true 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | -------------------------------------------------------------------------------- /21右值引用&移动语义/21右值引用 移动语义/21右值引用 移动语义.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | Debug 14 | x64 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | 16.0 23 | Win32Proj 24 | {70822981-9f6b-4848-a552-967ba25a98b2} 25 | My21右值引用移动语义 26 | 10.0 27 | 28 | 29 | 30 | Application 31 | true 32 | v143 33 | Unicode 34 | 35 | 36 | Application 37 | false 38 | v143 39 | true 40 | Unicode 41 | 42 | 43 | Application 44 | true 45 | v143 46 | Unicode 47 | 48 | 49 | Application 50 | false 51 | v143 52 | true 53 | Unicode 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | true 75 | 76 | 77 | false 78 | 79 | 80 | true 81 | 82 | 83 | false 84 | 85 | 86 | 87 | Level3 88 | true 89 | WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) 90 | true 91 | 92 | 93 | Console 94 | true 95 | 96 | 97 | 98 | 99 | Level3 100 | true 101 | true 102 | true 103 | WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 104 | true 105 | 106 | 107 | Console 108 | true 109 | true 110 | true 111 | 112 | 113 | 114 | 115 | Level3 116 | true 117 | _DEBUG;_CONSOLE;%(PreprocessorDefinitions) 118 | true 119 | 120 | 121 | Console 122 | true 123 | 124 | 125 | 126 | 127 | Level3 128 | true 129 | true 130 | true 131 | NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 132 | true 133 | 134 | 135 | Console 136 | true 137 | true 138 | true 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | --------------------------------------------------------------------------------