On Saturday, 24 May 2025 at 20:29:52 UTC, Andy Valencia wrote:
The best I"ve come up with for a "static if" to see if something's an array of ubyte:

OK, so e.g. `ubyte[] arg`.

```d
(isArray!(typeof(arg))) &&
```

That's fine.

is(typeof(arg).init[0] == ubyte)

1. Unfortunately `typeof(arg).init` gives `null` when `arg` is a dynamic array, so indexing won't work. Note: intuitively it would be `[]`, though perhaps with the same type as `arg`, but it isn't.

However, you already have a value - `arg`. So you can just use `arg[0]`.

2. `typeof(arg).init[0]` is a value, not a type. `is()` (almost) always takes a type for its first parameter. So for a static array `arg` only, `is(typeof(arg.init[0]) == ubyte)` does work.

Fixing both, you can use `is(typeof(arg[0]) == ubyte)`.

Reply via email to