<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
<title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
Le 25/11/10 14:03, biozic a écrit :
<blockquote cite="mid:iclmuf$2vjb$1@digitalmars.com" type="cite">Hello.
<br>
This leads to a compilation error:
<br>
<br>
import std.algorithm;
<br>
void main() {
<br>
string foo = "foo";
<br>
immutable string bar = "bar";
<br>
auto f = foo.endsWith("o");
<br>
auto b = bar.endsWith("r"); // ERROR cannot deduce template...
<br>
}
<br>
<br>
Same with startsWith. Is this related to issue #5134? or am I
missing somthing?
<br>
Thanks
<br>
Nicolas
<br>
</blockquote>
Trying to answer to myself:<br>
<br>
This is because std.algorithm.endsWith, startsWith, etc. expect
their first argument to be an InputRange (checked with
isInputRange), and an immutable array cannot be an InputRange
(because of immutability).<br>
<br>
I think several algorithms could either tolerate an Iterable
(checked with std.traits.isIterable) as their first argument or be
specialized for immutable arrays. It is the case of topNCopy for
instance.<br>
<br>
As for <a href="http://d.puremagic.com/issues/show_bug.cgi?id=5134">bug
#5134</a>: since a function argument with the 'in' "storage class"
is const, it cannot be an InputRange, so compilation fails...<br>
<br>
Am I right?<br>
Thanks,<br>
<br>
Nicolas<br>
<br>
</body>
</html>