Code Yarns ‍👨‍💻
Tech BlogPersonal Blog

STL: Swapping inside a container

📅 2009-Sep-28 ⬩ ✍️ Ashwin Nanjappa ⬩ 📚 Archive

Swapping elements of a C++ STL container is same as swapping normally.

// Swapping 2 elements of a STL container
#include <algorithm>
std::swap(ivec.at(0), ivec.at(1)); // Swap [0] & [1]