Sanity check: pithiest test for static if: "is an array of ubyte"

H. S. Teoh hsteoh at qfbox.info
Sat May 24 21:58:16 UTC 2025


On Sat, May 24, 2025 at 08:29:52PM +0000, Andy Valencia via Digitalmars-d-learn wrote:
> The best I"ve come up with for a "static if" to see if something's an
> array of ubyte:
> 
> ```d
> (isArray!(typeof(arg))) && is(typeof(arg).init[0] == ubyte)
> ```

That's totally overkill.  Just do this:

	T[] myArray;
	static if (is(typeof(myArray) == ubyte[])) {
		...
	}

That's all.  Dead simple, no need to bring out the cannons when a
screwdriver will suffice.


--T


More information about the Digitalmars-d-learn mailing list