On Tuesday, 6 July 2021 at 10:06:11 UTC, Jack Applegame wrote:


Here's another way using ``` std.typecons ```

```d
import std.stdio;
import std.typecons;
alias input = Typedef!int; //new code
struct Field {
    void opAssign(int a) {
        writefln("Field.opAssign(%s)", a);
    }
}

struct Register {
    Field clock(input a) {
writefln("Register.clock(%s)", cast(int)a); //note the cast
        return Field();
    }
}


void main() {
    input ip = 1;
    Register register;
    register.clock(ip) = 10; // works, good
//register.clock = 10; // works too, how to disable it? EDIT: Now it doesn't work :)
}
```

You will have to either cast your literal, or provide a variable with the new type as input though, so it is also not perfect.

Reply via email to