Yes, std::set stores its elements in such a way that iteration on the elements will be performed in sorted order (and a call to std::adjacent_find should show that std::set also stores unique elements).
#include <algorithm> #include <iterator> #include <ios> #include <iostream> #include <set> #include <string> int main() { auto const ss = std::set<std::string> { "foo", "bar", "test" }; std::cout << std::boolalpha << std::is_sorted(begin(ss), end(ss)) << "\n"; std::cout << std::boolalpha << (std::adjacent_find(begin(ss), end(ss)) == end(ss)) << "\n"; std::copy(begin(ss), end(ss), std::ostream_iterator<std::string>(std::cout, "\n")); }
Live example
TemplateRex Aug 04 '12 at 14:00 2012-08-04 14:00
source share