
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
m.begin.base() seems like it might work, but I'm having a little trouble figuring out the right parameters for the predicate. bpmap::value_type doesn't match. What's the correct type/typedef to use for the base void-ptr-map? Thanks, -- Bill -- -----Original Message----- From: boost-users-bounces@lists.boost.org [mailto:boost-users-bounces@lists.boost.org] On Behalf Of Thorsten Ottosen Sent: Thursday, February 09, 2006 4:09 AM To: boost-users@lists.boost.org Subject: Re: [Boost-users] [ptr_container] ptr_map predicates Bill Buklis wrote: like
this feature), but in this case I need access to the key in the predicate. How do I get at it?
this is an interesting use-case that I haven't thought of.
ptr_map version of above:
typedef boost::ptr_map< std::string, int > bpmap;
bool predicate( ??? ) { ??? }
bool predicate( const std::pair
void sample( bpmap& themap ) { std::find_if( ??? ); }
void sample( bpmap& m ) { std::find_if( m.begin().base(), m.end().base(), predicate() ); } iterator.base() should return an iterator to the underlying void-ptr-map. I hope it works -Thorsten _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users