>>Now since we're all here to learn and exchange ideas, you will forgive me as I proceed to rip your solution apart
thanks for ripping apart my solution
>>Not quite answered the question: You were expected to use the function prototype provided. However that is minor and can be overlooked.
Agreed, but the way i want to implement it(on compile time) doesn't allow me to do that.
>>The more important issue is that your code only caters to 16-bit integers. All modern day computers use 32-bit int's (http://www.viva64.com/terminology/Data_model.html) and hence this solution would fail miserably if it were given a large enough number.
the implementation can easily be extended for 32 or even 64 bit although that would be a bit lengthy.
>>Ummm...templates?...huh?!?! Why would you use a template for your struct? A template is used to allow your code to dynamically handle different data types. The question specifies that the type is an 'unsigned int', so there was absolutely no need to use templates. Also, you hard-coded the type into the template definition anyways (template ) thus rendering it completely useless!
My implementation is like a policy based class, I want to use templates because instantiation occurs at compile time and i want my program to be interpreted at compile time.
>>Incorrect use of enum: I have no idea why you used enum's. An enum is used when you want to define a set of related constant integers. Your code arguably does not really need the bit variables to be constant, and although that part might be overlooked, using an enum for SetBits is just plain awkward!
I could have used "static const int" instead of enum but i still have old habit of using enums this is called enum hack and is used for old compilers
>>Questionable OO Design: One of the primary themes of object oriented programming is encapsulation of data. This way the functionality is hidden and data which should not be exposed is rendered inaccessible. By using public data in your struct, not only can the user access SetBits, he can also directly access your first enum containing bit0 - bit15 (note that structs are public by default). Since your aim was to design a module which takes in an int and gives you back the number of 1-bits, using a struct for the purpose is completely inappropriate. You should either have used a function as the question originally asked, or at the very least should have made bit0 - bit15 private !
To begin with i am not following OO here so i have no obligation to follow it's themes, this is like a policy base class as already written above however i do agree that bits0-bits15 should be private, struct are also used frequently in policy based classes
>>Highly inefficient: The ultimate aim is to produce an amazingly efficient solution since coming up with a correct solution is rather trivial. Your solution is not very efficient in terms of run-time, and terribly inefficient in terms of memory usage. You used 17 int's inside your struct (thats 17 * 4 = 68 bytes), when you could have written it using only 1 char (so thats 1 byte)!
hmmm did you check my program urself? my program does calculation at compile time there is no runtime calculation!
for this statement
mov dword ptr [k],2
only a single mov.