Home page.


This page contrasts the rotate_position and rotate_value functions. They rotate values within a permutation.

Function rotate_position is a wrapper for std::rotate.

The examples rely on this definition:
    permu_arr_0<13> const q {4, 8, 6, 5, 12, 3, 7, 11, 1, 2, 10, 0, 9};
Given these statements:
    permu_arr_0<13> p {q}; 
    p.rotate_position (2, 5, 10);
what happens is:
  • the element at position 5 is moved to position 2;
  • the element at position 6 is moved to position 3;
  • the element at position 7 is moved to position 4;
  • the element at position 8 is moved to position 5;
  • the element at position 9 is moved to position 6;
  • the element that was at position 2 is moved to position 7;
  • the element that was at position 3 is moved to position 8;
  • the element that was at position 4 is moved to position 9.

table 1 — zero-based rotate_position
position: 0123456789101112
original: 4865123711121009
(2, 5, 10): 4837111265121009

Given these statements:
    permu_arr_0<13> p {q}; 
    p.rotate_value (2, 5, 10);
what happens is:
  • element 5 is moved to where element 2 was;
  • element 6 is moved to where element 3 was;
  • element 7 is moved to where element 4 was;
  • element 8 is moved to where element 5 was;
  • element 9 is moved to where element 6 was;
  • element 2 is moved to where element 7 was;
  • element 3 is moved to where element 8 was;
  • element 4 is moved to where element 9 was.

table 2 — zero-based rotate_value
position: 0123456789101112
original: 4865123711121009
(2, 5, 10): 7398126211151004

equivalentequivalent
Given these statements:
    permu_arr_1<13> p {q}; 
    p.rotate_position (3, 6, 11);
what happens is:
  • the element at position 6 is moved to position 3;
  • the element at position 7 is moved to position 4;
  • the element at position 8 is moved to position 5;
  • the element at position 9 is moved to position 6;
  • the element at position 10 is moved to position 7;
  • the element that was at position 3 is moved to position 8;
  • the element that was at position 4 is moved to position 9;
  • the element that was at position 5 is moved to position 10.

    table 3 — one-based rotate_position
    position: 12345678910111213
    original: 59761348122311110
    (3, 6, 11): 59481223761311110

Given these statements:
    permu_arr_1<13> p {q}; 
    p.rotate_value (3, 6, 11);
what happens is:
  • element 6 is moved to where element 3 was;
  • element 7 is moved to where element 4 was;
  • element 8 is moved to where element 5 was;
  • element 9 is moved to where element 6 was;
  • element 10 is moved to where element 7 was;
  • element 3 is moved to where element 8 was;
  • element 4 is moved to where element 9 was;
  • element 5 is moved to where element 10 was.

table 4 — one-based rotate_value
position: 12345678910111213
original: 59761348122311110
(3, 6, 11): 84109137312261115

permu_vec_0 and permu_vec_1 work the same way.