why BOOST_FOREACH cannot handle const boost::ptr_map?
Posted
by psaghelyi
on Stack Overflow
See other posts from Stack Overflow
or by psaghelyi
Published on 2010-04-13T13:50:26Z
Indexed on
2010/04/13
13:53 UTC
Read the original article
Hit count: 235
for-each
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...
© Stack Overflow or respective owner