endsWith - for a string vs an array of strings

Laeeth Isharc via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Jan 10 12:26:16 PST 2015


I understand from previous discussion there is some difficulty 
over immutability.  I did not quite figure out what the solution 
was in this case:

import std.array;
import std.string;
import std.stdio;
void main(string[] args)
{
	string[] test=["1","two","three!"];
	auto a="arghtwo".endsWith(test);
	writefln("%s",a);
}

This does not compile...

test.d(7): Error: template std.algorithm.endsWith cannot deduce 
function from argument types !()(string, string[]), candidates 
are:
/usr/include/dmd/phobos/std/algorithm.d(6143):        
std.algorithm.endsWith(alias pred = "a == b", Range, 
Needles...)(Range doesThisEnd, Needles withOneOfThese) if 
(isBidirectionalRange!Range && Needles.length > 1 && 
is(typeof(.endsWith!pred(doesThisEnd, withOneOfThese[0])) : bool) 
&& is(typeof(.endsWith!pred(doesThisEnd, 
withOneOfThese[1..__dollar])) : uint))
/usr/include/dmd/phobos/std/algorithm.d(6210):        
std.algorithm.endsWith(alias pred = "a == b", R1, R2)(R1 
doesThisEnd, R2 withThis) if (isBidirectionalRange!R1 && 
isBidirectionalRange!R2 && 
is(typeof(binaryFun!pred(doesThisEnd.back, withThis.back)) : 
bool))
/usr/include/dmd/phobos/std/algorithm.d(6237):        
std.algorithm.endsWith(alias pred = "a == b", R, E)(R 
doesThisEnd, E withThis) if (isBidirectionalRange!R && 
is(typeof(binaryFun!pred(doesThisEnd.back, withThis)) : bool))


Thanks.


Laeeth.


More information about the Digitalmars-d-learn mailing list