opDispatch & with

drug007 drug2004 at bk.ru
Fri Feb 17 21:06:34 UTC 2023


17.02.2023 23:55, drug007 пишет:
> 17.02.2023 22:30, John Chapman пишет:
[snipped]

  Probably you meant something like this:
```D
import std;

enum Suit { clubs, spades, hearts, diamonds }

struct Card {
    void opDispatch(string s)(Suit t)
    {
        pragma(msg, s); // compile time output - suit
        writeln(t);     // runtime output      - diamonds
    }
}

void main() {
    Card c;
    with (c) suit = .Suit.diamonds;
}
```


More information about the Digitalmars-d mailing list