www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Some algorithms on immutable data: bug 5134?

reply biozic <dransic free.fr> writes:
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...
}


somthing?
Thanks
Nicolas
Nov 25 2010
parent biozic <dransic free.fr> writes:
<!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
    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>

      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

    is const, it cannot be an InputRange, so compilation fails...<br>
    <br>
    Am I right?<br>
    Thanks,<br>
    <br>
    Nicolas<br>
    <br>
  </body>
</html>
Dec 04 2010