std::map< std::string , std::string > matrix_int;
typedef std::pair< std::string , std::string > lp_type;
BOOST_FOREACH( lp_type &row, matrix_int ){
}
this can not be complied: error C2440: 'initializing' : cannot convert from 'std::pair<_Ty1,_Ty2>' to 'lp_type &'
when I have ',' in element type, boost doc says I can use typedef or predefine a var; but what should I do when I want to get a reference?
Your typedef is incorrect; it needs to be:
typedef std::pair< const std::string , std::string > lp_type;
^ note the added const
The key element in the map pair is const-qualified.
It would be a bit cleaner to use the value_type typedef; this way you don't repeat the type information:
typedef std::map<std::string, std::string> map_t;
map_t matrix_int;
BOOST_FOREACH(map_t::value_type& row, matrix_int){
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With