Nifty chaining

Peter Alexander peter.alexander.au at gmail.com
Mon Oct 4 08:28:53 PDT 2010


== Quote from Steven Schveighoffer (schveiguy at yahoo.com)'s article
> 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 if add just returns the delta rather than the reference then
it's just:

with (a) numAdded = add(1,2,3) + add(b) + add(c[1..3]);
// (I'm hoping 'with' works like this! Can't test here)

or

numAdded = a.add(chain([1,2,3], b, c[1..3]);

(I'm assuming b was a range here, otherwise you could just add it
to the end of the first expression).


More information about the Digitalmars-d mailing list