Boost logo

Boost Users :

From: Bill Buklis (boostuser_at_[hidden])
Date: 2006-02-08 20:32:03


How would I accomplish the following using ptr_map instead of std::map?

typedef std::map< std::string, int* > stlmap;

bool predicate( stlmap::value_type& mapitem )
{
    // return true if key value has at least 4 characters
    return( mapitem.first.size() > 3 );
}

void sample( stlmap& themap )
{
    std::find_if( themap.begin(), themap.end(), predicate );
}

The predicate for std::find_if requires *iterator for the parameter.
However, with ptr_map *iterator returns a reference to the element value
instead of the key/value pair. Normally this is fine (in general code I like
this feature), but in this case I need access to the key in the predicate.
How do I get at it?

ptr_map version of above:

typedef boost::ptr_map< std::string, int > bpmap;

bool predicate( ??? )
{
  ???
}

void sample( bpmap& themap )
{
    std::find_if( ??? );
}


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net