On Tue, Nov 06, 2012 at 04:20:34PM +0100, Joseph Rushton Wakeling wrote:
> Suppose that I have two struct templates which take identical
> parameter lists:
> 
>     struct Foo(T1, T2, T3)
>     {
>         ...
>     }
> 
>     struct Bar(T1, T2, T3)
>     {
>         ...
>     }
> 
> Now suppose that I have a Foo which has been instantiated with a
> given set of parameters.  Is there any way for me to say, "now
> instantiate a Bar with the same parameters?"

You could alias the parameters so that they're accessible from outside:

        struct Foo(T1, T2, T3)
        {
                alias T1 t1;
                alias T2 t2;
                alias T3 t3;
                ...
        }

        struct Bar(X1, X2)
        {
                ...
        }

        auto fooToBar(FooInstance)(FooInstance f)
        {
                return Bar!(f.t2, f.t3)();
        }

This works if T1, T2, T3 are types. If they're values, you'll need to
use enums in Foo instead.


T

-- 
There are three kinds of people in the world: those who can count, and those 
who can't.

Reply via email to