I have a code In a form:
unordered_set<pair<int,int>,CustomHash> Edges;
typedef unordered_set<pair<int,int>,CustomHash>::iterator EdgesIt;
...
for(auto it=Edges.begin();it!=Edges.end();it++){
list<EdgesIt> List;
}
etc. How can I avoid defining a new type EdgesIt to be used in List declaration and get it in some smarter way, for example:
list<Edges::iterator_type> List;
InteliSense only suggests Edges::iterator
which is defined as typedef std::iterator pair<int,int> iterator
. More to say, it doesn't work. I also tried to use unordered_set::iterator
, but it also doesn't work.
Edges
is the name of object, not the name of the class. You can't get the nested typedef
from it directly like Edges::iterator
.
You can use decltype (since C++11) to get the type you want (i.e. unordered_set<pair<int,int>,CustomHash>
).
list<decltype(Edges)::iterator> List;
// same as list<unordered_set<pair<int,int>,CustomHash>::iterator> List;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With