On Tuesday, 15 January 2013 at 17:57:07 UTC, Andrei Alexandrescu wrote:
On 1/15/13 2:20 AM, monarch_dodra wrote:
auto l = cutBefore(a, b); //Gets the part of a that is before b
auto r = cutAfter(a, b); //Gets the part of a that is after b

I think cutBefore is sufficient. No? Ideas for better names?

Andrei

I've been trying to brainstorm a couple of ideas. Here is one:

//----
Tuple(R, R) cut(R other); //Returns both parts of the
                          //current range that are
                          //Before and After other

usage:
//----
Tuple(R, R) slices = a.cut(b); //Cuts a in two pieces, relative to b.
assert(equal(a, chain(slices[0], b, slices[1])));

From there, we adding just the "merge" primitive would give us:

//----
R result = merge(b, slices[1]);

The neat thing here is that we have consistent typing the entire algorithm through. Yay!

That's two extra functions, which can provide slicing and merging for bidirectional ranges. And they can be provided without breaking anything existing. Not too shabby (IMO).

This is still very sketchy of course, so don't destroy too hard ;)

Reply via email to