Thread overview | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
June 06, 2018 how to sort the container Array from std.container | ||||
---|---|---|---|---|
| ||||
I know that sort accepts Range( I am correct right ? ), so, Array!uint arr; //inserts element to arr sort( arr.Range ); don't work, it says cannot pass RangeT!(Array!uint) as function argument |
June 06, 2018 Re: how to sort the container Array from std.container | ||||
---|---|---|---|---|
| ||||
Posted in reply to Flaze07 | On Wednesday, 6 June 2018 at 13:44:09 UTC, Flaze07 wrote:
> sort( arr.Range );
> don't work, it says cannot pass RangeT!(Array!uint) as function argument
Range is the type, you want the value
I think you can do
sort(arr[])
maybe
|
June 06, 2018 Re: how to sort the container Array from std.container | ||||
---|---|---|---|---|
| ||||
Posted in reply to Adam D. Ruppe | On Wednesday, 6 June 2018 at 13:46:41 UTC, Adam D. Ruppe wrote: > On Wednesday, 6 June 2018 at 13:44:09 UTC, Flaze07 wrote: >> sort( arr.Range ); >> don't work, it says cannot pass RangeT!(Array!uint) as function argument > > Range is the type, you want the value > > I think you can do > > sort(arr[]) > > maybe I see why it works, so, [] is called slice operator right ? and in https://dlang.org/phobos/std_container_array.html#.Array.opSlice it returns range, so that's why it worked |
June 07, 2018 Re: how to sort the container Array from std.container | ||||
---|---|---|---|---|
| ||||
Posted in reply to Flaze07 | On 07/06/2018 1:58 AM, Flaze07 wrote:
> On Wednesday, 6 June 2018 at 13:46:41 UTC, Adam D. Ruppe wrote:
>> On Wednesday, 6 June 2018 at 13:44:09 UTC, Flaze07 wrote:
>>> sort( arr.Range );
>>> don't work, it says cannot pass RangeT!(Array!uint) as function argument
>>
>> Range is the type, you want the value
>>
>> I think you can do
>>
>> sort(arr[])
>>
>> maybe
>
> I see why it works, so, [] is called slice operator right ?
> and in https://dlang.org/phobos/std_container_array.html#.Array.opSlice it returns range, so that's why it worked
Yes.
|
June 06, 2018 Re: how to sort the container Array from std.container | ||||
---|---|---|---|---|
| ||||
Posted in reply to rikki cattermole | On Wednesday, 6 June 2018 at 14:06:54 UTC, rikki cattermole wrote:
> On 07/06/2018 1:58 AM, Flaze07 wrote:
>> On Wednesday, 6 June 2018 at 13:46:41 UTC, Adam D. Ruppe wrote:
>>> On Wednesday, 6 June 2018 at 13:44:09 UTC, Flaze07 wrote:
>>>> sort( arr.Range );
>>>> don't work, it says cannot pass RangeT!(Array!uint) as function argument
>>>
>>> Range is the type, you want the value
>>>
>>> I think you can do
>>>
>>> sort(arr[])
>>>
>>> maybe
>>
>> I see why it works, so, [] is called slice operator right ?
>> and in https://dlang.org/phobos/std_container_array.html#.Array.opSlice it returns range, so that's why it worked
>
> Yes.
hmm, and sorry for asking more, what about removing an element from it ? I found no remove operation that can remove from the middle ( removeAny and removeBack both removes the latest element, linearRemove receive Array!uint...which don't know how to provide )
|
June 07, 2018 Re: how to sort the container Array from std.container | ||||
---|---|---|---|---|
| ||||
Posted in reply to Flaze07 | On 07/06/2018 2:20 AM, Flaze07 wrote:
> On Wednesday, 6 June 2018 at 14:06:54 UTC, rikki cattermole wrote:
>> On 07/06/2018 1:58 AM, Flaze07 wrote:
>>> On Wednesday, 6 June 2018 at 13:46:41 UTC, Adam D. Ruppe wrote:
>>>> On Wednesday, 6 June 2018 at 13:44:09 UTC, Flaze07 wrote:
>>>>> sort( arr.Range );
>>>>> don't work, it says cannot pass RangeT!(Array!uint) as function argument
>>>>
>>>> Range is the type, you want the value
>>>>
>>>> I think you can do
>>>>
>>>> sort(arr[])
>>>>
>>>> maybe
>>>
>>> I see why it works, so, [] is called slice operator right ?
>>> and in https://dlang.org/phobos/std_container_array.html#.Array.opSlice it returns range, so that's why it worked
>>
>> Yes.
>
> hmm, and sorry for asking more, what about removing an element from it ? I found no remove operation that can remove from the middle ( removeAny and removeBack both removes the latest element, linearRemove receive Array!uint...which don't know how to provide )
filter will remove any and all occurrences of whatever you tell it to. But only in the range not the origin data structure.
|
June 06, 2018 Re: how to sort the container Array from std.container | ||||
---|---|---|---|---|
| ||||
Posted in reply to rikki cattermole | On Wednesday, 6 June 2018 at 14:24:15 UTC, rikki cattermole wrote:
> On 07/06/2018 2:20 AM, Flaze07 wrote:
>> On Wednesday, 6 June 2018 at 14:06:54 UTC, rikki cattermole wrote:
>>> On 07/06/2018 1:58 AM, Flaze07 wrote:
>>>> [...]
>>>
>>> Yes.
>>
>> hmm, and sorry for asking more, what about removing an element from it ? I found no remove operation that can remove from the middle ( removeAny and removeBack both removes the latest element, linearRemove receive Array!uint...which don't know how to provide )
>
> filter will remove any and all occurrences of whatever you tell it to. But only in the range not the origin data structure.
what about removing certain index ?
|
June 07, 2018 Re: how to sort the container Array from std.container | ||||
---|---|---|---|---|
| ||||
Posted in reply to Flaze07 | On 07/06/2018 2:27 AM, Flaze07 wrote:
> On Wednesday, 6 June 2018 at 14:24:15 UTC, rikki cattermole wrote:
>> On 07/06/2018 2:20 AM, Flaze07 wrote:
>>> On Wednesday, 6 June 2018 at 14:06:54 UTC, rikki cattermole wrote:
>>>> On 07/06/2018 1:58 AM, Flaze07 wrote:
>>>>> [...]
>>>>
>>>> Yes.
>>>
>>> hmm, and sorry for asking more, what about removing an element from it ? I found no remove operation that can remove from the middle ( removeAny and removeBack both removes the latest element, linearRemove receive Array!uint...which don't know how to provide )
>>
>> filter will remove any and all occurrences of whatever you tell it to. But only in the range not the origin data structure.
>
> what about removing certain index ?
Indexes and ranges don't usually go together.
|
June 06, 2018 Re: how to sort the container Array from std.container | ||||
---|---|---|---|---|
| ||||
Posted in reply to rikki cattermole | On Wednesday, 6 June 2018 at 14:29:28 UTC, rikki cattermole wrote:
> On 07/06/2018 2:27 AM, Flaze07 wrote:
>> On Wednesday, 6 June 2018 at 14:24:15 UTC, rikki cattermole wrote:
>>> On 07/06/2018 2:20 AM, Flaze07 wrote:
>>>> On Wednesday, 6 June 2018 at 14:06:54 UTC, rikki cattermole wrote:
>>>>> [...]
>>>>
>>>> hmm, and sorry for asking more, what about removing an element from it ? I found no remove operation that can remove from the middle ( removeAny and removeBack both removes the latest element, linearRemove receive Array!uint...which don't know how to provide )
>>>
>>> filter will remove any and all occurrences of whatever you tell it to. But only in the range not the origin data structure.
>>
>> what about removing certain index ?
>
> Indexes and ranges don't usually go together.
welp, ok then, thank you
|
June 06, 2018 Re: how to sort the container Array from std.container | ||||
---|---|---|---|---|
| ||||
Posted in reply to Flaze07 | On 6/6/18 10:20 AM, Flaze07 wrote:
> On Wednesday, 6 June 2018 at 14:06:54 UTC, rikki cattermole wrote:
>> On 07/06/2018 1:58 AM, Flaze07 wrote:
>>> On Wednesday, 6 June 2018 at 13:46:41 UTC, Adam D. Ruppe wrote:
>>>> On Wednesday, 6 June 2018 at 13:44:09 UTC, Flaze07 wrote:
>>>>> sort( arr.Range );
>>>>> don't work, it says cannot pass RangeT!(Array!uint) as function argument
>>>>
>>>> Range is the type, you want the value
>>>>
>>>> I think you can do
>>>>
>>>> sort(arr[])
>>>>
>>>> maybe
>>>
>>> I see why it works, so, [] is called slice operator right ?
>>> and in https://dlang.org/phobos/std_container_array.html#.Array.opSlice it returns range, so that's why it worked
>>
>> Yes.
>
> hmm, and sorry for asking more, what about removing an element from it ? I found no remove operation that can remove from the middle ( removeAny and removeBack both removes the latest element, linearRemove receive Array!uint...which don't know how to provide )
To remove element 5, for example:
arr.linearRemove(arr[5 .. 6]);
-Steve
|
Copyright © 1999-2021 by the D Language Foundation