Inferring function argument types from other argument types
Joseph Rushton Wakeling
joseph.wakeling at webdrake.net
Mon Nov 12 10:53:09 PST 2012
On 11/12/2012 04:38 PM, Vijay Nayar wrote:
> I think this is what you want. This example compiled and ran using DMD v2.060.
>
> FooType.T1 func(FooType, FooT1)(FooType foo, FooT1 x)
> if (is(FooType.T1) && is(FooT1 : FooType.T1))
> {
> return x * foo.a;
> }
Thanks for that. You're obviously correct to use FooType.T1 as return type
here; the reality of what I'm trying to do is slightly more complicated, as the
real situation I have is that I'm passing the x value on into another (also
templated) function. But of course I can use FooType.T1 for that template value.
I'm still a little disappointed that I can't just insist that a given parameter
type should depend on another template parameter. :-(
To be sure I understand your formulation, can you clarify the meaning of
is(FooT1 : FooType.T1)?
More information about the Digitalmars-d-learn
mailing list