Idea: swap with multiple arguments

Jonathan M Davis via Digitalmars-d digitalmars-d at puremagic.com
Mon May 23 14:38:54 PDT 2016


On Monday, May 23, 2016 16:27:43 Steven Schveighoffer via Digitalmars-d wrote:
> On 5/23/16 4:01 PM, Andrei Alexandrescu wrote:
> > So swap(a, b) swaps the contents of a and b. This could be easily
> > generalized to multiple arguments such that swap(a1, a2, ..., an)
> > arranges things such that a1 gets an, a2 gets a1, a3 gets a2, etc. I do
> > know applications for three arguments. Thoughts? -- Andrei
>
> One thing that screams out to me: this should be called rotate, not swap.

That would probably be better. My immediate thought on reading Andrei's
suggestion for swap was that it would be way too easy to forget what's
actually being swapped when there are more than two arguments. Rotate at
least implies and ordering to it.

Though I confess that I've never heard of a swap function (or anything like
a swap function) that's swapped more than two arguments, and I'm not aware
of any point in time when I thought that such a thing might be useful. So,
I'm not exactly clamoring for a function like this, but that obviously
doesn't mean that it's not worth adding, just that I don't personally see
any particular value in it.

- Jonathan M Davis



More information about the Digitalmars-d mailing list