www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 9711] New: extend IFTI to deduce static array length

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

           Summary: extend IFTI to deduce static array length
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: timon.gehr gmx.ch


--- Comment #0 from timon.gehr gmx.ch 2013-03-13 15:08:02 PDT ---
IFTI can deduce both the value and key types for associative arrays:

auto deduceKeyAndVal(T,S)(T[S] a){ return a; }
static assert(is(typeof(deduceKeyAndVal(["1":1,"2":2,"3":3]))==int[string]));


It would be nice if it could also deduce static array lengths:

auto deduceLength(T,size_t n)(T[n] a){ return a; }
static assert(is(typeof(deduceLength([1,2,3]))==int[3]));

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


Zhenya Chapovsky <zheny list.ru> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |zheny list.ru


--- Comment #1 from Zhenya Chapovsky <zheny list.ru> 2013-03-13 15:16:45 PDT ---
[1,2,3] seems is dynamic allocated array,so typeof([1,2,3]) == int[]

but

auto deduceLength(T,size_t n)(T[n] a){ return a; }
enum int[3] a = [1,2,3];
static assert(is(typeof(deduceLength(a))==int[3])); // pass

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


timon.gehr gmx.ch changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |DUPLICATE


--- Comment #2 from timon.gehr gmx.ch 2013-03-13 15:25:17 PDT ---
[1,2,3] is supposed to be a polysemous array literal. I mis-guessed the cause
of this, merging into issue 9712.

*** This issue has been marked as a duplicate of issue 9712 ***

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 13 2013