How AI is applied across API Evangelist and APIs.io. Read my AI disclosure →
API Evangelist API Evangelist
Discovery
Learnings
Guidance
Toolbox
Alignment
API Evangelist LLC

Rotation revisited: Another unidirectional algorithm -- Raymond Chen

calendar_today July 21, 2026 person Blog Staff domain cplusplus

Some time ago, we looked at how to swap two adjacent blocks of memory in constant extra space, and along the way explored how std::rotate accomplishes the same task. I later claimed that the random-access implementations in both libc++ and libstdc++ treat the operation as a permutation decomposed into cycles—but after taking a closer look, I discovered that only libc++ does; libstdc++ uses a different algorithm altogether. Rotation revisited: Another unidirectional algorithm by Raymond Chen From the article: Some time ago, we looked at the problem of swapping two blocks of memory that reside i

open_in_new Read original post