why BOOST_FOREACH cannot handle const boost::ptr_map?
- by psaghelyi
void main()
{
typedef boost::ptr_map<int, char> MyMap;
MyMap mymap;
mymap[1] = 'a';
mymap[2] = 'b';
mymap[3] = 'c';
BOOST_FOREACH(MyMap::value_type value, mymap)
{
std::cout << value.first << " " << value.second << std::endl;
}
MyMap const & const_mymap = mymap;
BOOST_FOREACH(MyMap::value_type value, const_mymap)
{
std::cout << value.first << " " << value.second << std::endl;
}
}
The following error message comes from GCC at the second BOOST_FOREACH
error: conversion from 'boost::ptr_container_detail::ref_pair<int, const char* const>' to non-scalar type 'boost::ptr_container_detail::ref_pair<int, char* const>' requested
I reckon that this is the weakness of the pointer container's ref_pair...