I was following the documentation here: http://dlang.org.mirror/spec/arrays.html#slicing and I'm having a problem comparing the returned Slice from a function with an array.

Here's the simplified code:

```
import std.stdio;
import std.regex;
import std.string;
import std.array;

auto sliceIt(array[string] words_arr) {
  int i = 1;
  string word;
  while(i < words_arr.length) {
    word = words_arr[i];
    if(matchFirst(word, r"^[A-Z]+$")) { break; }
    i++;
  }
  return def_words_arr[1..i];
}

unittest {
  auto words = ["HELLO", "world", "hi", "ENDOFTHERUNWAY"];
  auto resulting_arr = sliceIt(["world", "hi"]);
  assert(resulting_arr == ["world", "hi"]);
}
```

This produces a compile-time error:

```
Error: template `std.array.array(Range)(Range r) if (isIterable!Range && !isAutodecodableString!Range && !isInfinite!Range)` is used as a type Failed: ["~/.local/dlang/dmd-2.108.1/freebsd/bin64/dmd", "-debug", "-unittest", "-main", "-v", "-o-", "words.d", "-Idefinition"]
```

I was thinking of maybe assigning correct return type for the function, tried it, but got more errors produced by the compiler. Can someone point me to an obvious mistake or lack of understanding?
  • Comparing slice ... madwebness via Digitalmars-d-learn
    • Re: Compari... madwebness via Digitalmars-d-learn
      • Re: Com... Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
        • Re:... madwebness via Digitalmars-d-learn
          • ... Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
          • ... madwebness via Digitalmars-d-learn
            • ... madwebness via Digitalmars-d-learn
              • ... madwebness via Digitalmars-d-learn
                • ... Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn

Reply via email to