On Tuesday, 27 February 2018 at 11:33:04 UTC, Simen Kjærås wrote:
That only checks if the first element is the same. For a full 'is slice' check you'd need something like this:

assert(a.ptr <= b.ptr && b.ptr + b.length <= a.ptr + a.length);

// Or:

    auto c = b.ptr - a.ptr;
    assert(c >= 0 && c + b.length <= a.length);

And trust me, the compiler complains about both of these. Possibly rightfully in the first example, but the latter never does anything scary with the given pointers.

--
  Simen

aka isSliceOf -> https://github.com/dlang/phobos/pull/6147

Reply via email to