Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualBrother Bob

Posted 20 November 2012 - 06:54 AM

A thread like this is typically not complete without a standard library-centric answer.
horde.remove_if(
    [](zombie *z) {return z->onUpdate() == DELETE;}
);

std::for_each(
    std::begin(horde),
    std::end(horde),
    [](zombie *z) {z->onRender();}
);
Or if you want to to the update and the rendering in the same place.
horde.remove_if(
    [](zombie *z)->bool {
	    if(z->onUpdate() == DELETE) {
		    return true;
	    }
	    z->onRender();
	    return false;
    }
);
This one is less obvious and self-explaning though as you're mixing rendering code with the update and remove logic.

#1Brother Bob

Posted 20 November 2012 - 06:53 AM

A thread like this is typically not complete without a standard library-centric answer.
horde.remove_if(
    [](zombie *z) {return z->onUpdate() == DLETE;}
);

std::for_each(
    std::begin(horde),
    std::end(horde),
    [](zombie *z) {z->onRender();}
);
Or if you want to to the update and the rendering in the same place.
horde.remove_if(
    [](zombie *z)->bool {
	    if(z->onUpdate() == DLETE) {
		    return true;
	    }
	    z->onRender();
	    return false;
    }
);
This one is less obvious and self-explaning though as you're mixing rendering code with the update and remove logic.

PARTNERS