📚 C++ Templates 2ed 笔记:C++11/14/17 模板技术

Overview
  • C++ 模板技术是泛型编程的核心,但囿于编译器技术限制,不得不带着缺陷诞生,语法晦涩,报错冗长,难以调试,开发应用较少使用,相关技术书籍匮乏,因此掌握难度较大。模板相关的经典技术书籍主要有三本,分别是 2001 年出版的 Modern C++ Design、2002 年出版的 C++ Templates、2004 年出版的 C++ Template Metaprogramming。三者基于的 C++ 标准都是 C++98,Modern C++ Design 涉及 Andrei Alexandrescu 写书时配套的 LokiC++ Template Metaprogramming 涉及 Boost,二者以介绍元编程(模板技术的一种应用)为主,只有 C++ Templates 主要介绍 C++98 标准的模板技术。时过境迁,C++ 标准的更新逐步修复了一些语法缺陷,减少了使用者的心智负担,并引入了语法糖和工具,让编写模板越来越简单。2017 年 9 月 25 日,基于 C++17 标准,C++ Templates 2ed 出版,填补了十多年间模板技术进化时相关书籍的空白,堪称最全面的模板教程,也是对 C++11/14/17 特性介绍最为全面的书籍之一。此为个人笔记,精简并覆盖了原书所有关键知识点(略过涉及代码较少的 ch 10 模板术语ch 17 未来的方向ch 18 模板的多态威力 三章),对书中示例代码使用 VS 2017 编译过并对错误代码全部进行了纠正(仅一处因语法复杂编译失败)。或是学习源码时遇到模板黑魔法不得其解,或是见他人轻松把玩模板心生羡慕,或是希望无限逼近精通 C++ 的状态,C++ 爱好者对模板求知若渴却又望而生畏,分享该笔记,希望帮助更多 C++ 爱好者掌握模板的使用。

part1:基础

  1. 函数模板(Function Template)
  2. 类模板(Class Template)
  3. 非类型模板参数(Nontype Template Parameter)
  4. 可变参数模板(Variadic Template)
  5. Tricky Basic
  6. 移动语义与 enable_if
  7. 按值传递与按引用传递(By Value or by Reference?)
  8. 编译期编程(Compile-Time Programming)
  9. 模板实战(Using Templates in Practice)
  10. 泛型库(Generic Library)

part2:深入模板

  1. 深入模板基础(Fundamentals in Depth)
  2. 模板中的名称(Names in Template)
  3. 实例化(Instantiation)
  4. 模板实参推断(Template Argument Deduction)
  5. 特化与重载(Specialization and Overloading)

part3:模板与设计

  1. Traits 的实现(Implementing Traits)
  2. 基于类型属性的重载(Overloading on Type Property)
  3. 模板与继承(Template and Inheritance)
  4. 桥接静态多态与动态多态(Bridging Static and Dynamic Polymorphism)
  5. 元编程(Metaprogramming)
  6. Typelist
  7. Tuple
  8. 标签联合(Discriminated Union)
  9. 表达式模板(Expression Template)
  10. 模板的调试(Debugging Template)
C++ intrusive container templates. Abstract node links, no use of new/delete.

C-plus-plus-intrusive-container-templates C++ intrusive container templates. Abstract node links, no use of new/delete (AVL tree, singly-linked list,

Walt Karas 11 Feb 10, 2022
Mustache text templates for modern C++

About Mustache implementation for modern C++ (requires C++11) Header only Zero dependencies Templated string type for compatibility with any STL-like

Kevin Wojniak 284 Jun 17, 2022
A modern compile-time reflection library for C++ with support for overloads, templates, attributes and proxies

refl-cpp v0.12.1 Documentation refl-cpp encodes type metadata in the type system to allow compile-time reflection via constexpr and template metaprogr

Veselin Karaganev 658 Jun 23, 2022
Templates, algorithms and data structures implemented and collected for programming contests.

Templates, algorithms and data structures implemented and collected for programming contests.

Shahjalal Shohag 1.8k Jun 27, 2022
Basic jam templates using Handmade libraries to get up and running quickly.

This is a selection of template projects to get up and running with for the Wheel Reinvention Jam. They are built on top of Handmade-inspired librarie

Handmade Network 13 Jun 19, 2022
URI Templates expansion and reverse-matching for C++

URI-template This library implements URI Template with full support up to Level 4 providing expansion and match capabilities. It requires c++17 compil

Tinkoff.ru 7 Jan 21, 2022
Variadic recursive expression templates which look like ordinary (possibly nested) containers.

Variadic resursive expressions with lazy evaluation which look like nested containers LazyExpression is a header-only library written in C++17. It imp

null 9 Jan 6, 2022
Blazing-fast Expression Templates Library (ETL) with GPU support, in C++

Expression Templates Library (ETL) 1.3.0 ETL is a header only library for C++ that provides vector and matrix classes with support for Expression Temp

Baptiste Wicht 201 Jun 4, 2022
C++ intrusive container templates. Abstract node links, no use of new/delete.

C-plus-plus-intrusive-container-templates C++ intrusive container templates. Abstract node links, no use of new/delete (AVL tree, singly-linked list,

Walt Karas 11 Feb 10, 2022
Concise CMake templates for creating C++ libraries or executables.

cmake_templates Concise cmake templates for creating C++ libraries and executables. Creating a normal cmake project Copy the chosen project template s

Ali Can Demiralp 109 Apr 28, 2022
010 Editor binary templates to open some newer Eurocom/EngineX formats.

gforce-tools 010 Editor binary templates to open some newer Eurocom/EngineX formats. https://sphinxandthecursedmummy.fandom.com/wiki/EngineX The Filel

Swyter 2 May 5, 2022