I was trying to resort a set when i realised that it was impossible to resort a set and i had to create a new set and have a custom sort function to resort it . I researched onl
It's usually better to define a functor class to specify the ordering, rather than a function; that way, you can specify it as a template parameter:
struct p2d_sortby_y {
bool operator()(Point2D x, Point2D y) {return whatever;}
};
This has to take its arguments by value or const
reference (not non-const
reference, as yours does) to be used on the constant set members.
You can't directly initialise the new set from a different type of set, but you can initialise it from its range:
set p2d_set2(p2d_set.begin(), p2d_set.end());