#include // for EXIT_SUCCESS #include // for std::cout, std::endl #include // for std::unique_vec #include // for std::vector #include // for sort() using std::unique_ptr; using std::vector; using std::cout; using std::endl; using std::sort; using std::for_each; bool sortfunction(const unique_ptr &x, const unique_ptr &y) { return *x < *y; } void printfunction(unique_ptr &x) { cout << *x << endl; } int main(int argc, char **argv) { vector > vec; vec.push_back(unique_ptr(new int(9))); vec.push_back(unique_ptr(new int(5))); vec.push_back(unique_ptr(new int(7))); // buggy: sorts based on the values of the ptrs sort(vec.begin(), vec.end()); cout << "Sorted:" << endl; for_each(vec.begin(), vec.end(), &printfunction); // better: sorts based on the pointed-to values sort(vec.begin(), vec.end(), &sortfunction); cout << "Sorted:" << endl; for_each(vec.begin(), vec.end(), &printfunction); return EXIT_SUCCESS; }