gitmyhub

CppTemplateTutorial

C++ ★ 11k updated 1mo ago

中文的C++ Template的教学指南。与知名书籍C++ Templates不同,该系列教程将C++ Templates作为一门图灵完备的语言来讲授,以求帮助读者对Meta-Programming融会贯通。(正在施工中)

A Chinese-language tutorial that teaches C++ templates as their own small programming language, covering basics through advanced topics like SFINAE, variadic templates, and C++20 Concepts.

C++ClangVisual Studiosetup: easycomplexity 3/5

This repository is a Chinese-language tutorial for C++ templates, written with the goal of making the topic accessible to developers who find standard reference books too dense. The author's approach is to treat the C++ template system as its own small programming language with its own values, functions, and expressions, rather than presenting templates as just an extension of regular C++ syntax. The idea is that once you see templates this way, most techniques in template programming become much easier to follow.

The tutorial is organized into chapters that build on each other. Early chapters cover the basic syntax of class templates and function templates: how to declare them, how to instantiate them, and how to define member functions outside the class body. The middle chapters move into template metaprogramming fundamentals, covering specialization and partial specialization (which serve as a form of compile-time conditional logic), name lookup rules, and the typename keyword. Later chapters go deeper into partial specialization versus function overloading, variadic templates, SFINAE (a mechanism that lets template substitution failures be handled gracefully rather than causing hard errors), and Concepts, a C++20 feature for adding clear constraints to template parameters.

The recommended compilers for working through examples are Clang 14 or later and Visual Studio 2022. An online compiler link is provided for convenience. The tutorial has been written over time and some sections are noted as still under construction. The intended audience is developers who already know basic C++ and have used the standard library, but have not studied templates in depth.

The full README is longer than what was shown.

Where it fits