On Thursday, 22 February 2018 at 02:41:30 UTC, Steven
Schveighoffer wrote:
Hah! I never thought of doing a slice with negative indexes ;)
Maybe is my past of python:
arr[-3:] to get the last 3 elements for eg.
:)
On 22.02.2018 01:26, Adam D. Ruppe wrote:
On Thursday, 22 February 2018 at 00:13:43 UTC, SrMordred wrote:
string x = "123";
auto c = x.ptr;
c++;
writeln(c[-1]); // 1
That's only happening because pointers bypass range checks.
writeln(c[-1..0]); //BOOM Range violation
But with a slice
On Thursday, 22 February 2018 at 02:41:30 UTC, Steven
Schveighoffer wrote:
On 2/21/18 7:30 PM, SrMordred wrote:
But with a slice negative indexes are never allowed, even on
a pointer.
youd have to do
(c-1)[0 .. 1];
Nice!
Thank you both!
In D Slice article it says "You can even use
On 2/21/18 7:30 PM, SrMordred wrote:
But with a slice negative indexes are never allowed, even on a pointer.
youd have to do
(c-1)[0 .. 1];
Nice!
Thank you both!
In D Slice article it says "You can even use negative indexes!" so I
thought
that the [-1..x] should work too :)
Hah! I
But with a slice negative indexes are never allowed, even on a
pointer.
youd have to do
(c-1)[0 .. 1];
Nice!
Thank you both!
In D Slice article it says "You can even use negative indexes!"
so I thought
that the [-1..x] should work too :)
On Thursday, 22 February 2018 at 00:13:43 UTC, SrMordred wrote:
string x = "123";
auto c = x.ptr;
c++;
writeln(c[-1]); // 1
That's only happening because pointers bypass range checks.
writeln(c[-1..0]); //BOOM Range violation
But with a slice negative indexes are never allowed, even on a
On Thursday, 22 February 2018 at 00:13:43 UTC, SrMordred wrote:
string x = "123";
auto c = x.ptr;
c++;
writeln(c[-1]); // 1
writeln(c[-1..0]); //BOOM Range violation
Can I do this / Bug / some mistake ?
youd have to do
(c-1)[0 .. 1];
string x = "123";
auto c = x.ptr;
c++;
writeln(c[-1]); // 1
writeln(c[-1..0]); //BOOM Range violation
Can I do this / Bug / some mistake ?