// Use a functor to change the sorting order of a container. // // Why doesn’t 1.0 show up? #include #include #include using namespace std; // Sort doubles according to how close they are to 5.0. class Proximity { public: bool operator()(double a, double b) const { return fabs(a-5.0) < fabs(b-5.0); } }; int main() { set s; s.insert(1.2); s.insert(3.4); s.insert(5.6); s.insert(7.8); s.insert(9.0); s.insert(1.0); for (set::iterator it=s.begin(); it!=s.end(); ++it) cout << *it << ' '; cout << '\n'; }