Idea: swap with multiple arguments
Xinok via Digitalmars-d
digitalmars-d at puremagic.com
Mon May 23 14:49:10 PDT 2016
On Monday, 23 May 2016 at 20:01:08 UTC, 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
It doesn't make sense for "swap" to make take than two arguments
and it's unintuitive how it should rearrange the elements when
you write swap(a1, a2, a3, ...). Who's to say that it should
shift the elements to the left?
I'm not saying this is useless but it would really need a better
name. "swap" only makes intuitive sense when it takes two
arguments, no more and no less.
While this is technically a rotation, a "rotate" function
generally takes an extra argument which is an element/index to
rotate on. See: https://www.sgi.com/tech/stl/rotate.html
More information about the Digitalmars-d
mailing list