On 2016-05-24 02:16, H. S. Teoh via Digitalmars-d wrote:
On Mon, May 23, 2016 at 04:01:08PM -0400, Andrei Alexandrescu via Digitalmars-d
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
As others have said, 'swap' is a horrible name for this. I'd go with
'rotate', but then there's the question of which direction it rotates.
Conceivably, it's equally valid for an to get a1, a1 to get a2, etc..
So 'rotateRight' would be most unambiguous, though a handful to type.
I would do it as rotate(RandomAccessRange, ptrdiff_t shift).
shift >= 1 means rotate right by amount of shift
shift <= -1 means rotate left
shift == 0 does nothing
This way it's more general, it's possible to rotate by any amount, left
or right.