Type constraint

ryuukk_ ryuukk.dev at gmail.com
Tue Oct 3 14:06:37 UTC 2023


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


More information about the Digitalmars-d-learn mailing list