Uwe Stöhr <[EMAIL PROTECTED]> writes: +void delete_opt(vector<string> & opts, char const * const * what) +{ + if (opts.empty()) + return; + + // remove found options from the list + // do this after handle_opt to avoid potential memory leaks and to be able + // to find in every case the last language option + vector<string>::iterator it; + for (; *what; ++what) { + it = find(opts.begin(), opts.end(), *what); + if (it != opts.end()) + opts.erase(it); + } +}
Can't you use std::remove multiple times and then perform only one erase? Should be much more efficient, no? See http://www.sgi.com/tech/stl/remove.html (it doesn't actually remove anything, just moves those iterators matching the predicate to the end...) typedef vector<string>::iterator iterator; iterator opts_end = opts.end(); iterator const opts_begin = opts.begin(); for (; *what; ++what) { opts_end = std::remove(opts_begin, opts_end, *what); if (opts_end == opts_begin) break; } std::erase(opts_end, opts.end(); Better still, use a predicate that itself loops over the what. Why are you using a c-string anyway? It's been a long time (and I get lost with pointers to pointers), but I think that the code below, or something like it should do the trick. Minimal re-working of your opts vector... struct ContainsCharInCString { private char const * const * cstring; ContainsCharInCString(char const * const * data) : this.cstring(data) {} bool operator(char input) { for (char const * const * ptr = cstring; *ptr; ++ptr) { if (input == *ptr) return true; } return false; } } iterator new_end = std::remove_if( opts.begin(), opts.end(), ContainsCharInCString(what)); std::erase(new_end, opts.end(); Angus