A
Alan Woodland
Is this well defined behaviour?
#include <vector>
#include <string>
#include <algorithm>
int main() {
std::vector<std::string> content;
content.push_back("foo");
content.push_back("bar");
content.push_back("foo");
// make sure the content is unique, discard any duplicates
std::sort(content.begin(), content.end());
content.erase(std::unique(content.begin(), content.end()),
content.end());
return 0;
}
My concern is that the order of evaluation of the arguments passed to
erase() is unspecified, and therefore that unique could invalidate the
iterator returned by end(). If I've understood things correctly then
unique can't invalidate any iterators and so the example code is well
defined?
Thanks,
Alan
#include <vector>
#include <string>
#include <algorithm>
int main() {
std::vector<std::string> content;
content.push_back("foo");
content.push_back("bar");
content.push_back("foo");
// make sure the content is unique, discard any duplicates
std::sort(content.begin(), content.end());
content.erase(std::unique(content.begin(), content.end()),
content.end());
return 0;
}
My concern is that the order of evaluation of the arguments passed to
erase() is unspecified, and therefore that unique could invalidate the
iterator returned by end(). If I've understood things correctly then
unique can't invalidate any iterators and so the example code is well
defined?
Thanks,
Alan