Quote Originally Posted by MWAAAHAAA View Post
Fair enough.

The following immediately stands out:

a) Why are the bits friends with the twiddler? There is absolutely no need for this in the design you presented. The statement should be removed.

b) From a conceptual point of view, the constructor to bits should not take the argument 'n'. This is simply *wrong*. Ask yourself the question why anyone constructing an instance of a bits class (a bitset if you so will), would specify which bit is supposed to be modified by any future operations performed on the bitset. What you should do in the constructor is simply construct the bitset, either an empty one, or a bitset with a predefined set of values. If you want to make things a little fancier you might want to take a second argument specifying the size of the bitset, i.e. the number of bits in the set. But not in any case a parameter which logically belongs to an operation being performed on the bitset.
Such a design would logically allow operations to be performed on just a single predefined bit in the set, whereas this is definitely not the purpose of the class, which becomes evident immediately upon seeing the workaround implemented by the author, consisting of constructing a new instance of the class (and overwriting the old one) everytime the bitset is accessed. What we want, and what is intended, but not reflected in the class design, is to modify the contents of a given bitset, instead of overwriting it completely each time an operation is performed. This is simply not a good design.

c) And this is related to point b) above, why should the parameter n be stored in the class at all? Is the bit we want to operate on an intrinsic property of a bitset? No, it is an argument to an operation that we wish to perform, hence it should be treated as such. Besides which, you are wasting space for a whole int on storing this parameter, which defeats one of the main purposes of defining a bitset in the first place: saving space! Interestingly, the actual bitset is defined as an 8-bit value (probably padded to 4 bytes though). Again, this is not proper design.



Superficially, perhaps not, but what class intended to act as a bitset would be? The bitset must be constructed and initialized, no? We have to access individual bits, no? Given the interface description for the std::bitset however, that particular implementation seems not to suffer from b, c above.



Pedantic note: "wondering about that one minor thing" implies that you do *not* "understand the entire class".

Oh, and just as anyone should respect your right to voice your opinion, so should you. So I will damn well not "shut the hell up" thank you very much.
Good points mhaaawaaa.