substitute with predicate won't compile

Bastiaan Veelo Bastiaan at Veelo.net
Tue Oct 28 21:14:42 UTC 2025


On Tuesday, 28 October 2025 at 20:08:41 UTC, H. S. Teoh wrote:
> On Tue, Oct 28, 2025 at 07:43:56PM +0000, Bastiaan Veelo via 
> Digitalmars-d-learn wrote:
>> Why doesn't this compile?
>> 
>> ```d
>> import std;
>> 
>> void main()
>> {
>>     string s;
>>     //...
>>     s = s.substitute!((a, b) => sicmp(a, b) == 0, "&", "&",
>>                                                   "<", "<",
>>                                                   ">", ">",
>>                                                   """, 
>> `"`,
>>                                                   "'", 
>> "'").array;
>> }
>> ```
>
> You have all your arguments as CT arguments; I think 
> .substitute wants the lamdba as a CT argument but the other 
> arguments as RT.
>
> But having said that, after changing the substitution arguments 
> to RT arguments, it still doesn't compile for me for some 
> reason.  So I dunno.
>
>
> T

This seems to be a bug. It does work with runtime arguments, but 
only if the predicate is given as a string:
```d
     s = s.substitute!"a.toLower==b.toLower"("&", "&",
                                             "<", "<",
                                             ">", ">",
                                             """, `"`,
                                             "'", 
"'").to!string;
```

-- Bastiaan.


More information about the Digitalmars-d-learn mailing list