www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 5061] New: std.traits.arrayTarget

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5061

           Summary: std.traits.arrayTarget
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: Phobos
        AssignedTo: nobody puremagic.com
        ReportedBy: mchaten gmail.com



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);
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 15 2010
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5061


Andrei Alexandrescu <andrei metalanguage.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
                 CC|                            |andrei metalanguage.com
         AssignedTo|nobody puremagic.com        |andrei metalanguage.com


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 09 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5061


yebblies <yebblies gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |yebblies gmail.com



Is this covered by ElementType/EncodingType?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 15 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5061


Andrej Mitrovic <andrej.mitrovich gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
                 CC|                            |andrej.mitrovich gmail.com
         Resolution|                            |FIXED



13:19:11 PST ---

 Is this covered by ElementType/EncodingType?
Yes, except it's more generic and works with pointers too. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Dec 18 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5061


Denis Shelomovskij <verylonglogin.reg gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
                 CC|                            |verylonglogin.reg gmail.com
         Resolution|FIXED                       |



10:30:43 MSK ---
Not fixed.
The enhancement is about arrays, not ranges. Phobos misses a lot of traits in
regard to arrays. This one included.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 17 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5061


yebblies <yebblies gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|REOPENED                    |RESOLVED
         Resolution|                            |FIXED



Arrays _are_ ranges.  This functionality is already in phobos.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 17 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5061




13:42:03 MSK ---

 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. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Feb 18 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5061




09:17:34 PST ---


 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. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Feb 18 2013
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5061


Denis Shelomovskij <verylonglogin.reg gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|FIXED                       |WONTFIX



12:11:57 MSD ---
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 -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Oct 26 2013