Например, строка < /p>
Код: Выделить всё
This is a "foo", that is a "foobar"
Код: Выделить всё
void swapInPlace(std::string& data, size_t a, size_t next_a, size_t b, size_t next_b) {
const size_t gap_len = b - next_a;
const size_t b_len = next_b - b;
std::rotate(data.begin()+a, data.begin()+next_a, data.begin()+b);
std::rotate(data.begin()+a+gap_len, data.begin()+b, data.begin()+next_b);
std::rotate(data.begin()+a, data.begin()+a+gap_len, data.begin()+a+gap_len+b_len);
}
Подробнее здесь: https://stackoverflow.com/questions/797 ... allocation
Мобильная версия