www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Regarding type deduction

reply "bearophile" <bearophileHUGS lycos.com> writes:
Do you think it's useful and possible to extend the D type 
inference (deduction) for templates to support something like 
this (I know there are different ways to do this in D)?


struct Tree1 {
     static struct Node { int x; }
}
struct Tree2 {
     static struct Node { int x, y; }
}
void foo(T)(T.Node n1, T.Node n2) {} // ***
void main() {
     Tree1.Node n1, n2;
     foo(n1, n2);
}


(I am asking this because nested types are becoming increasingly 
common in D code.)

Bye,
bearophile
Sep 17 2012
parent "Jesse Phillips" <jessek.phillips+D gmail.m> writes:
On Monday, 17 September 2012 at 14:54:48 UTC, bearophile wrote:
 Do you think it's useful and possible to extend the D type 
 inference (deduction) for templates to support something like 
 this (I know there are different ways to do this in D)?


 struct Tree1 {
     static struct Node { int x; }
 }
 struct Tree2 {
     static struct Node { int x, y; }
 }
 void foo(T)(T.Node n1, T.Node n2) {} // ***
 void main() {
     Tree1.Node n1, n2;
     foo(n1, n2);
 }


 (I am asking this because nested types are becoming 
 increasingly common in D code.)

 Bye,
 bearophile

I can't say I've ever thought to have such. But it seems it could simplify something. Though I'd think the syntax: Void foo(T: T.Node) (... Or more proper.
Sep 17 2012