I have:
std::unordered_set<ui::Button*> _buttons;
std::unordered_set<Sprite*> _sprites;
std::unordered_set<Sprite*> _someOtherSprites;
Both ui::Button
and Sprite
, inherit from Node
.
So for example, I can do:
for(Node* node : _sprites){
node->setPosition(1,2);
}
for(Node* node : _someOtherSprites){
node->setPosition(1,2);
}
for(Node* node : _buttons){
node->setPosition(1,2);
}
Since I need to do the same operations on both sets, is there some way do this with just one set of loops ? I mean keeping all the code that executes within the loops in one place, instead of repeating it in different loops like above ?
I have to maintain sprites,someOtherSprites and buttons in separate sets.
Can I do something like this:
std::unordered_set<std::unordered_set<Node*>> mySets;
mySets.insert(_buttons);
mySets.insert(_sprites);
mySets.insert(_someOtherSprites);
for(auto mySet : mySets)
for(Node* node : mySet){
node->setPosition(1,2);
}
}
I have no necessity to do this. I am just curious if something like this is possible.