C++ 模板数字拼接
// 辅助函数:计算 10 的幂
constexpr int pow10(int n)
{
return n == 0 ? 1 : 10 * pow10(n - 1);
}
template <int... Num>
struct NumCat;
template <int First, int... Rest>
struct NumCat<First, Rest...>
{
static constexpr int value = First * pow10(sizeof...(Rest)) + NumCat<Rest...>::value;
};
template <int Last>
struct NumCat<Last>
{
static constexpr int value = Last;
};
/*
数字拼接:
如: constexpr int result = IDCat<1,2,3>::value; // 会得到:result = 123;
*/