Boost Users :

Subject: Re: [Boost-users] Needs advices on design ( mpl or processor )
From: Larry Evans (cppljevans_at_[hidden])
Date: 2012-01-07 18:28:25

On 01/07/12 02:42, Allan Nielsen wrote:
> On Sat, Jan 7, 2012 at 1:54 AM, Larry Evans <cppljevans_at_[hidden]> wrote:
>> On 01/06/12 16:19, Allan Nielsen wrote:
>>> My problem is not to calculate the actually size, but move the
>>> calculation from the instantiation into the definition of the library.
>> I have not idea what this means.
>
> First of all, thanks for your input.
>
> I will try to illustrate my design problem in a more simple example:
>
> struct TagA {
> enum Size { size = 4 };
> enum E { A0 = 0, A1 = 1, A2 = 2, A3 = 3, };
> };
>
> struct TagB {
> enum Size { size = 4 };
> enum E { B0 = 0, B1 = 1, B2 = 2, B3 = 3, };
> };
>
> struct TagC {
> enum Size { size = 4 };
> enum E { C0 = 0, C1 = 1, C2 = 2, C3 = 3, };
> };
>
>
> // Simple edition of CompressedEnum, but has the same problem

Sorry, what was that problem again?

> template<typename T, int OFFSET>
> struct CompressedEnum {
> enum O { offset = OFFSET };
> enum S { size = T::size };
> T get( ) { ... }
> };
>
> // Simple edition of CompressedEnums, but has the same problem
> template < typename B0, typename B1, typename B2 >
> struct CompressedEnums: public B0, B1, B2 {
> template < typename T> get() { ... }
> };
>
> void example1()
> {
> // As you see, the expresions for calculating the offset get quite long,
> // and are not easy to maintain.

Here's where I don't understand why the calculation are done outside
the temple and then passed as args to the template.
Why not have a template do the calculations and accumulate the results,
somewhat like mpl::fold or the code I posted earlier?

> C< CompressedEnum<tagA, 1>,
>
> CompressedEnum<tagB, CompressedEnum<tagA, 1>::offset *
> CompressedEnum<tagA, 1>::size >,
>
> CompressedEnum<tagC,
>
> CompressedEnum<tagB, CompressedEnum<tagA, 1>::offset *
> CompressedEnum<tagA, 1>::size >::offset
> *
> CompressedEnum<tagB, CompressedEnum<tagA, 1>::offset *
> CompressedEnum<tagA, 1>::size >::size
> >
> > c1;
>
>
> }
>
[snip]

-regards,
Larry