Bug 9835 – DynamicArrayTypeOf and isDynamicArray work inconsistently
Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-03-30T06:48:00Z
Last change time
2013-03-30T07:13:59Z
Assigned to
nobody
Creator
tobias
Comments
Comment #0 by tobias — 2013-03-30T06:48:11Z
---
struct Wrapper {
int[] data;
alias data this;
};
pragma(msg, DynamicArrayTypeOf!Wrapper) // int[]
pragma(msg, isDynamicArray!Wrapper) // false
---
There are two issues here: The first one is that DynamicArrayTypeOf and isDynamicArray should work consistently that is, isDynamicArray!T should be true if and only if DynamicArrayTypeOf!T yields a type.
Second according to TDPL alias this makes Wrapper a subtype of int[] and isDynamicArray!Wrapper should be true or otherwise isDynamicArray is quite useless as a template constraint like in std.array.popFront.
Comment #1 by k.hara.pg — 2013-03-30T07:12:21Z
Current behavior is completely intended, so it's not a bug.
In old days, I thought that std.traits.isSomething should consider alias this types. That was necessary for std.format and std.conv implementation. For the purpose I added std.traits.SomethingTypeOf, and used them as the implementation of isSomething.
https://github.com/D-Programming-Language/phobos/pull/488
But, the change of isSomething's behavior had been complained as a bug by some peoples. They said "isDymanicArray!T should be true if and only if T is actually a dynamic array type. If T is a struct with alias this, it should return false".
I finally agreed with that and reverted the behavior.
https://github.com/D-Programming-Language/phobos/pull/976
Now, std.format and std.conv uses is(SomethingTypeOf!T).
Furthermore, SomethingTypeOf is now *undocumented* templates, so their specifications are "as-is". (But considering "alias this" type is sometimes useful, so they are not marked wit "package".)
If you really need SomethingTypeOf, please open an enhancement that they should be *documented*.
Comment #2 by k.hara.pg — 2013-03-30T07:13:59Z
I think that both isSomething and SomethingTypeOf should not be changed.