Problem with std.algorithm.iteration::substitute

Jesse Phillips Jesse.K.Phillips+D at gmail.com
Sat Jan 11 19:36:00 UTC 2020


On Saturday, 11 January 2020 at 17:10:02 UTC, Martin Brezl wrote:
> Hi,
>
> i have a function like this:
> ```
> import std.algorithm.iteration : substitute;
> //...
> string replace(string content, string[] searches , string 
> replace) {
> 	
> 	if(searches.empty) return content;
>
> 	auto result = content.substitute(searches.front,replace);
> 	for(size_t i=1; i < searches.length; i++) {
> 		searches.popFront();
> 		result = result.substitute(searches.front,replace);
> 	}
>         //...
>         return "example return";
> }
> ```

The issue is the double assigned result.

auto result = content.substitute(searches.front,replace);
result = result.substitute(searches.front,replace);

`substitute` is going to return a template range typed off 
`content` then it uses that type to perform another substitution.

`content` and `result` don't have the same type.




More information about the Digitalmars-d-learn mailing list