摘要:基于C++模板编程,我们可以将一部分计算放到编译期来完成,还能够给编写代码带来很多方便。比如题目中提到的,利用C++模板技术求各整数类型的最大最小值。代码如下:// indicates T is signed or unsignedtemplate< typename T > struct TFSigned{ enum { fSigned = T(-1) < 0 };}; // represents the bit length of Ttemplate< typename T > struct TBitCount{ enum { cBits = sizeof(
阅读全文
09 2012 档案