D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 9711 - extend IFTI to deduce static array length
Summary: extend IFTI to deduce static array length
Status: RESOLVED DUPLICATE of issue 9712
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P2 enhancement
Assignee: No Owner
URL:
Keywords:
Depends on: 9712
Blocks:
  Show dependency treegraph
 
Reported: 2013-03-13 15:08 UTC by timon.gehr
Modified: 2013-03-13 15:25 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description timon.gehr 2013-03-13 15:08:02 UTC
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]));
Comment 1 Zhenya Chapovsky 2013-03-13 15:16:45 UTC
[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
Comment 2 timon.gehr 2013-03-13 15:25:17 UTC
[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 ***