• Create Account

Banner advertising on our site currently available from just \$5!

### #ActualCornstalks

Posted 30 June 2013 - 09:59 AM

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())) {
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());


### #1Cornstalks

Posted 30 June 2013 - 09:57 AM

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()(GameObject* o) {
if (!inBounds(o->getX(), o->getY())) {
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());


PARTNERS