toLower

Joel joelcnz at gmail.com
Thu Aug 17 19:39:33 UTC 2023


On Thursday, 17 August 2023 at 14:14:00 UTC, bachmeier wrote:
> On Thursday, 17 August 2023 at 09:28:05 UTC, Joel wrote:
>
>> I get an compile time error with sort after using toLower, 
>> putting in array before sort, didn’t work:
>>
>>     ```d
>>     void main() {
>>         Import std;
>>
>>         "EzraTezla"
>>             .to!(char[])
>>             .byCodeUnit
>>             .map!(std.uni.toLower)
>>             .sort!"a<b"
>>             .writeln;
>>     }
>>     ```
>
> It works for me. Modifying your code to
>
> ```
> void main() {
>     import std;
>
>     "EzraTezla"
>         .to!(char[])
>         .byCodeUnit
>         .map!(std.uni.toLower)
>         .array
>         .sort!"a<b"
>         .writeln;
> }
> ```
>
> compiles and gives the expected output. 
> https://run.dlang.io/is/85VjiL

```d
void main() {
     import std;

     "EzraTezla"
         .to!(char[])
         .byCodeUnit
         .map!(std.ascii.toLower)
         .array
         .sort!"a<b"
         .writeln;
}
```

std.uni.toLower works, but not ascii. Ascii works with bycode 
after map, though.

/Library/D/dmd/src/phobos/std/algorithm/sorting.d(1936): Error: 
static assert:  "When using SwapStrategy.unstable, the passed 
Range 'char[]' must either fulfill hasSwappableElements, or 
hasAssignableElements, both were not the case"
once.d(9):        instantiated from here: `sort!("a<b", 
SwapStrategy.unstable, char[])`



More information about the Digitalmars-d-learn mailing list