C#'s greatest mistakes

Jonathan M Davis jmdavisProg at gmx.com
Mon Nov 29 12:30:13 PST 2010


On Sunday, November 28, 2010 04:43:47 Jérôme M. Berger wrote:
> Jonathan M Davis wrote:
> > A clearer way to create such template constraints would definitely be
> > nice. But aside from the fact that I'd absolutely hate to see interfaces
> > be conflated with template constraints in this manner, you'd need a way
> > to deal with the fact that the parameters and return types for such
> > functions are frequently dependent on the type that the template is
> > being instantiated with. A concept as you describe it would have to
> > somehow take templated types into account in a way that interfaces
> > can't. For instance, you could never define an interface which defined a
> > forward range like isForwardRange!() does because the interface wouldn't
> > be properly templatized.
> 
> 	Why not?
> 
> ==============================8<------------------------------
> concept FooBar(U)
> {
>    int  foo (int);
>    bool bar (U);
> }
> 
> template Test(T, U) if (is!(FooBar!U, T)) ...
> ------------------------------>8==============================
> 
> 	This already works with class and interface templates...

That may work. I was thinking of a verifying against a concrete interface - 
which _wouldn't_ work with templates. I probably didn't think of this because 
mixing templates and interfaces or classes is generally a bad idea in D, because 
template functions can't be virtual.

- Jonathan M Davis


More information about the Digitalmars-d mailing list