I saw a C ++ post on the BBS. Is the C ++ child going astray ?, It reminds me of ordinary youth and literary youth. Bytes
Bytes
Look at this typical NB program and find the number of bits.
Common C ++ programmers
Namespace traditional
{
Int bits_of (int remain)
{
If (remain)
Return 1 + bits_of (remain> 1 );
Return 0;
}
Int bits_of (void)
{
Return bits_of (~ (Int) 0 );
}
}
C ++ programmers
Namespace modern
{
Template <int, typename THEN, typename ELSE>
Struct IF {typedefTHEN type ;};
Template <typename THEN, typename ELSE>
Struct IF <0, THEN, ELSE> {typedef ELSE type ;};
Template <typename T, t x>
Struct zero
{
Static const Tvalue = X;
};
Template <typename T, t x>
Struct bits_of
{
Typedef typenameIF <X, bits_of <T, (X> 1)>, zero <T, 0 >>:: type;
Static const Tvalue = type: value + !! X;
};
}
Unit test of Wen Qing,
Typedef int a0 [bits_of <int, 0 >:: value = 0? 1:-1];
Typedef int a1 [bits_of <int, 1 >:: value = 1? 1:-1];
Typedef int a2 [bits_of <int, 2 >:: value = 2? 1:-1];
Typedef int a3 [bits_of <int, 3 >:: value = 2? 1:-1];
Typedef int a4 [bits_of <int, 4 >:: value = 3? 1:-1];
Typedef int a7 [bits_of <int, 7 >:: value = 3? 1:-1];
Typedef int a8 [bits_of <int, 8 >:: value = 4? 1:-1];
Typedef int a15 [bits_of <int, 15 >:: value = 4? 1:-1];
Typedef int a16 [bits_of <int, 16 >:: value = 5? 1:-1];
Class C ++ programmers
Namespace third_party
{
// Are you sure you can understand? Zookeeper
}
From Viper's column