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 13:21:29


On 01/06/12 10:49, Allan Nielsen wrote:
> This is a much simple illustration of the problem I try to solve:
>
> template<int OFFSET>
> struct A {
> enum O { offset = OFFSET };
> enum S { size = 2 };
> };
>
> template<int OFFSET>
> struct B {
> enum O { offset = OFFSET };
> enum S { size = 4 };
> };

What is the purpose of the OFFSET template argument?
>From the name and glancing at the following code,
it looks like it has something to do with the offset
of the structure with respect to the containing structure,
such as the c1 or c2 in the following code.

Could you explain a little more. Also, the A and B structs contain
no data; yet, your first code example had enums.get<TagA>(), suggesting
there was data stored in the structs.

>
> template < typename B0, typename B1, typename B2 >
> struct C : public B0, B1, B2 {
> };
>
> int main(int argc, const char *argv[])
> {
> C< A<1>,
>
> B< A<1>::offset * A<1>::size >,
>
> A<
> B< A<1>::offset * A<1>::size >::offset *
> B< A<1>::offset * A<1>::size >::size
> >
> > c1;
>
> // does the same
> C< A<1>,
>
> B< A<1>::size >,
>
> A<
> A<1>::size *
> B< A<1>::size >::size
> >
> > c2;
>
> return 0;
> }
>
> Is there a simpler way to let template arguments propagate through
> derived classes?
[snip]

-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