I want to use for_each to iterate over a series of sprites based on a predicate and then draw them. But I forgot how to use predicates. The only way I could think of was the following:
Can I compact the two functors into one and use some predicate in the for_each calls? Because as it is now I couldve just written out a for loop. The only thing different is the == and != in the functors.Code:struct OpaqueTest { void operator()(CSprite &sprite) { if (sprite.GetOpacity() == ALPHA_OPAQUE) { sprite.Draw(); } } }; struct NonOpaqueTest { void operator()(CSprite &sprite) { if (sprite.GetOpacity() != ALPHA_OPAQUE) { sprite.Draw(); } } }; std::for_each(m_Sprites, m_Sprites + Size, OpaqueTest); std::for_each(m_Sprites, m_Sprites + Size, NonOpaqueTest);



LinkBack URL
About LinkBacks


