* question about std::distance
@ 2004-09-19 23:22 Jeffrey Holle
2004-09-20 0:49 ` Jeffrey Holle
0 siblings, 1 reply; 4+ messages in thread
From: Jeffrey Holle @ 2004-09-19 23:22 UTC (permalink / raw)
To: gcc-help
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?
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: question about std::distance
2004-09-19 23:22 question about std::distance Jeffrey Holle
@ 2004-09-20 0:49 ` Jeffrey Holle
2004-09-20 5:11 ` Jeffrey Holle
0 siblings, 1 reply; 4+ messages in thread
From: Jeffrey Holle @ 2004-09-20 0:49 UTC (permalink / raw)
To: gcc-help
On further investigation, it appears that the problem that I'm having is
related to my ltEdgeDescriptor functor. In calling either .count or
distance, this functor is called forever. It has been used before, but
only with map. It appears to be at least intolerant of duplicates.
There it is:
struct ltEdgeDescriptor : public
std::binary_function<DataEdge,DataEdge,bool>
{
bool operator() (const DataEdge& s1, const DataEdge& s2) const
{
return s1.m_source<s2.m_source || (!(s1.m_source<s2.m_source) &&
s1.m_target<s2.m_target);
}
};
I copied this pattern from stl_pair.h, so I thought I was safe.
Can someone point out the problem here and hopefully sugguest an
alternate implementation?
Jeffrey Holle wrote:
> 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?
>
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: question about std::distance
2004-09-20 0:49 ` Jeffrey Holle
@ 2004-09-20 5:11 ` Jeffrey Holle
2004-09-23 3:06 ` Jeffrey Holle
0 siblings, 1 reply; 4+ messages in thread
From: Jeffrey Holle @ 2004-09-20 5:11 UTC (permalink / raw)
To: gcc-help
Found my alternate implement via:
typedef map<vector EdgeData> > Edges.
Would really like to know if I found a big bug in sgi stl or my bug,
probably in my compare functor.
Jeffrey Holle wrote:
> On further investigation, it appears that the problem that I'm having is
> related to my ltEdgeDescriptor functor. In calling either .count or
> distance, this functor is called forever. It has been used before, but
> only with map. It appears to be at least intolerant of duplicates.
> There it is:
> struct ltEdgeDescriptor : public
> std::binary_function<DataEdge,DataEdge,bool>
> {
> bool operator() (const DataEdge& s1, const DataEdge& s2) const
> {
> return s1.m_source<s2.m_source || (!(s1.m_source<s2.m_source) &&
> s1.m_target<s2.m_target);
> }
> };
>
> I copied this pattern from stl_pair.h, so I thought I was safe.
> Can someone point out the problem here and hopefully sugguest an
> alternate implementation?
>
>
>
> Jeffrey Holle wrote:
>
>> 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?
>>
>>
>
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: question about std::distance
2004-09-20 5:11 ` Jeffrey Holle
@ 2004-09-23 3:06 ` Jeffrey Holle
0 siblings, 0 replies; 4+ messages in thread
From: Jeffrey Holle @ 2004-09-23 3:06 UTC (permalink / raw)
To: gcc-help
Found my problem!
It was my ltEdgeDescriptor functor.
Instead of:
return s1.m_source < s2.m_source ||
(!(s1.m_source < s2.m_source) && s1.m_target < s2.m_target);
It needed to be:
return s1.m_source < s2.m_source ||
(!(s2.m_source < s1.m_source) && s1.m_target < s2.m_target);
Jeffrey Holle wrote:
> Found my alternate implement via:
> typedef map<vector EdgeData> > Edges.
> Would really like to know if I found a big bug in sgi stl or my bug,
> probably in my compare functor.
>
> Jeffrey Holle wrote:
>
>> On further investigation, it appears that the problem that I'm having
>> is related to my ltEdgeDescriptor functor. In calling either .count
>> or distance, this functor is called forever. It has been used before,
>> but only with map. It appears to be at least intolerant of duplicates.
>> There it is:
>> struct ltEdgeDescriptor : public
>> std::binary_function<DataEdge,DataEdge,bool>
>> {
>> bool operator() (const DataEdge& s1, const DataEdge& s2) const
>> {
>> return s1.m_source<s2.m_source || (!(s1.m_source<s2.m_source) &&
>> s1.m_target<s2.m_target);
>> }
>> };
>>
>> I copied this pattern from stl_pair.h, so I thought I was safe.
>> Can someone point out the problem here and hopefully sugguest an
>> alternate implementation?
>>
>>
>>
>> Jeffrey Holle wrote:
>>
>>> 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?
>>>
>>>
>>
>>
>
>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2004-09-23 3:06 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-09-19 23:22 question about std::distance Jeffrey Holle
2004-09-20 0:49 ` Jeffrey Holle
2004-09-20 5:11 ` Jeffrey Holle
2004-09-23 3:06 ` Jeffrey Holle
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).