"isDroppable" range trait for slicing to end

monarch_dodra monarchdodra at gmail.com
Mon Oct 29 07:34:03 PDT 2012


On Monday, 29 October 2012 at 14:33:01 UTC, monarch_dodra wrote:
> [SNIP]

Extension:

An extension to this proposal, is the function "extractSlice".
This function would *ONLY* require isDroppable. It would be
implemented as:

//----
auto extractSlice(R)(R r, size_t i, size_t j)
{
      static if (hasSlicing)
          return r[i .. j];
      else
          return r.drop(i).takeExactly(j - i);
}
//----

What makes this notion interesting, is that it works both on
sliceable ranges AND infinite ranges, but does not pretend to
have back-assignement to the original range. This is very
interesting, because it would allow "hasSlicing" to turn down
infinite ranges, but we'd still have a way to extract a range out
of those infinite ranges.

Another added bonus would be that certain non-infinite ranges, in
particular immutable ranges, are considered not-sliceable,
because they can't be back-assignabe. extractSlice would allow us
to extract a slice out of those ranges, even if we can't assign
them back...


More information about the Digitalmars-d mailing list