#include "llvm/ADT/SmallVector.h" #includeint main() { llvm::SmallVector vec{10, 20, 30, 40, 50}; vec.erase(vec.begin() + 2); for (auto i : vec) { std::cout << i << " "; } return 0; } // Output: 10 20 40 50
#include "llvm/ADT/SmallVector.h" #includeIn this example, elements with indices from 1 to the second-to-last are removed from the vector. The erase() function takes iterators to the beginning and end positions of the range to remove. Package Library used: LLVMint main() { llvm::SmallVector vec{10, 20, 30, 40, 50}; vec.erase(vec.begin() + 1, vec.end() - 1); for (auto i : vec) { std::cout << i << " "; } return 0; } // Output: 10 50