One interesting implementation is counting the number of bits set in a file. C ++ code with abundant use of STL. If everything is so good, then why is it in the
“Abnormal Programming” blog (readers strongly recommended to be moved to the C ++ blog), you ask? Now you will see :)
First, we declare a bit iterator class:
')
Now calculate the number of bits set in the executable file:
Funny is not it? And to count the number of zero bits, just need to call:
Instead:
The source code is posted here:
codepad.org/S1TT56PR (see link in UPDATE2).
UPDATE1:
Comrade
gribozavr rightly
noted that it is more correct to use the constant CHAR_BIT instead of the number 8 in the code.
UPDATE2:
Comrade
mark_ablov pointed out a flaw in the copy constructor, the code in the article was updated and here is the revised version of the code:
http://codepad.org/knEKdNJX .