Boost logo

Boost Users :

From: Nat Goodspeed (nat_at_[hidden])
Date: 2008-04-18 15:14:34


Robert Dailey wrote:

> I have the following code:
>
> void HandlePair( std::pair<int, char*>& mypair )
> {
> }
>
> void main()
> {
> boost::ptr_map<int, char> mymap;
> HandlePair( *mymap.begin() );
> }
>
>
> What's the proper way to accept pairs in the HandlePair function?

I'd suggest basing it on your actual ptr_map type, e.g.:
void HandlePair(const boost::ptr_map<int, char>::value_type& mypair) {}

I usually use map_type::value_type (using an appropriate typedef for
map_type) even when working with std::map, since the type of a pair
stored in a std::map<A, B> is NOT the same as std::pair<A, B>: it's
actually std::pair<const A, B>. I have no idea what the transformation
is for boost::ptr_map, but in any case, its value_type should give you
what you want.


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