Metaprogramming

Shangri-La of CPP - Template Metaprogramming(TMP)

C++程序员生活在两个世界里, 区别在于是否使用template metaprogramming(TMP).

C++ programmers live in two worlds, which are different depending on whether they use template metaprogramming(TMP) or not.

一个世界是几乎不使用TMP, 另一个世界几乎用TMP完成95%的代码.

In one world, programmers almost never use TMP. In the other world, programmers use TMP for about 95% of their code.

这篇文章是写给第一个世界C++程序员的TMP使用技术简介.

This article is a short introduction to TMP for C++ programmers in the first world (who do not use TMP often).

我们先使用TMP实现一个简单的程序, 你可以思考下如果不使用TMP应该如何实现.

Let’s start with a simple example using TMP. You can think about how you would write it without TMP.