[ptr_container] Pair type for boost::ptr_map?
Hi, 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 can't seem to find a boost::ptr_pair anywhere, or something like that.
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.
Nat Goodspeed skrev:
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) {}
Actually, using void HandlePair(boost::ptr_map<int, char>::const_reference mypair); is better, since the reference type is not a real reference. So don't rely on map::reference to be equal to map::value_type&. HTH -Thorsten
participants (3)
-
Nat Goodspeed
-
Robert Dailey
-
Thorsten Ottosen