Boost logo

Boost Users :

Subject: Re: [Boost-users] Needs advices on design ( mpl or processor )
From: Larry Evans (cppljevans_at_[hidden])
Date: 2012-01-06 14:26:52


On 01/06/12 12:56, Allan Nielsen wrote:
>> Wouldn't that variable have to be large enough to contain all the enums.
>> At first glance this looks like:
>>
>> fusion::vector<Enum_1,Enum_2,...Enum_n>:
>
> The idea is that four enums which each only can contain four values,
> can together only represent 256 ( 4^4) values which can be stored in a
> char.
>
> This off cause assume that their associated values are defined from 0 to 3.
>
> It also works for numbers which are not powers of 2:
>
> enum A{ a0 = 0, a1 = 1, a2 = 2, a3 = 3, a4 = 4 };
> enum B{ b0 = 0, b1 = 1, b2 = 2, b3 = 3, b4 = 4 };
>
> CompressedEnums< unsigned char,
> CompressedEnum<unsigned char, 1, A>,
> CompressedEnum<unsigned char, 5, B>
> > ENUMS;
>
> sizeof(ENUMS) == sizeof(unsigned char);
>
> I do not know boost::fusion very well, but I do not think this use
> full for this.

I think you're right. IIRC, fusion::vector stores all its values in
member variables name m1, m2, ...,mn, where, in your case:

  A m1;
  B m2;

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.

HTH.

-regards,
Larry




Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net