Pasted below.
/**
If $(D startsWith(r1, r2)), consume the corresponding elements off $(D
r1) and return $(D true). Otherwise, leave $(D r1) unchanged and
return $(D false).
*/
bool startsWithConsume(alias pred = "a == b", R1, R2)(ref R1 r1, R2 r2)
if (is(typeof(binaryFun!pred(r1.front, r2.front))))
{
auto r = r1; // .save();
while (!r2.empty && !r.empty && binaryFun!pred(r.front, r2.front))
{
r.popFront();
r2.popFront();
}
return r2.empty ? (r1 = r, true) : false;
}
unittest
{
auto s1 = "Hello world";
assert(!startsWithConsume(s1, "Ha"));
assert(s1 == "Hello world");
assert(startsWithConsume(s1, "Hell") && s1 == "o world");
}
Andrei
On 03/16/2010 10:49 AM, Steve Schveighoffer wrote:
You are using some new function "startsWithConsume" that isn't yet in phobos:
untag.d(68): Error: undefined identifier startsWithConsume
untag.d(68): Error: function expected before (), not startsWithConsume of type
int
untag.d(69): Error: undefined identifier startsWithConsume
untag.d(69): Error: function expected before (), not startsWithConsume of type
int
-Steve
----- Original Message ----
From: Andrei Alexandrescu<[email protected]>
To: Steve Schveighoffer<[email protected]>; Walter Bright<[email protected]>; Sean
Kelly<[email protected]>; Discuss the internals of DMD<[email protected]>
Sent: Tue, March 16, 2010 11:29:32 AM
Subject: Re: Rare and pernicious bug in string append
Damn. Sorry.
Andrei
_______________________________________________
dmd-internals mailing list
[email protected]
http://lists.puremagic.com/mailman/listinfo/dmd-internals