
On 01/06/12 13:26, Larry Evans wrote: [snip]
So, IIUC, you want (as the name compressed_enums suggests) want to sum the sizes of each enum, then create a buffer with at least that number of bits, and then check that that buffer size is < sizeof(StorageType).
I've thought some more about the problem and started coding something; however, it's not complete, but you may be able to complete it. As it is, it just prints 3, which is: size_enum<E1>::size+sizer_enum<E1>::size
BTW, the attached code uses variadic templates; however, I'm guessing you could easily use non-variadic template compiler after some code changes.
[snip] The attached code is a revision of the previously posted code. It does not properly calculate the size of the storage needed for the compressed enums; however, IIUC this could easily be corrected using Nevin Liber's suggestion about using log2. The int enums_offsets<>::buffer[] in the real code would be what you've called: STORAGE_TYPE data; in your OP. As mentioned, the size is incorrect but that's easily remedied. The revised code also illustrates the use of CRTP to allow access of the super types to the storage buffer. These super types use the overloaded get's with the proper TAG argument to access the proper portion of the buffer. The output of the attached is: :eos_t::offset=9 :eos_v.buffer()[2]=2 :get(T1)=7 :get(T2)=4 :get(T3)=0 and was compiled with gcc4.7. HTH. -Larry