Thread overview | ||||||
---|---|---|---|---|---|---|
|
June 12, 2018 remove not callable for char[] | ||||
---|---|---|---|---|
| ||||
well, not really, it just cannot auto deduce, the problem is, I don't know what to put in, I know that I can put in SwapStrategy.stable for the first one, but what about the Range, I don't know what to put in E.g int[] i = [ 1, 2 ]; i = i.remove( 1 );//able to automagically deduce char[] c = [ 'a', 'b' ]; c = c.remove( 1 ); //unable to deduce what char[] is in range |
June 12, 2018 Re: remove not callable for char[] | ||||
---|---|---|---|---|
| ||||
Posted in reply to Flaze07 | On 6/12/18 2:33 AM, Flaze07 wrote:
> well, not really, it just cannot auto deduce, the problem is, I don't know what to put in, I know that I can put in SwapStrategy.stable for the first one, but what about the Range, I don't know what to put in
> E.g
> int[] i = [ 1, 2 ];
> i = i.remove( 1 );//able to automagically deduce
>
> char[] c = [ 'a', 'b' ];
> c = c.remove( 1 ); //unable to deduce what char[] is in range
The issue is that char[] is treated as an auto-decoding bi-directional range by Phobos, not an array.
To get Phobos to behave, you can use byCodeUnit:
import std.utf: byCodeUnit;
c = c.byCodeUnit.remove(1).source;
-Steve
|
June 13, 2018 Re: remove not callable for char[] | ||||
---|---|---|---|---|
| ||||
Posted in reply to Steven Schveighoffer | On Tuesday, 12 June 2018 at 14:08:25 UTC, Steven Schveighoffer wrote:
> On 6/12/18 2:33 AM, Flaze07 wrote:
>> well, not really, it just cannot auto deduce, the problem is, I don't know what to put in, I know that I can put in SwapStrategy.stable for the first one, but what about the Range, I don't know what to put in
>> E.g
>> int[] i = [ 1, 2 ];
>> i = i.remove( 1 );//able to automagically deduce
>>
>> char[] c = [ 'a', 'b' ];
>> c = c.remove( 1 ); //unable to deduce what char[] is in range
>
> The issue is that char[] is treated as an auto-decoding bi-directional range by Phobos, not an array.
>
> To get Phobos to behave, you can use byCodeUnit:
>
> import std.utf: byCodeUnit;
>
> c = c.byCodeUnit.remove(1).source;
>
> -Steve
I see, so it means that only char is affected, gotcha
|
June 13, 2018 Re: remove not callable for char[] | ||||
---|---|---|---|---|
| ||||
Posted in reply to Flaze07 | On 6/13/18 1:18 AM, Flaze07 wrote:
> I see, so it means that only char is affected, gotcha
>
Well, char[] and wchar[]. dchar[] is treated as an array by Phobos. But calling byCodeUnit on a dchar array should work just like an array as well, so using it is the most generic solution.
-Steve
|
Copyright © 1999-2021 by the D Language Foundation