|
-
August 9th, 2008, 09:19 AM
#8
Re: Setting an iterator to "end"
 Originally Posted by Paul McKenzie
If it were up to me in a code review, I would reject any code that does this.
The proper loop construct if you want to change things around like this is a while loop, or at least a for loop that has some sort of terminating condition:
Code:
bool okToContinue = true;
for (int i = 0; i < somevalue && okToContinue; ++i)
{
// if ( whatever )
{
okToContinue = false;
}
}
Then the loop terminates automatically since the okToContine is false.
Regards,
Paul McKenzie
Even this might raise some eyebrows. I prefer Kurt's suggestion as long as there is no practical reason not to use break.
Another option if you're so inclined is to use std::find_if, with a predicate along the lines of:
Code:
class Mouse_Over_Tile_Pred
{
public:
Mouse_Over_Tile_Pred(const SDL_Rect & mouse) :
m_mouse(mouse)
{
}
bool operator()(Tile_Pen * /* ? */ tile_pen) const
{
return SDL_Tools::mouse_over_rect(m_mouse, tile_pen->Get_Position());
}
private:
const STL_Rect m_mouse;
};
But that's a bit of overkill for such a simple predicate.
- Alon
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|