std::equal_range Behaviour
Thanks in advance;
What I'm trying to do is find all the elements in the map that have a
certain value. The question I have is can you do this when the value
you are trying to find is not in the key of the map? The code seems to
work except that when I iterate through the result I end up getting
values that don't match the criteria.
Is there another algorithm that I should use instead? For instance,
can I use find_if in a while loop or something like that?
Here is a snippet of the code:
class ChannelFields
{
public:
long lngPortId;
}
class CompChannelPortId
{
public:
CompChannelPortId() {}
bool operator() ( const std::pair<long, ChannelFields>& lhs, const
std::pair<long, ChannelFields>& rhs ) const
{
return( lhs.second.lngPortId < rhs.second.lngPortId )
}
};
class ChannelDbMap : std::map<long, ChannelFields>
{
public:
void
refreshMap( long id )
{
std::pair<long, ChannelFields> compChannel;
compChannel.second.lngPortId = id;
std::pair<iterator, iterator> range
= std::equal_range( begin(), end(), compChannel,
CompChannelPortId() );
}
}