joiner: How to iterate over immutable ranges?

Bastiaan Veelo via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Feb 14 07:24:39 PST 2016


Hi,

I am having trouble getting the iteration methods in 
std.algorithm.iteration to work on immutable data:

> import std.algorithm.iteration;
> import std.stdio;
> 
> void main()
> {
> 	string[][] cycles;
> 	cycles ~= ["one", "two"];
> 	cycles ~= ["three", "four"];
> 	foreach (number; cycles.joiner) // This works.
> 		writeln(number);
> 
> 	immutable(string[])[] icycles;
> 	icycles ~= ["one", "two"];
> 	icycles ~= ["three", "four"];
> 	foreach (number; icycles.joiner)  // Should this work?
> 		writeln(number);
> }

The error message is:

/d149/f840.d(15): Error: template std.algorithm.iteration.joiner 
cannot deduce function from argument types 
!()(immutable(string[])[]), candidates are:
/opt/compilers/dmd2/include/std/algorithm/iteration.d(1911):      
   std.algorithm.iteration.joiner(RoR, Separator)(RoR r, Separator 
sep) if (isInputRange!RoR && isInputRange!(ElementType!RoR) && 
isForwardRange!Separator && is(ElementType!Separator : 
ElementType!(ElementType!RoR)))
/opt/compilers/dmd2/include/std/algorithm/iteration.d(2194):      
   std.algorithm.iteration.joiner(RoR)(RoR r) if (isInputRange!RoR 
&& isInputRange!(ElementType!RoR))

I had expected this to work. What did I miss?

Thanks,
Bastiaan.


More information about the Digitalmars-d-learn mailing list