On Monday, 1 September 2025 at 13:37:11 UTC, user1234 wrote:
On Monday, 1 September 2025 at 12:20:02 UTC, Kapendev wrote:
Insane way to do things:

```d
struct Matrix(R, C, T, bool canFly, bool isCute) if ((isNumberType!T || isMathType!T) && isGoodType!T && isMagicType!T) {
    static if (canFly) {
        this(Blah blah) {
            // Blah blah...
        }
    } else static if (isCute) {
        this(Blah blah) {
            // Blah blah...
        }
    } else {
        // Blah blah...
    }
    // Just more template hell...
}
```

This example is actually an issue very specific to constructors, which cannot be overloaded if templatized. Non-ctor functions can be both overloaded and templatized.

I think the D style to prevent that is to use "static factories", i.e thanks to a global function you prevent the problem of having both template constraints and static `ifs`.

Wrong, now I remember what is the issue I thought about... it is that you cannot explicitly instantiate a templatized ctor... as there are not named (they is the workaround sub mentioned however).

Reply via email to