Open-source project
wuye9036/CppTemplateTutorial avatar
wuye9036/CppTemplateTutorial

CppTemplateTutorial: Teaching C++ Templates as a Turing-Complete Language

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

10,592 stars1,606 forksC++License varies

At a glance

What is it?
A Chinese-language tutorial series that treats C++ templates as their own programming language rather than as a feature of C++. It is aimed at readers who already know basic C++ and want metaprogramming to stop feeling like folklore.
Who is it for?
Adopt it if you write library code, already know basic C++ syntax, and want specialization, SFINAE and concepts explained as one connected language instead of as scattered tricks. Do not adopt it as a first C++ course: the README assumes familiarity with STL and recursion, and the repository itself states that chapter 5 is unfinished and that several announced sections are still to be written.
Can I use it commercially?
Not without permission. GitHub finds no licence file in the repository, and without a licence all rights are reserved by default: you may read the code but not reuse it. Check the README, or ask the authors, before using it.
Is it still maintained?
Yes. The repository last received commits 133 days ago.
What is it written in?
Mainly C++, according to GitHub's language statistics.

Answers come from the project's GitHub data, last synced on September 26, 2026, and from our analysis. They are not legal advice.

Editorial analysis

The problem CppTemplateTutorial takes on

Most C++ template material falls into one of two camps. Reference books enumerate syntax and language rules until a beginner gives up, and metaprogramming books assume you already enjoy writing typelists. The README says exactly this about the two well-known predecessors: it calls C++ Templates rich in detail but says that for newcomers the detail is so abundant that they retreat, and it describes Modern C++ Design as written in a near-geek style that makes it somewhat hard to read.

The stated goal is to present a simple, clear template language from the perspective of a programming language. The argument in section 1.1 is that in the C++03 era templates could stand alone as a language with values, functions, expressions and statements, and that apart from awkward syntax it has no pointers, no arrays and none of C++'s inheritance or polymorphism. If that framing is right, then learning templates as a language should cost a fraction of what learning object orientation costs.

The audience is narrow and the README is honest about it. Readers should be comfortable with basic C++ syntax, should have used the STL, and should know common algorithms plus recursive design methods. This is not an introductory C++ text, and the examples assume you can already write a basic function template and class template.

How the tutorial is structured, from class templates to concepts

The table of contents runs from template basics through to concepts, and the ordering carries an argument. Chapter 2 covers class templates, function templates, and the fact that integers can be template parameters. Chapter 3 builds the metaprogramming foundation: what metaprogramming is, then specialization and partial specialization presented as the if-then-else of the template world, then instantiation and name lookup, including the typename keyword.

Chapter 4 is where the design becomes visible. It compares partial specialization with function overloading, covers variadic template parameters and default template arguments, then moves to SFINAE and finally to concepts as a direct description of constraints on template parameters. That sequence matters: concepts arrive after you have seen the problems that specialization and SFINAE create, which is the opposite of how a reference manual usually presents it.

The repository layout matches a book rather than a library. The top level holds ReadMe.md, a Visual Studio solution and project (CppTemplateTutorial.sln, CppTemplateTutorial.vcxproj), a CppTemplateTutorial.cpp translation unit, plus QuickSort.cpp, stdafx.cpp, stdafx.h and targetver.h. The chapter table of contents is generated by the Markdown All in One VS Code extension, so the structure is maintained as Markdown rather than as a build artifact.

Getting the material and compiling your first template

There is no package to install. The project is a tutorial repository, so the material is the Markdown and the accompanying C++ files. Clone it and open the solution in Visual Studio, or read ReadMe.md directly on GitHub.

bash
git clone https://github.com/wuye9036/CppTemplateTutorial.git
cd CppTemplateTutorial

The README states which compilers were used to test the code in the text: Clang 14.0.3 and 15.0 on amd64, and Visual Studio 2022 19.2 or later on amd64. Some complex examples also link to an online compiler preview at gcc.godbolt.org, which is useful if you do not want to set up either toolchain locally.

A first real exercise is the class template from section 2.2.2. Declare it, define it, and instantiate it with a concrete type.

C++
template <typename T> class ClassA
{
    T member;
};

ClassA<int> a;

The README explains that `template` is the keyword introducing a template, that `typename T` is a template parameter, and that `T` plays the role of a function parameter while `typename` plays the role of the parameter's type. Instantiating `ClassA<int>` substitutes int for T. Section 2.2.3 stresses that a class template cannot define a variable on its own: `vector unknownVector;` is given as an error example, because instantiation with concrete arguments is what produces a real class. The same section shows the instantiation form as a template name followed by angle brackets containing the arguments, with `ClassB<int, float>` as an example of a two-parameter template.

Where the tutorial is thin, and where it stops

The repository is candid about being unfinished. The description on the repository page says the series is under construction, and chapter 5 of the table of contents is literally titled as unfinished chapters. Several sections in chapter 2, including 2.1 on what a template is, 2.2.1 on the terminology question of template class versus class template, and the whole of 2.3 on function templates, appear in the contents without body text in the README.

Section 1.6 lists what the author still intends to add: motivation for using templates, a how-to-use-this-document section, complete type deduction rules covering parameter-argument, auto variables, decltype and decltype(auto), ADL in the context of function template overloading and instantiation, and variadic templates explained according to the standard's argument packing and unpacking rules. If your reason for reading is to understand deduction or variadic templates, the README itself tells you that ground is not covered yet.

There is also a version boundary. The introduction frames the whole approach around C++03, where templates could be treated as a standalone language. The recommended compilers are modern, and the standard table lists std::decay_t<T> as requiring C++14, but the conceptual framing predates concepts being standardized. Readers on C++20 or later should expect to reconcile the tutorial's model with the language they actually compile.

How this differs from a reference book approach

The obvious alternative is C++ Templates, which the README names directly and positions itself against. The difference is one of ordering and intent. A reference book presents the language rules and lets you assemble a mental model; this tutorial starts from the claim that templates are a language with values, functions, expressions and statements, and then introduces specialization as control flow and SFINAE as a recovery mechanism.

The README also gives a reading order rather than treating the books as competitors. It suggests reading this tutorial first, then C++ Templates for richer syntax and implementation detail, and for Modern C++ Design it suggests reading the generic programming chapters after chapters 1 to 3 while leaving the metaprogramming parts such as Typelist until after this tutorial. That is a concrete claim about where the overlap sits: little overlap with the generic programming material, more with the metaprogramming material.

A second alternative is simply the compiler and cppreference. If you need to know whether a specific construct compiles, a two-line example on gcc.godbolt.org answers faster than any book. This tutorial is worth reading for the model, not for lookup.

Maintenance, licence and what a fork costs you

The repository is not archived, and the last push was on 2026-05-20. That is recent enough that the text is still being touched, but the README's own unfinished-chapter list is the better signal of completeness than the push date: activity here means chapters are being written, not that the book is finished.

Upgrade cost is close to zero in the software sense. There is no dependency to track, no build step required to read the material, and the only versioned artifact is the Visual Studio solution used for the accompanying code. The real cost is editorial: if you translate or adapt the text, you inherit a moving target while chapters 2, 3 and 4 are still being filled in.

The licence is the practical obstacle. The README's copyright section states that the author reserves all rights over the parts he wrote, and that anyone reposting or quoting should credit the source and inform the author. No licence file appears among the top-level entries, and the repository metadata does not name one. That is not a permissive licence by any reading, so a company wanting to reuse the text internally should treat the credit-and-notify request as a condition to satisfy rather than an optional courtesy. This is a description of what the README says, not legal advice.

Editorial conclusion

Adopt it if you write library code, already know basic C++ syntax, and want specialization, SFINAE and concepts explained as one connected language instead of as scattered tricks. Do not adopt it as a first C++ course: the README assumes familiarity with STL and recursion, and the repository itself states that chapter 5 is unfinished and that several announced sections are still to be written. Before relying on it, check the chapter list against what you need, since the README's own to-do list mentions missing material on type deduction rules, ADL and variadic templates. The licence question is the one to settle first: the README reserves copyright on the author's own text and asks reusers to credit the source and notify the author, and no licence file is visible at the repository root.

Frequently asked questions

What does the `template <typename T>` keyword mean in C++?

The README explains that `template` is the keyword that announces a template definition, and that `typename T` is a template parameter where T behaves like a function parameter and typename plays the role of its type. The parameter T is later replaced by a concrete type when the template is instantiated, as in ClassA<int>.

What is a C++ template?

The tutorial treats a template as a form from which concrete classes or functions are produced by binding types or integers to template parameters. The README notes that a class template cannot define a variable by itself, and that binding arguments to it, called instantiation, is what yields an ordinary class.

What is a template and example?

The README's example is a class template declared as `template <typename T> class ClassA;` and defined with a single `T member;`. Instantiating it as ClassA<int> produces a class whose member is an int, which the README compares to a typedef of a class containing an int member.

How do I use templates in C++?

According to the README, you declare and define the template with its parameters, then instantiate it by writing the template name followed by angle brackets containing the arguments, such as vector<int> or ClassB<int, float>. The README notes that the arguments must match the parameters correctly, just as with a function call.

Official sources

  1. Issues
  2. README
  3. wuye9036/CppTemplateTutorial on GitHub
Add this badge to your README

If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.

Add this badge to your README

markdown
[![Hysen Labs](https://hysenlabs.com/badge/wuye9036-cpptemplatetutorial.svg)](https://hysenlabs.com/projects/wuye9036-cpptemplatetutorial)