Showing posts with label transform_iterator. Show all posts
Showing posts with label transform_iterator. Show all posts

Saturday, November 23, 2013

Exploring ways to express an algorithm

Suppose you want to rewrite the following loop
  
struct Shape {
    int rgb_color() const;
};

map<int, Shape*> id_to_shape;
vector<int> bright_colors;


for( map<int, Shape*>::iterator it=id_to_shape.begin(); it != id_to_shape.end(); ++it )
{
    int color = it->second->rgb_color();
    if (color_is_bright (color))
        v.push_back(bright_colors);
}
  
Here follows a tour in ways that this loop could be expressed.