Code Yarns ‍👨‍💻
Tech BlogPersonal Blog

STL: Swapping inside a container

📅 2009-Sep-28 ⬩ ✍️ Ashwin Nanjappa ⬩ 🏷️ containers, swapping ⬩ 📚 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]

© 2022 Ashwin Nanjappa • All writing under CC BY-SA license • 🐘 @codeyarns@hachyderm.io📧