不完美,因为它需要每个二进制数字之间的逗号,但允许任何数量的空格和任何二进制数字的任何 const expr - 例如 0xFFFF FFFF FFFF FFFF 应该是:
use_mask<bit64<
1,1,1,1, 1,1,1,1, 1,1,1,1, 1,1,1,1,
1,1,1,1, 1,1,1,1, 1,1,1,1, 1,1,1,1,
1,1,1,1, 1,1,1,1, 1,1,1,1, 1,1,1,1,
1,1,1,1, 1,1,1,1, 1,1,1,1, 1,1,1,1
>::VAL>
代码:
template <
bool b3F,bool b3E,bool b3D,bool b3C,bool b3B,bool b3A,bool b39,bool b38,
bool b37,bool b36,bool b35,bool b34,bool b33,bool b32,bool b31,bool b30,
bool b2F,bool b2E,bool b2D,bool b2C,bool b2B,bool b2A,bool b29,bool b28,
bool b27,bool b26,bool b25,bool b24,bool b23,bool b22,bool b21,bool b20,
bool b1F,bool b1E,bool b1D,bool b1C,bool b1B,bool b1A,bool b19,bool b18,
bool b17,bool b16,bool b15,bool b14,bool b13,bool b12,bool b11,bool b10,
bool b0F,bool b0E,bool b0D,bool b0C,bool b0B,bool b0A,bool b09,bool b08,
bool b07,bool b06,bool b05,bool b04,bool b03,bool b02,bool b01,bool b00
>
class bit64
{
public:
static const unsigned long long VAL=0UL
|((unsigned long long)b00<< 0)|((unsigned long long)b01<< 1)|((unsigned long long)b02<< 2)|((unsigned long long)b03<< 3)
|((unsigned long long)b04<< 4)|((unsigned long long)b05<< 5)|((unsigned long long)b06<< 6)|((unsigned long long)b07<< 7)
|((unsigned long long)b08<< 8)|((unsigned long long)b09<< 9)|((unsigned long long)b0A<<10)|((unsigned long long)b0B<<11)
|((unsigned long long)b0C<<12)|((unsigned long long)b0D<<13)|((unsigned long long)b0E<<14)|((unsigned long long)b0F<<15)
|((unsigned long long)b10<<16)|((unsigned long long)b11<<17)|((unsigned long long)b12<<18)|((unsigned long long)b13<<19)
|((unsigned long long)b14<<20)|((unsigned long long)b15<<21)|((unsigned long long)b16<<22)|((unsigned long long)b17<<23)
|((unsigned long long)b18<<24)|((unsigned long long)b19<<25)|((unsigned long long)b1A<<26)|((unsigned long long)b1B<<27)
|((unsigned long long)b1C<<28)|((unsigned long long)b1D<<29)|((unsigned long long)b1E<<30)|((unsigned long long)b2F<<31)
|((unsigned long long)b20<<32)|((unsigned long long)b21<<33)|((unsigned long long)b22<<34)|((unsigned long long)b23<<35)
|((unsigned long long)b24<<36)|((unsigned long long)b25<<37)|((unsigned long long)b26<<38)|((unsigned long long)b27<<39)
|((unsigned long long)b28<<40)|((unsigned long long)b29<<41)|((unsigned long long)b2A<<42)|((unsigned long long)b2B<<43)
|((unsigned long long)b2C<<44)|((unsigned long long)b2D<<45)|((unsigned long long)b2E<<46)|((unsigned long long)b3F<<47)
|((unsigned long long)b30<<48)|((unsigned long long)b31<<49)|((unsigned long long)b32<<50)|((unsigned long long)b33<<51)
|((unsigned long long)b34<<52)|((unsigned long long)b35<<53)|((unsigned long long)b36<<54)|((unsigned long long)b37<<55)
|((unsigned long long)b38<<56)|((unsigned long long)b39<<57)|((unsigned long long)b3A<<58)|((unsigned long long)b3B<<59)
|((unsigned long long)b3C<<60)|((unsigned long long)b3D<<61)|((unsigned long long)b3E<<62)|((unsigned long long)b3F<<63)
;
};
对于支持它的编译器,这也可能是 constexpr