Re: Deleting an element from an array

2009-02-21 Thread Sergey Gromov
Tue, 3 Feb 2009 18:11:35 +0100, nobody wrote: > "Jarrett Billingsley" wrote in message > news:mailman.637.1233680615.22690.digitalmars-d-le...@puremagic.com... >> On Tue, Feb 3, 2009 at 11:51 AM, nobody wrote: >>> Would you also happen to know why the following gives an error? >>> >>> arr[1] =

Re: Deleting an element from an array

2009-02-04 Thread Saaa
Please tell me when I got something wrong : ) >>> >>> arr = arr[ 0 .. lowerBound ] ~ arr[ upperBound .. $ ]; >>> >> >> That's simple enough, but inefficient. Because it loops over arr.length-2 and copies the pointers. Will the compiler optimize by not copying the [0..lowerbound] part? And will the

Re: Deleting an element from an array

2009-02-03 Thread nobody
"Jarrett Billingsley" wrote in message news:mailman.637.1233680615.22690.digitalmars-d-le...@puremagic.com... > On Tue, Feb 3, 2009 at 11:51 AM, nobody wrote: >> Would you also happen to know why the following gives an error? >> >> arr[1] = arr[$-1];// main.d(11): Error: cannot assign to s

Re: Deleting an element from an array

2009-02-03 Thread Jarrett Billingsley
On Tue, Feb 3, 2009 at 11:51 AM, nobody wrote: > Would you also happen to know why the following gives an error? > > arr[1] = arr[$-1];// main.d(11): Error: cannot assign to static array arr[1][] = arr[$-1][]; You cannot reassign what fixed-size array references point to, but you can copy t

Re: Deleting an element from an array

2009-02-03 Thread nobody
"Jarrett Billingsley" wrote in message news:mailman.636.1233678501.22690.digitalmars-d-le...@puremagic.com... > On Tue, Feb 3, 2009 at 10:54 AM, nobody wrote: >> Let's see if I understand memmove.. >> The way it's used here, it copies the tail of an array onto that same >> array, >> only start

Re: Deleting an element from an array

2009-02-03 Thread Jarrett Billingsley
On Tue, Feb 3, 2009 at 10:54 AM, nobody wrote: > Let's see if I understand memmove.. > The way it's used here, it copies the tail of an array onto that same array, > only starting one index earlier, thus removing the undesired element? > Neat. Right. > However I just realized that order does not

Re: Deleting an element from an array

2009-02-03 Thread nobody
"Jarrett Billingsley" wrote in message news:mailman.635.1233675301.22690.digitalmars-d-le...@puremagic.com... > On Tue, Feb 3, 2009 at 10:14 AM, Frank Benoit > wrote: >> >> arr = arr[ 0 .. lowerBound ] ~ arr[ upperBound .. $ ]; >> > > That's simple enough, but inefficient. > > Something like th

Re: Deleting an element from an array

2009-02-03 Thread Steven Schveighoffer
"Frank Benoit" wrote > nobody schrieb: >> "Denis Koroskin" <2kor...@gmail.com> wrote in message >> news:op.uor1gzqho7c...@korden-pc... >>> On Tue, 03 Feb 2009 15:46:52 +0300, nobody >>> wrote: >>> What is the best way to completely remove an element from an array? For example you h

Re: Deleting an element from an array

2009-02-03 Thread nobody
"Frank Benoit" wrote in message news:gm9n0e$314...@digitalmars.com... > nobody schrieb: >> "Denis Koroskin" <2kor...@gmail.com> wrote in message >> news:op.uor1gzqho7c...@korden-pc... >>> On Tue, 03 Feb 2009 15:46:52 +0300, nobody >>> wrote: >>> What is the best way to completely remove a

Re: Deleting an element from an array

2009-02-03 Thread Jarrett Billingsley
On Tue, Feb 3, 2009 at 10:14 AM, Frank Benoit wrote: > > arr = arr[ 0 .. lowerBound ] ~ arr[ upperBound .. $ ]; > That's simple enough, but inefficient. Something like this: import std.c.string; // or import tango.stdc.string; T[] erase(T)(ref T[] arr, size_t idx) { if(arr.length == 0)

Re: Deleting an element from an array

2009-02-03 Thread Frank Benoit
nobody schrieb: > "Denis Koroskin" <2kor...@gmail.com> wrote in message > news:op.uor1gzqho7c...@korden-pc... >> On Tue, 03 Feb 2009 15:46:52 +0300, nobody wrote: >> >>> What is the best way to completely remove an element from an array? >>> >>> For example you have an array: >>> [1,2,3,4,5,6] >>

Re: Deleting an element from an array

2009-02-03 Thread nobody
"Denis Koroskin" <2kor...@gmail.com> wrote in message news:op.uor1gzqho7c...@korden-pc... > On Tue, 03 Feb 2009 15:46:52 +0300, nobody wrote: > >> What is the best way to completely remove an element from an array? >> >> For example you have an array: >> [1,2,3,4,5,6] >> and want to remove eleme

Re: Deleting an element from an array

2009-02-03 Thread Denis Koroskin
On Tue, 03 Feb 2009 15:46:52 +0300, nobody wrote: What is the best way to completely remove an element from an array? For example you have an array: [1,2,3,4,5,6] and want to remove element "3" in such a way that the resulting array is: [1,2,4,5,6] Thanks. import std.array; auto arr = [0

Deleting an element from an array

2009-02-03 Thread nobody
What is the best way to completely remove an element from an array? For example you have an array: [1,2,3,4,5,6] and want to remove element "3" in such a way that the resulting array is: [1,2,4,5,6] Thanks.