I was trying to use remove_if template for a map container but I am getting compiler error for the template argument. I am unable to understand why.
int main()
{
map<const int, int> intmap;
intmap[1] = 1;
intmap[2] = 2;
intmap[3] = 3;
intmap[4] = 4;
auto isOdd = [&](pair<const int, int> it)->bool
{ return static_cast<bool>(it.second % 2); };
isOdd(*(intmap.begin()));
remove_if(intmap.begin(), intmap.end(), isOdd);
}
This remove_if is throwing compiler errors. Any suggestion to fix it?
Error message is
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\utility(260) : error C2166: l-value specifies const object
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\utility(259) : while compiling class template member function
'std::pair<_Ty1,_Ty2> &std::pair<_Ty1,_Ty2>::operator =(std::pair<_Ty1,_Ty2> &&)'
with
[
_Ty1=const int,
_Ty2=int
]
maperaseif.cpp(29) : see reference to class template instantiation 'std::pair<_Ty1,_Ty2>' being compiled
with
[
_Ty1=const int,
_Ty2=int
]