Add __traits isDynamicArray - #23803
Conversation
DMD perf check
All measurements
601e313 vs merge-base 86b74e2 · about these metrics |
|
|
|
What's the rationale for isArray and why is an Associative Array not one? |
|
From the issue
This PR's implementation accepts enums |
Good point. I agree that isArray should be true for AAs. Update: I removed isArray from this PR. |
Shouldn't we mimic the behavior And then later disallow all traits of this kind to not accept enums? For the sake of consistency. I'm ok with both alternatives. |
That's not what I meant, I don't see why it needs to exist in the first place. What's the real world use case? |
I don't know. |
19d5ca5 to
4c2c3be
Compare
|
|
Removed |
4c2c3be to
364eec9
Compare
| @@ -0,0 +1,3 @@ | |||
| Add a new unary builtin trait `isDynamicArray` that evalutes to true | |||
| iff its single type argument is a D (fat-pointer) array (slice) of any | |||
| type. No newline at end of file | |||
There was a problem hiding this comment.
newline at end of file missing
364eec9 to
601e313
Compare
|
Can't we do this with an |
Yes, as seen in template isDynamicArray(T)
{
static if (is(T == U[], U))
enum bool isDynamicArray = true;
else static if (is(T U == enum))
// BUG: isDynamicArray / isStaticArray considers enums
// with appropriate base types as dynamic/static arrays
// Retain old behaviour for now, see
// https://github.com/dlang/phobos/pull/7574
enum bool isDynamicArray = isDynamicArray!U;
else
enum bool isDynamicArray = false;
}So this addition is for conformity with the existing builtin traits The behavior of supporting enums for all the builtin traits Note, that long-term I would like increase convenience of builtin traits by somehow making them referreable to as identifiers and passable as alias parameters. |
Partially resolves #23784.
I can split the PR up into two if requested.Changelog will be updated if this gets approved.
Looking into failing tests.