On Tuesday, 3 October 2023 at 14:06:37 UTC, ryuukk_ wrote:
On Tuesday, 3 October 2023 at 11:43:46 UTC, Joel wrote:
I’ve got a struct that has a method that adds numbers together. I want to do something like this, static if (isInteger!T) … but it isn’t working. static if (is(T==int)) works for one integer type.

```d
struct List(T) {
     auto addUp()
         If (isInteger!T) {
             (Add numbers)
         }
    }
}
```


```D
static if (__traits(isIntegral, T))
{
}
else static assert(0, "type no supported");

```

https://dlang.org/spec/traits.html#isIntegral

Oh, I found,
```d
static if (isIntegral!T)
```
seems to work.

Reply via email to