Bug 5061 – std.traits.arrayTarget

Status
RESOLVED
Resolution
WONTFIX
Severity
enhancement
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2010-10-15T21:44:00Z
Last change time
2013-10-26T01:11:57Z
Assigned to
andrei
Creator
mchaten

Comments

Comment #0 by mchaten — 2010-10-15T21:44:45Z
I've been in need of getting the type of the contents of an array. Phobos includes a function to get the type of the pointer target. I propose a simple template, arrayTarget to std.traits to implement this functionality. The following works under DMD 2.049, Linux/x86 template arrayTarget(T:T[]) { alias T arrayTarget; } unittest { assert(is(arrayTarget!(int[5][]) == int[5])); assert(is(arrayTarget!(int[5]) == int)); assert(is(arrayTarget!(int[]) == int)); assert(is(arrayTarget!(int[][]) == int[])); assert(__traits(compiles,arrayTarget!(int)) == false); assert(__traits(compiles,arrayTarget!(int *)) == false); }
Comment #1 by yebblies — 2011-06-15T23:16:49Z
Is this covered by ElementType/EncodingType?
Comment #2 by andrej.mitrovich — 2012-12-18T13:19:11Z
(In reply to comment #1) > Is this covered by ElementType/EncodingType? Yes, except it's more generic and works with pointers too.
Comment #3 by verylonglogin.reg — 2013-02-17T23:30:43Z
Not fixed. The enhancement is about arrays, not ranges. Phobos misses a lot of traits in regard to arrays. This one included.
Comment #4 by yebblies — 2013-02-17T23:49:27Z
Arrays _are_ ranges. This functionality is already in phobos.
Comment #5 by verylonglogin.reg — 2013-02-18T02:42:03Z
(In reply to comment #4) > Arrays _are_ ranges. No. E.g. `int[1]` and `const int[]` are not ranges. > This functionality is already in phobos. `char[]` can be just an array of `char`-s without any thoughts about encoding and combining that `char`-s into a string so neither `ElementType` nor `ElementEncodingType` are applicable.
Comment #6 by andrej.mitrovich — 2013-02-18T09:17:34Z
(In reply to comment #5) > (In reply to comment #4) > > Arrays _are_ ranges. > > No. E.g. `int[1]` and `const int[]` are not ranges. Both ElementType and ElementEncodingType work with these. > `char[]` can be just an array of `char`-s without any thoughts about encoding > and combining that `char`-s into a string so neither `ElementType` nor > `ElementEncodingType` are applicable. I don't understand what you mean. A code example would help.
Comment #7 by verylonglogin.reg — 2013-10-26T01:11:57Z
The fix was in phobos pull 776 [1] which was rejected. Andrei's comment [2]: > I appreciate the arguments in favor of adding an ArrayElementType. However, ElementEncodingType is adequate (albeit unintuitively named) and I couldn't get convinced by the arguments involving precedents. I will close this now. Thanks for the contribution, and let's focus on the more meaty ones. [1] https://github.com/D-Programming-Language/phobos/pull/776 [2] https://github.com/D-Programming-Language/phobos/pull/776#issuecomment-8603386