simplify implementation of isDynamicArray() - #11094
Conversation
904d6e0 to
9445418
Compare
|
Even with the compile error fixed, this is not a valid refactor because it changes existing behavior. Example: import std.traits;
struct S
{
int[] a;
alias this = a;
}
// current behavior - prints "false"
pragma(msg, isDynamicArray!S);
// new behavior - prints "true"
static if (is(S U : U[])))
pragma(msg, "true");
else
pragma(msg, "false"); |
9445418 to
f924de6
Compare
I don’t think so. |
f924de6 to
d5b137e
Compare
|
#0xEAB I don't think so, either. Somehow I pushed into the wrong branch. |
|
@pbackus This is why I detest Phobos. isDynamicArray has utterly misleading documentation. There are 4 kinds of dynamic arrays:
and there's no clue in the documentation which of these is supported. And what it does support is completely arbitrary - one has to carefully read the implementation in both Phobos and the compiler source code. The correct way to do "traits" is to define them for basic building blocks, and then the user can & | and ^ to get what he needs. |
|
Yes, And that's what I've been doing with the traits in Phobos v3. Anyone who wants to test for implicit conversions can then do explicitly by But we cannot change the behavior in v2, because who knows how much code relies on the existing behavior, and changing stuff that ends up in conditional compilation such as template constraints and For the most part, we cannot fix anything like this in std.traits, because doing so breaks code. We can potentially change an implementation here and there as long as it results in exactly the same behavior, but we cannot change the existing behavior even if it's bad behavior. |
|
@WalterBright If you want to see how this particular trait was improved in Phobos v3, you can see the current version of it here: https://github.com/dlang/phobos/blob/master/phobos/sys/traits.d#L255 The implementation itself is dead simple, the documentation attempts to be very clear and thorough (though it's pretty long given how much it explains), and it has quite a few examples in the ddoc-ed This is in stark contrast to v2, which has I am by no means claiming that the current v3 stuff is perfect, but I have gone to great lengths to both try to fix the implementation mistakes in v2 and make the documentation as clear as I can make it. |
Rationale
Feature request or issue tracking
Closes #10974.
Pre-review checklist
LLM/AI disclosure
This PR was written with the assistance of an LLM/AI.
This PR was written entirely by an LLM/AI.