Re: Remove array element within function

2021-07-05 Thread Ali Çehreli via Digitalmars-d-learn
On 7/5/21 8:14 AM, Rekel wrote: > On Monday, 5 July 2021 at 14:22:24 UTC, jfondren wrote: >> What use of long? >> >> remove returns the same type of range as it gets: > > My apology, I meant to say countUntil instead of remove in that context. countUntil says it returns ptrdiff_t, which is the

Re: Remove array element within function

2021-07-05 Thread Rekel via Digitalmars-d-learn
Oh my, thank you both, that mostly cleared up my confusion, I had no clue this was struct related. I'll be reading the references you gave me & probably submitting an issue 

Re: Remove array element within function

2021-07-05 Thread Rekel via Digitalmars-d-learn
On Monday, 5 July 2021 at 14:22:24 UTC, jfondren wrote: What use of long? remove returns the same type of range as it gets: My apology, I meant to say countUntil instead of remove in that context.

Re: Remove array element within function

2021-07-05 Thread Mike Parker via Digitalmars-d-learn
On Monday, 5 July 2021 at 14:30:11 UTC, Mike Parker wrote: You never copy the contents of a dynamic array/slice. That only comes into play with static arrays: I should rephrase that. You aren't going to copy the contents of an array/slice just by passing it to a function.

Re: Remove array element within function

2021-07-05 Thread Mike Parker via Digitalmars-d-learn
On Monday, 5 July 2021 at 13:34:50 UTC, Rekel wrote: Ah, ref, thanks, I didn't know if that would work as I was confused since arrays themselves are kind of already pointers. Except they're not :-) Think of them as struct instances with length and pointer fields. That's actually what they

Re: Remove array element within function

2021-07-05 Thread Mike Parker via Digitalmars-d-learn
On Monday, 5 July 2021 at 13:41:59 UTC, Rekel wrote: I'm not sure if this is the place to talk about it, but on the same topic it's a little strange to me neither the Dlang Tour nor the arrays spec page mention removing elements. Even though basically everyone is going to use it sooner or

Re: Remove array element within function

2021-07-05 Thread jfondren via Digitalmars-d-learn
On Monday, 5 July 2021 at 13:10:55 UTC, Rekel wrote: Am I the only one slightly unamused by how arrays/ranges work? They keep backfiring on me, or require weird additions other languages wouldn't require such as manually changing .length, or worrying about what operation returns a copy etc.

Re: Remove array element within function

2021-07-05 Thread Rekel via Digitalmars-d-learn
I'm not sure if this is the place to talk about it, but on the same topic it's a little strange to me neither the Dlang Tour nor the arrays spec page mention removing elements. Even though basically everyone is going to use it sooner or later (most likely sooner). Is that because it's part

Re: Remove array element within function

2021-07-05 Thread Rekel via Digitalmars-d-learn
Ah, ref, thanks, I didn't know if that would work as I was confused since arrays themselves are kind of already pointers. On Monday, 5 July 2021 at 13:18:55 UTC, Mike Parker wrote: In what situations do you need to manually change the length? Where do you worry about copies? It's possible

Re: Remove array element within function

2021-07-05 Thread Mike Parker via Digitalmars-d-learn
On Monday, 5 July 2021 at 13:10:55 UTC, Rekel wrote: Am I the only one slightly unamused by how arrays/ranges work? They keep backfiring on me, or require weird additions other languages wouldn't require such as manually changing .length, or worrying about what operation returns a copy etc.

Re: Remove array element within function

2021-07-05 Thread Mike Parker via Digitalmars-d-learn
On Monday, 5 July 2021 at 13:10:55 UTC, Rekel wrote: But what do you do when you have?: ```d void function(int[] a){ . . . long index = countUntil(a, element); a.remove(index); } ``` ```d void function(ref int[] a) { ... } ``` An array is effectively a length/pointer

Remove array element within function

2021-07-05 Thread Rekel via Digitalmars-d-learn
Is there an easy way to remove elements from an array passed in as a parameter? Every example I find does something along the lines of: ```d int[] a = ... long index = countUntil(a, element); a = a.remove(index); But what do you do when you have?: ```d void function(int[] a){ . . .