May 01, 2020
On Friday, 1 May 2020 at 15:17:53 UTC, drug wrote:
> 01.05.2020 18:04, notna пишет:
>> 
>> hmmm, whích results in:
>>   Error: cannot use [] operator on expression of type dchar
>> 
>
> try this:
> ```D
> import std;
> void main()
> {
>     string word = "Привет";
>     dchar[] line3 = to!(dchar[])(word.dup) // make a copy to get a range of mutable char
>                                            // and convert char to dchar
>         .sort                              // sort it
>         .release;                          // get the sorted range
>     assert(line3 == "Пвеирт");
> }
> ```

THANKS, this looks even cleaner :)
May 01, 2020
On 5/1/20 11:17 AM, drug wrote:
> 01.05.2020 18:04, notna пишет:
>>
>> hmmm, whích results in:
>>   Error: cannot use [] operator on expression of type dchar
>>
> 
> try this:
> ```D
> import std;
> void main()
> {
>      string word = "Привет";
>      dchar[] line3 = to!(dchar[])(word.dup) // make a copy to get a range of mutable char
>                                             // and convert char to dchar
>          .sort                              // sort it
>          .release;                          // get the sorted range
>      assert(line3 == "Пвеирт");
> }
> ```

Nice! Yeah, I was sloppy in my newsgroup coding, sorry.

One minor nit here, the to!(dchar[])(word.dup), the dup is not necessary, you are going to end up allocating a temporary array and throwing it away.

Just do word.to!(dchar[]). `to` takes care of all the formalities.

-Steve
May 02, 2020
On Friday, 1 May 2020 at 19:25:43 UTC, Steven Schveighoffer wrote:
>
> Nice! Yeah, I was sloppy in my newsgroup coding, sorry.
>
> One minor nit here, the to!(dchar[])(word.dup), the dup is not necessary, you are going to end up allocating a temporary array and throwing it away.
>
> Just do word.to!(dchar[]). `to` takes care of all the formalities.
>
> -Steve

THANK YOU for all the great hints and explanations here and in general in this NG, Steve!

No blaming for the "sloopy code" at all. I should have seen the missing [] by myself, but...

_AND_ btw. your hint with the "release" was key to the discussion / solution anyhow! :)
1 2
Next ›   Last »