Implicit type conversion for function calls?

Simen Kjaeraas simen.kjaras at gmail.com
Sun Jul 10 06:29:06 PDT 2011


I'm trying to have this sort of code compile:

////////////////
struct Foo {
      int data;
      this(int n) {
          data = n;
      }
}

void bar(Foo f) {}

bar(3);
////////////////

Is this even possible? I believe the feature was called
opImplicitCastFrom, at some point.

Conversely, the following would also be useful:

////////////////
struct Foo {
       int data;
       this(int n) {
           data = n;
       }
}

void bar(int n) {}

Foo f;
bar(f);
////////////////

This would then be called opImplicitCastTo.

The reason I want this, is I'm trying to create templates that do what
typedef should - create a supertype, subtype, or lateral type to an
existing type.

-- 
     Simen


More information about the Digitalmars-d-learn mailing list