Type-qualified functions?
    Jesse Phillips 
    jessekphillips+D at gmail.com
       
    Fri Jan 21 14:30:34 PST 2011
    
    
  
Sean Eskapp Wrote:
> 
> > templates:
> 
> > void foo(T)(T, void delegate(T) fn)
> > {
> > }
> 
> > This parameterizes foo based on T, which could be A, const A, or int, or
> > whatever works to compile the function.
> 
> What if the parameters are more general, for instance the first parameter is
> always a Foo, the second is a delegate which takes a Foo.Bar, but they're always
> qualified the same way?
Their is probably better ways to do this...
void main() {
    foo(new Foo, (int) { });
}
void foo(T, U)(T t, void delegate(U) fn) 
   if(__traits(compiles, fn(t.bar))) {
}
class Foo {
    int bar() {
        return 0;
    }
}
    
    
More information about the Digitalmars-d-learn
mailing list