文档目录
模板元编程(Template Metaprogramming)
模板元编程让编译器在编译期执行计算。理解它不是为了写花哨代码,而是为了写出高性能、零运行时开销的泛型库。
本节目录
- 泛型编程与模板特化 一、类模板全特化与偏特化 // 主模板 template <typename T> struct TypeInfo { static constexpr …
- 编译期类型萃取(Type Traits)与 SFINAE 一、Type Traits 的本质 #include <type_traits> // is_pointer 的底层实现(简化版) template …
- `constexpr` 与 C++20 Concepts 一、constexpr —— 让代码在编译期运行 // 编译期阶乘 constexpr int factorial(int n) { if (n <= 1) …
- 第一阶段到第四阶段总结 第一阶段(移动语义): 左值/右值 → std::move 是 cast 不是 move → 右值引用变量本身是左值(面试陷阱) → 完美转发 …