I'm not sure about the exact implementation of std :: next_permutation, but if it is the same as the Narayana Pandita algorithm, as described in the wiki here: http://en.wikipedia.org/wiki/Permutation#Systematic_generation_of_all_permutations ,
assuming the elements are different, it looks like O (1) is being depreciated! (Of course, there may be errors below)
Let's calculate the total number of swaps completed.
We get the recurrence relation
T (n + 1) = (n + 1) T (n) + & Theta; (n 2 )
(n + 1) T (n) comes from fixing the first element and performing swaps for the remaining n.
& Theta; (n 2 ) comes from a change in the first element. At the point we change the first element, we do & Theta; (n) swaps. Do it n times, you get & Theta; (n 2 ).
Now let's get X(n) = T(n)/n!
Then we get
X (n + 1) = X (n) + & Theta; (n 2 ) / (n + 1)!
ie, there exists some constant C such that
X (n + 1) <= X (n) + Cn 2 / (n + 1)!
Writing down n such inequalities, we get
X (n + 1) - X (n) <= Cn 2 / (n + 1)!
X (n) - X (n-1) <= C (n-1) 2 / (n)!
X (n-1) - X (n-2) <= C (n-2) 2 / (n-1)!
...
X (2) - X (1) <= C1 2 / (1 + 1)!
Adding these values โโgives us X(n+1) - X(1) <= C(\sum j = 1 to n (j^2)/(j+1)!) .
Since the infinite series \sum j = 1 to infinity j^2/(j+1)! converges to C ', say, we get X(n+1) - X(1) <= CC'
Remember that X (n) calculates the average number of swaps needed (T (n) / n!)
Thus, the average number of swaps is O (1).
Since the element search for swap is linear with the number of swaps, O (1) is amortized even if you take other operations into account.