[Issue 1064] New: Compile time array literal from a tuple

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Mar 15 12:37:05 PDT 2007


http://d.puremagic.com/issues/show_bug.cgi?id=1064

           Summary: Compile time array literal from a tuple
           Product: D
           Version: 1.009
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla at digitalmars.com
        ReportedBy: jmjmak at utu.fi


template T(E...) { alias E T; }

// Error: cannot implicitly convert expression (tuple(1,2))
// of type (int, int) to int
//int[] a = [ T!(1,2) ];

// Error: cannot implicitly convert expression (tuple(1))
// of type (int) to int
//int[] a = [ T!(1) ];

struct S {
  // Error: cannot implicitly convert expression (tuple(1,2))
  // of type (int, int) to int
  //static int[] a = [ T!(1,2) ];

  // works
  static int[] a = [ 1,2 ];
}

// works
int[] a = [ 1,2 ];

void main() {
  // works
  int[] a = [ T!(1,2) ];

  // works
  int[] b = [ T!(1) ];

  // Error: cannot implicitly convert expression ([1,2])
  // of type int[2] to int
  //auto c = [ T!(1,2) ];

  // Error: tuple index 1 exceeds 1
  // Error: cannot implicitly convert expression ([1])
  // of type int[1] to int
  //auto d = [ T!(1) ];
}

I suppose they all should work. It's possible to do (on the global scope)

//int[] a = [ T!(1,2)[0], T!(1,2)[1] ];

but an arbitrary length tuple does not compile.


-- 



More information about the Digitalmars-d-bugs mailing list