Open-source project
wuye9036/CppTemplateTutorial avatar
wuye9036/CppTemplateTutorial

CppTemplateTutorial: templates taught as a language of their own

A Chinese-language guide to C++ templates. Unlike the well-known book C++ Templates, this series teaches C++ templates as a Turing-complete language, aiming to help readers fully master metaprogramming. (Work in progress.)

10,599 stars1,604 forksC++License varies

At a glance

What is it?
A Chinese-language C++ template guide that treats template code as a self-contained language rather than a C++ feature, and that ships its own list of chapters it has not written yet.
Who is it for?
Read this if you already know C++ syntax and STL and want template metaprogramming explained through a language analogy rather than a rule catalogue. It will not serve as a syntax reference: the deduction rules, ADL, and variadic packing are named as future work, and the two books it positions against are still the denser references.
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 180 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 November 15, 2026, and from our analysis. They are not legal advice.

From daily snapshots

Star history

  • wuye9036/CppTemplateTutorial10,599 ★ · +8
Star history
Repository2026-09-222026-11-15
wuye9036/CppTemplateTutorial10.6k10.6k

8 Stars in the last 54 days, measured from the daily GitHub snapshot. Compare with other projects

Editorial analysis

Templates are presented as a separate language, and the books it names are reading order

The project description says outright that this series teaches C++ Templates as a Turing-complete language, in contrast to the book C++ Templates, aiming to help readers fully master metaprogramming, and that it is under construction. Chapter 1.1 gives the argument: as of C++03 templates already had values, functions, expressions and statements, but no pointers, no arrays, and none of C++'s inheritance and polymorphism, so the subset is smaller than C itself. The chapter then runs the history in dated steps, from generic programming entering C++ consideration in 1987, through Alexander Stepanov's library work starting in 1992 and the STL entering the standard in 1993, to the Barton and Nackman matrix multiplication example in the 1995 C++ Report, Alexandrescu's Modern C++ Design and the Loki library in 2001, and C++ Templates in 2002. Section 1.2 turns that history into a reading order: this guide first, C++ Templates second for the denser syntax detail, and the Typelist chapters of Modern C++ Design only after finishing here.

Instantiation is a two-step process with a syntax form of its own

Chapter 2.2.3 makes the point that defining a variable takes two steps: vector<int> binds int to the class template to produce an ordinary class, and only then does that class declare a variable. Because of the split, a class template name alone cannot declare a variable, and the README shows the mistake directly:

C++
vector unknownVector; // 错误示例

The fix is template instantiation, given its own notation in the chapter:

code
模板名 < [模板实参1,模板实参2,...] >

and instantiated against a two-parameter template:

C++
template <typename T0, typename T1> class ClassB
{
    // Class body ...
};

ClassB<int, float>

The practical consequence for a reader is that the compiler will not carry a template name across on its own. Each use site has to spell the arguments, and the arguments have to match the parameters in count and kind, in the same way a function call has to match its signature.

The examples are a Visual Studio solution with precompiled headers

The repository is not laid out as a code tree you can build per chapter. Top-level entries are .gitattributes, .gitignore, CppTemplateTutorial.cpp, CppTemplateTutorial.sln, CppTemplateTutorial.vcxproj, CppTemplateTutorial.vcxproj.filters, QuickSort.cpp, ReadMe.md, stdafx.cpp, stdafx.h and targetver.h. That is one Visual Studio solution and one project file, plus stdafx.h and targetver.h, which are the standard MSVC precompiled-header scaffolding. There is no CMakeLists.txt and no Makefile at the top level, so on Linux or macOS you reconstruct a project yourself before any snippet builds, and there is no directory that corresponds to a chapter, which means the code for a given section cannot be pulled out as one unit. The online compiler links in chapter 1.4 fill that gap for reading, at gcc.godbolt.org, but they are for previewing a snippet rather than for running the sample project.

One writing convention for snippets, and no bibliography behind the quotes

Section 1.5 fixes the house style: example code is shown in C++ code blocks, and the sample snippet is a function carrying a Chinese comment.

C++
void SampleCode() {
    // 这是一段示例代码
}

Quotations are also marked in place, with a standard citation carrying its clause number in the form 1.1.2/1 and a book citation carrying only its title in 《书名》 form. So attribution exists inline, but there is no reference list to resolve, which means you cannot check a quote's edition or page from anything inside the repository. Section 1.3 is explicit about the reason and the terms: the text was written straight into GitHub as it went, so some citations will be missing, and the author retains all copyright over the writing while asking that any repost or quotation name the source and notify the author. Section 1.6 lists an unbuilt section that would have standardized all of this, a how-to-use-this-article section covering typography, hints and example organisation.

Chapter 5 is the unfinished-chapters heading, and section 1.6 is the to-do list

The table of contents ends at chapter 5 with a heading that names unfinished chapters, so the incompleteness is structural rather than a matter of trimming. Section 1.6 spells out what is queued. Under what still needs adding: the motivation for using templates at all, the how-to-use section, examples given real purpose rather than only demonstrating syntax, a full narration of the type deduction rules covering Parameter-Argument matching, the auto variable, decltype and decltype(auto), ADL inside the sections on function template overloading and instantiation, and variadic templates taught to the standard's Argument Packing and Unpacking rather than informally. Under what is only suggested: comparing templates against ordinary functions, and an analysis of C++14 return type deduction for normal functions. The consequence is precise: four topics a template programmer needs, ADL, deduction, variadics and return type deduction, are promises in a list rather than chapters you can read.

Specialization is the if-then-else, and it does not transfer cleanly to functions

Chapter 3.2 is titled the if-then-else of the template world, and it is built on class template specialization and partial specialization, running from executing code according to type, through specialization itself, to a subsection of other questions about specialization. Chapter 4 then goes deeper on partial specialization, opens with a section on understanding partial specialization correctly, and immediately compares partial specialization with function overloading. That comparison is the load-bearing part, because for function templates you select behaviour by overloading, not by specializing, so a reader who has just internalised selection through specialization has to rebuild part of the model on the way over. The same chapter carries two further mechanics that get their own sections, non-fixed template parameter lists and default template arguments. Both are listed as chapter content rather than discussed, and both are the kind of detail that changes how a signature is written, so the practical gap is at the level of code you write, not background you read.

Three constraint mechanisms, and only one of them is tagged with a standard

Chapter 3.3 covers deduction at the point of use, 即用即推导, split into three subsections that name the difficulties directly: syntax errors that are not reported as errors, name lookup under the heading I am who I am, and the redundant typename keyword. Chapter 4.2 adds SFINAE, filed under a heading that frames it as regret medicine, a cure you reach for after the fact. Chapter 4.3 adds Concepts, described as a direct description of constraints on template parameters, with subsections on what concepts solve and an introduction to them. The version story is thin here: the only feature in the section 1.4 standards table is std::decay_t<T> at C++14, and the compiler list is Clang 14.0.3 and 15.0 on amd64 plus Visual Studio 2022 19.2 or later on amd64.

Editorial conclusion

Read this if you already know C++ syntax and STL and want template metaprogramming explained through a language analogy rather than a rule catalogue. It will not serve as a syntax reference: the deduction rules, ADL, and variadic packing are named as future work, and the two books it positions against are still the denser references. Before quoting or redistributing anything from it, settle the license question yourself, since the repository carries no license file and the author only asks in text for attribution.

Frequently asked questions

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

In CppTemplateTutorial, typename is compared to the int in a function parameter declaration, marking that the template parameter T will match a type, while the parameter name itself is compared to a function formal parameter.

What is a CPP template?

The guide treats templates as a language in their own right, arguing that as of C++03 they had values, functions, expressions and statements, but no pointers, no arrays, and no inheritance or polymorphism.

How do I use templates in C++?

A class template cannot declare a variable by itself. You instantiate it by supplying the template arguments, written as the template name followed by angle brackets, and the README shows vector<int>, ClassA<double> and ClassB<int, float> as the notation.

What is a template and example?

The class template declaration and definition are shown as template <typename T> class ClassA, followed by a definition holding a member of type T, which the chapter then illustrates with vector<int> and vector<float> variables.

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)

Star history chart for your README

markdown
[![Star history](https://hysenlabs.com/chart/wuye9036-cpptemplatetutorial.svg)](https://hysenlabs.com/projects/wuye9036-cpptemplatetutorial)

Was this useful?