Code: Select all
bool ZeroKey ( const hash_map<int,int>::value_type & v )
{
return v.first==0;
}
hash_map<int,int> h;
find_if( h.begin(), h.end(), ZeroKey );
h.erase( remove_if( h.begin(), h.end(), ZeroKey ), h.end() ); // not compiled
Code: Select all
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\algorithm(492) : error C2582: 'operator =' 함수는 'std::pair<_Ty1,_Ty2>'에서 사용할 수 없습니다.
with
[
_Ty1=const int,
_Ty2=int
]
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\algorithm(522) : 컴파일 중인 함수 템플릿 인스턴스화 '_OutIt std::remove_copy_if<std::_Tree<_Traits>::iterator,_FwdIt,bool(__cdecl *)(const stdext::hash_map<_Kty,_Ty>::value_type &)>(_InIt,_InIt,_OutIt,_Pr)'에 대한 참조를 확인하십시오.
with
[
_OutIt=std::_Tree<std::_Tmap_traits<int,int,std::less<int>,std::allocator<std::pair<const int,int>>,false>>::iterator,
_Traits=std::_Tmap_traits<int,int,std::less<int>,std::allocator<std::pair<const int,int>>,false>,
_FwdIt=std::_Tree<std::_Tmap_traits<int,int,std::less<int>,std::allocator<std::pair<const int,int>>,false>>::iterator,
_Kty=int,
_Ty=int,
_InIt=std::_Tree<std::_Tmap_traits<int,int,std::less<int>,std::allocator<std::pair<const int,int>>,false>>::iterator,
_Pr=bool (__cdecl *)(const stdext::hash_map<int,int>::value_type &)
]
d:\Works\equalto\equalto\equalto.cpp(228) : 컴파일 중인 함수 템플릿 인스턴스화 '_FwdIt std::remove_if<std::_Tree<_Traits>::iterator,bool(__cdecl *)(const stdext::hash_map<_Kty,_Ty>::value_type &)>(_FwdIt,_FwdIt,_Pr)'에 대한 참조를 확인하십시오.
with
[
_FwdIt=std::_Tree<std::_Tmap_traits<int,int,std::less<int>,std::allocator<std::pair<const int,int>>,false>>::iterator,
_Traits=std::_Tmap_traits<int,int,std::less<int>,std::allocator<std::pair<const int,int>>,false>,
_Kty=int,
_Ty=int,
_Pr=bool (__cdecl *)(const stdext::hash_map<int,int>::value_type &)
]
const 에다가 대입을 하려고 해서 생기는 에러인 것 같습니다.
그래서 여기 저기 찾아보니까 map 이나 set 류의 associative container 에다가는
remove_if 를 사용할 수 없다는 뉘앙스의 글들이 종종 보이는데,
쓸 수 없다는 명백한 문장은 찾을 수 없었습니다.
정말 쓸 수 없는게 맞을까요?