question about std::distance

Jeffrey Holle jeff.holle@verizon.net
Sun Sep 19 23:22:00 GMT 2004


I'm using gcc v3.4.2.

For the first time, I'm attempting to use std::distance and std::advance 
and am having trouble with at least std::distance.

Basically, I'm trying to deal with duplicates.
In the following code, I want to iterate thru just the non-duplicates.
In my test case, edges has a size of 47 and there are two sets of 4 
duplicates each.  So I want the for loop to execute 41 times.

typedef std::multiset<DataEdge,ltEdgeDescritor> Edges;
Edges edges;

<populate edges>

for(Edges::iterator iter=edges.begin();
                     iter!=edges.end(); 
advance(iter,distance(edges.lower_bound(*iter),edges.upper_bound(*iter)))
{
.....
}

What I find is that my program enters distance and doesn't leave.

Am I somehow misusing distance?

Can someone sugguest an alternate method for me to accomplish what I'm 
trying to do?



More information about the Gcc-help mailing list