C
clark.coleman
Relatively new to STL use. I coded up a bunch of container code with
lots of iterators. Now I question whether I want to have so much
nested iterator syntax.
For example, if you are coding a compiler and you have classes such as
BasicBlock. Each basic block has predecessors and successors in the
control flow graph. Right now, I am storing these as iterators:
list<list<BasicBlock>::iterator> Predecessors;
list<list<BasicBlock>::iterator> Successors;
This leads to messy looking code. I have a GetFirstPred() method that
now returns something of type:
list<list<BasicBlock>::iterator>::iterator
and likewise a GetLastPred() method that does the same. Now, when I
want to iterate through all predecessors of a block, I have a loop
with all kinds of dereferencing of iterators:
list<list<BasicBlock>::iterator>::iterator CurrPred;
for (CurrPred = this->GetFirstPred(); CurrPred != this->GetLastPred();
++CurrPred) {
if ((*CurrPred)->IsJoinPoint()) .... etc.
}
Should this all be list of references instead of list of iterators for
simplicity?
list<BasicBlock &> Predecessors;
Thanks for any recommendations.
lots of iterators. Now I question whether I want to have so much
nested iterator syntax.
For example, if you are coding a compiler and you have classes such as
BasicBlock. Each basic block has predecessors and successors in the
control flow graph. Right now, I am storing these as iterators:
list<list<BasicBlock>::iterator> Predecessors;
list<list<BasicBlock>::iterator> Successors;
This leads to messy looking code. I have a GetFirstPred() method that
now returns something of type:
list<list<BasicBlock>::iterator>::iterator
and likewise a GetLastPred() method that does the same. Now, when I
want to iterate through all predecessors of a block, I have a loop
with all kinds of dereferencing of iterators:
list<list<BasicBlock>::iterator>::iterator CurrPred;
for (CurrPred = this->GetFirstPred(); CurrPred != this->GetLastPred();
++CurrPred) {
if ((*CurrPred)->IsJoinPoint()) .... etc.
}
Should this all be list of references instead of list of iterators for
simplicity?
list<BasicBlock &> Predecessors;
Thanks for any recommendations.