Conversation
DMD perf checkNo differences above the noise thresholds. All measurements
0677c27 vs merge-base 278dce2 · 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 the convenience of builtin traits by somehow making them referreable to as identifiers and passable as alias parameters like how traits in |
|
DAutoTest failure seems like an unrelated timeout to me. |
I guess it doesn't like that your changelog file starts with an empty line. |
601e313 to
12c5b4c
Compare
| assert(__traits(isDynamicArray, S) == false); | ||
| assert(__traits(isDynamicArray, C) == false); | ||
| assert(__traits(isDynamicArray, E) == false); | ||
| assert(__traits(isDynamicArray, void*) == false); |
There was a problem hiding this comment.
A missing interesting case is an enum with slice basetype (e.g., enum E : string) - where the implementation currently yields true AFAICT.
Edit: Ah, I've missed the discussion above. Anyway, that edge case definitely deserves a test case.
There was a problem hiding this comment.
Shall I include a test case for
enum ES2 : char[2] { a = "aa", b = "bb", c = "cc" }
assert(__traits(isStaticArray, ES2) == true);?
12c5b4c to
41d1a74
Compare
41d1a74 to
107e9da
Compare
Added. |
107e9da to
52ebb92
Compare
52ebb92 to
0677c27
Compare
|
Anything else? If not, ready for merge. |
|
Perhaps a quick check from @LightBender and @WalterBright since their DConf conversation sparked the issue. |
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.