Problem with my Quadtree - converting from std::vector to std::set

Started by
9 comments, last by Cornstalks 10 years, 9 months ago
Note that it might be simpler to do something like this:


// Disclaimer: there might be some minor syntactic errors in this
// First define this functor (could also be a function, if parent can be accessed globally, which I'd be concerned about)
struct CheckInBounds
{
    Parent* parent; // Or whatever type "parent" really is
 
    CheckInBounds(Parent* p) : parent(p) {
    }
 
    bool operator()(const GameObject* o) {
        if (!inBounds(o->getX(), o->getY())) {
            parent->addObject(o);
            return true; // remove it
        }
        else {
            return false; // don't remove it
        }
    }
};
 
// Then, you can do something simple like this:
auto newEnd = std::remove_if(objects.begin(), objects.end(), CheckInBounds(parent));
objects.erase(newEnd, objects.end());
[size=2][ I was ninja'd 71 times before I stopped counting a long time ago ] [ f.k.a. MikeTacular ] [ My Blog ] [ SWFer: Gaplessly looped MP3s in your Flash games ]

This topic is closed to new replies.

Advertisement