static array is no range?
Sebastiaan Koppe via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sat Sep 5 04:12:16 PDT 2015
```
import std.algorithm;
char[1024] buffer;
buffer.find("LOCATION: "); // get error about how all the
different versions of find don't match
```
```
import std.algorithm;
char[1024] buffer;
buffer[0..$].find("LOCATION: "); // works as expected
```
Before trying the slice I manually pragma(msg) all the template
constraints to see why it was failing. Apparently a static array
is not a ForwardRange. Now, there is probably a good reason for
that, that is not what I want to discuss.
The point is that it is rather hard to find out what went wrong.
What I would like the compiler to emit is this: `Error: buffer is
not a ForwardRange`. But I know that wouldn't be so easy.
At least the compiler shouldn't show me candidates with
non-matching arguments length (e.g.
`std.algorithm.searching.find(alias pred, InputRange)(InputRange
haystack) if (isInputRange!InputRange)`)
More information about the Digitalmars-d-learn
mailing list