[Issue 13877] Problem with map+join

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Fri Dec 19 07:01:25 PST 2014


https://issues.dlang.org/show_bug.cgi?id=13877

Ketmar Dark <ketmar at ketmar.no-ip.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ketmar at ketmar.no-ip.org

--- Comment #2 from Ketmar Dark <ketmar at ketmar.no-ip.org> ---
btw, with such modification both variants becomes equivalent:

  auto stripSave(RT) (auto ref RT rng) {
    static struct R {
      RT r;
      @disable void save ();
      alias r this;
    }
    return R(rng);
  }


  const(int)[] foo2 (in int[] data, in int i, in int max) {
    count2++;
    if (i < max) {
      return data.map!(n => foo2(data, i + 1, max)).stripSave.join;
    } else {
      return data;
    }
  }


the code turns MapResult to non-forward range, and then join doesn't calculate
everything twice.

the question is: should MapResult has '.save' here in the first place?

or maybe we need some API — as `stripSave` to explicitly remove features from
ranges? it's very obvious to the programmer that recalculating range values is
costly in this case, so he can just remove `.save` to stop Phobos using it.

--


More information about the Digitalmars-d-bugs mailing list