Boost logo

Boost Users :

From: Bill Buklis (boostuser_at_[hidden])
Date: 2006-02-09 12:52:23


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_at_[hidden]
[mailto:boost-users-bounces_at_[hidden]] On Behalf Of Thorsten Ottosen
Sent: Thursday, February 09, 2006 4:09 AM
To: boost-users_at_[hidden]
Subject: Re: [Boost-users] [ptr_container] ptr_map predicates

Bill Buklis wrote:
> 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?

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<const std::string,void*>& p )
{
   return p.first.size() > 3;
}

> 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_at_[hidden]
http://lists.boost.org/mailman/listinfo.cgi/boost-users


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