Le 25/11/10 14:03, biozic a écrit :
Hello.
This leads to a compilation error:

import std.algorithm;
void main() {
    string foo = "foo";
    immutable string bar = "bar";
    auto f = foo.endsWith("o");
    auto b = bar.endsWith("r"); // ERROR cannot deduce template...
}

Same with startsWith. Is this related to issue #5134? or am I missing somthing?
Thanks
Nicolas
Trying to answer to myself:

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).

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.

As for bug #5134: since a function argument with the 'in' "storage class" is const, it cannot be an InputRange, so compilation fails...

Am I right?
Thanks,

Nicolas

Reply via email to