overloadable implicit cast

Adam Cigánek adam.ciganek at gmail.com
Tue Oct 26 13:10:07 PDT 2010


Hello,

Is it possible to make a type implicitly cast to another type?
Something like overloading opCast, but make it so it's used
implicitly. Or is there implicit casting in D at all?

Pseudo-example:

  // hypothetical implicit cast:
  A opImplicitCast(T)(B b) if (is(T == A)) {
    // convert b to A somehow;
  }

  void do_stuff(A a) {
    // do some stuff with a;
  }

  A a;
  B b;

  do_stuff(b); // equivalent to do_stuff(opImplicitCast(A)(b));


adam.


More information about the Digitalmars-d-learn mailing list