On Wednesday, 21 February 2018 at 14:42:56 UTC, Simen Kjærås wrote:
On Wednesday, 21 February 2018 at 14:29:38 UTC, ixid wrote:
I do not understand what is happening here, I tried to wrote what I thought would be the answer. If someone could explain that would be great. I wrote this code:

struct Foo2(T, S) {
  T bar;
  this(S s) {
    bar = s.to!T;
  }
}

void main() {
        float some_float = 0.5f;
        int some_int = 1;

        auto foo1 = Foo2!(int, float)(some_float);    // Compiles, OK!
auto foo2 = Foo2!(int, float)(some_int); // Compiles, wat?
}

int n = 1;
float f = n; // Basically this.

Foo2!(int, float) expects a float, and ints are implicitly convertible to float.

--
  Simen

Ah yes, that was silly of me to forget. Thanks!

Reply via email to