Nifty chaining
Steven Schveighoffer
schveiguy at yahoo.com
Mon Oct 4 08:22:01 PDT 2010
On Mon, 04 Oct 2010 11:10:53 -0400, Peter Alexander
<peter.alexander.au at gmail.com> wrote:
> I must be missing something, because I don't really see the need
> for this at all.
>
> Why not just return the number of items added, and forget about
> chaining? If you're worried about having to type the container's
> identifier in over and over again, just use with(c) {...}, and if
> you want to chain together multiple different ranges, just use
> std.range.chain.
This works also. It depends on your preference for style.
I personally find this much more pleasant:
auto numAdded = lengthChain(a).add(1,2,3).add(b).add(c[1..3]).delta;
than:
int numAdded = void;
with(a)
{
auto olength = length;
add(1,2,3);
add(b);
add(c[1..3]);
numAdded = length - olength;
}
But you might not.
> Is there any use case where these don't suffice?
Achieving it all with a single expression. You might not care whether
that's possible, but I personally like it better. Whether it achieves
much more than style points, I don't know. I'm guessing it might add a
bit of bloat.
-Steve
More information about the Digitalmars-d
mailing list