Tuples citizenship

kennytm kennytm at gmail.com
Fri Mar 2 01:31:14 PST 2012


Jonathan M Davis <jmdavisProg at gmx.com> wrote:

> That's assuming that you're passing all of the pieces of the tuple to the 
> function. Often, that's not the case at all. Take the findSplit trio, for 
> instance. What are the odds that you're going to want to pass all of the 
> elements in the tuples that any of the return to another function? About zero, 
> I'd say. It's _much_ more likely that you're going to want to take the results 
> and then pass _one_ of them to another function. So, as it stands, chaining 
> with those functions just doesn't work unless you only care about one of the 
> results in the tuple.
> 
> - Jonathan M Davis

How does 'out' make chaining any easier? Suppose we have a `R3
findSplit2(R1, R2, out R4, out R5)`, how to chain if we want to pass the R4
to another function?

    R5 ignored;
    R4 theRange;
    findSplit2(haystack, needle, theRange, ignored);
    return doSomething(theRange);

vs

    return doSomething(findSplit(haystack, needle)[1]);


More information about the Digitalmars-d mailing list