C#'s greatest mistakes

Torarin torarind at gmail.com
Sat Nov 27 16:23:02 PST 2010


2010/11/28 Jonathan M Davis <jmdavisProg at gmx.com>:
> If you have a set
> of functions that are expected to be there (for instance, to verify that the
> given type is a certain type of range), then just create template which checks
> for each of the functions that are supposed to be there and use the template (
> e.g. isForwardRange!T ). Interfaces and structs don't have anything to do with
> each other.

Yes, that works, and you end up with this:

template isSomething(T)
{
  enum bool isSomething = is(typeof(
  {
    int ret = T.foo(5);
    string ret2 = T.bar();
    T.write("");
   }()));
}

I don't see what's so wrong with being able to do:

interface Something
{
  int foo(int);
  string bar();
  void write();
}

if (Implements!(Something, T))

Thanks for the link, BLS, I'll see if I can make it work.


More information about the Digitalmars-d mailing list