digitalmars.D - slice based on base and width
- =?UTF-8?B?IsOYaXZpbmQi?= (13/13) Sep 08 2013 I find myself writing the following a lot:
- =?UTF-8?B?IsOYaXZpbmQi?= (2/3) Sep 08 2013 I think this should be
- Chang Long (2/6) Sep 08 2013 try &a[base][0..width]
- Simen Kjaeraas (6/14) Sep 08 2013 That throws safety out the window for one. If you want safety and
- =?UTF-8?B?IsOYaXZpbmQi?= (7/23) Sep 08 2013 Thanks
- Walter Bright (3/11) Sep 08 2013 Try it and see. If it isn't, feel free to file an enhancement request fo...
I find myself writing the following a lot: a[base..base+width] to get the slice starting at 'base' of width 'width'. In verilog, we select members of a vector/array in three ways a[c : d] //D: a[c .. d+1] a[c +: d] //D: a[c .. c+d] a[c -: d] //D: a[c-d .. c] Borrowing a bit from verilog, could we make two new operators, maybe +.. and -.. that allow us to do the same? I could then write e.g. a[base+..width] instead of the more verbose a[base..base+width]
Sep 08 2013
a[c -: d] //D: a[c-d .. c]I think this should be a[c -: d] //D: a[c-d+1 .. c+1], e.g. a[5 -: 2] == [a[4], a[5]]
Sep 08 2013
On Sunday, 8 September 2013 at 10:53:23 UTC, Øivind wrote:try &a[base][0..width]a[c -: d] //D: a[c-d .. c]I think this should be a[c -: d] //D: a[c-d+1 .. c+1], e.g. a[5 -: 2] == [a[4], a[5]]
Sep 08 2013
On 2013-09-08, 14:02, Chang Long wrote:On Sunday, 8 September 2013 at 10:53:23 UTC, =C3=98ivind wrote:a[c -: d] //D: a[c-d .. c]I think this should be a[c -: d] //D: a[c-d+1 .. c+1], e.g. a[5 -: 2] =3D=3D [a[4], a[5]]=try &a[base][0..width]That throws safety out the window for one. If you want safety and no new language features, this should work: a[base..$][0..width] -- = Simen
Sep 08 2013
On Sunday, 8 September 2013 at 12:08:50 UTC, Simen Kjaeraas wrote:On 2013-09-08, 14:02, Chang Long wrote:Thanks Still a little verbose, but at least you don't have to type the same things twice. I guess the double slice will be optimized into a single one at least for release mode, so there should be no performance degredation?On Sunday, 8 September 2013 at 10:53:23 UTC, Øivind wrote:That throws safety out the window for one. If you want safety and no new language features, this should work: a[base..$][0..width]try &a[base][0..width]a[c -: d] //D: a[c-d .. c]I think this should be a[c -: d] //D: a[c-d+1 .. c+1], e.g. a[5 -: 2] == [a[4], a[5]]
Sep 08 2013
On 9/8/2013 6:03 AM, "Øivind" wrote:Try it and see. If it isn't, feel free to file an enhancement request for the optimizer!That throws safety out the window for one. If you want safety and no new language features, this should work: a[base..$][0..width]Thanks Still a little verbose, but at least you don't have to type the same things twice. I guess the double slice will be optimized into a single one at least for release mode, so there should be no performance degredation?
Sep 08 2013