digitalmars.D.learn - How to copy a const multi-dimensional array to mutable?
- ixid (14/14) Sep 15 2012 This doesn't work:
- =?UTF-8?B?QWxpIMOHZWhyZWxp?= (6/19) Sep 15 2012 This feels like a limitation to me too. The following workaround works:
This doesn't work: const int[4][4] a = [[10,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0]]; int[4][4] b = a.dup; Error: cannot implicitly convert expression (_adDupT(& D15TypeInfo_xG4G4i6__initZ,cast(const(int[4u])[])a)) of type int[4u][] to int[] And with dynamic arrays: Error: cannot implicitly convert expression (_adDupT(& D13TypeInfo_xAAi6__initZ,a)) of type const(int)[][] to int[][] This does: const int[4] c = [10,0,0,0]; int[4] d = c.dup; Shouldn't dup do the former as well and if not how should it be done?
Sep 15 2012
On 09/15/2012 09:47 PM, ixid wrote:This doesn't work: const int[4][4] a = [[10,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0]]; int[4][4] b = a.dup; Error: cannot implicitly convert expression (_adDupT(& D15TypeInfo_xG4G4i6__initZ,cast(const(int[4u])[])a)) of type int[4u][] to int[] And with dynamic arrays: Error: cannot implicitly convert expression (_adDupT(& D13TypeInfo_xAAi6__initZ,a)) of type const(int)[][] to int[][] This does: const int[4] c = [10,0,0,0]; int[4] d = c.dup; Shouldn't dup do the former as well and if not how should it be done?This feels like a limitation to me too. The following workaround works: const int[4][4] a = [[10,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0]]; int[4][4] b; b = a; Ali
Sep 15 2012