Есть незатейливый код:
#include "map"
#include "set"
typedef std::map<int, int*> map_elements;
struct less_id
{
bool operator()(const map_elements::value_type& rval, int rs) const
{ return m_Less(rval.first, rs); }
bool operator()(int rs, const map_elements::value_type& rval) const
{ return m_Less(rs, rval.first); }
private:
std::less<int> m_Less;
};
void main()
{
map_elements elements;
std::set<int> subelements;
std::vector<int> elem_deleted;
std::set_difference(
subelements.begin(), subelements.end(),
elements.begin(), elements.end(),
std::back_inserter(elem_deleted), less_id()); // line 841
}
Который компилируется в релизе и не компилируется в дебаге.
Почему так происходит и как можно обойти?
Ошибки VS80SP1 в дебаге:
d:\program files\microsoft visual studio 8\vc\include\xutility(323) : error C2664: 'bool less_id::operator ()(const int,const std::pair<_Ty1,_Ty2> &) const' : cannot convert parameter 2 from 'int' to 'const std::pair<_Ty1,_Ty2> &'
with
[
_Ty1=const int,
_Ty2=int *
]
Reason: cannot convert from 'int' to 'const std::pair<_Ty1,_Ty2>'
with
[
_Ty1=const int,
_Ty2=int *
]
No constructor could take the source type, or constructor overload resolution was ambiguous
d:\program files\microsoft visual studio 8\vc\include\xutility(1449) : see reference to function template instantiation 'bool std::_Debug_lt_pred<_Pr,int,int>(_Pr,_Ty1 &,_Ty2 &,const wchar_t *,unsigned int)' being compiled
with
[
_Pr=less_id,
_Ty1=int,
_Ty2=int
]
d:\program files\microsoft visual studio 8\vc\include\xutility(1460) : see reference to function template instantiation 'void std::_Debug_order2<_InIt,_Pr>(_FwdIt,_FwdIt,_Pr,const wchar_t *,unsigned int,std::forward_iterator_tag)' being compiled
with
[
_InIt=std::_Tree<std::_Tset_traits<int,std::less<int>,std::allocator<int>,false>>::iterator,
_Pr=less_id,
_FwdIt=std::_Tree<std::_Tset_traits<int,std::less<int>,std::allocator<int>,false>>::iterator
]
d:\program files\microsoft visual studio 8\vc\include\algorithm(4161) : see reference to function template instantiation 'void std::_Debug_order<_InIt1,_Pr>(_InIt,_InIt,_Pr,const wchar_t *,unsigned int)' being compiled
with
[
_InIt1=std::_Tree<std::_Tset_traits<int,std::less<int>,std::allocator<int>,false>>::iterator,
_Pr=less_id,
_InIt=std::_Tree<std::_Tset_traits<int,std::less<int>,std::allocator<int>,false>>::iterator
]
d:\program files\microsoft visual studio 8\vc\include\algorithm(4185) : see reference to function template instantiation '_OutIt std::_Set_difference<std::_Tree<_Traits>::iterator,std::_Tree<std::_Tmap_traits<_Kty,_Ty,_Pr,_Alloc,_Mfl>>::iterator,_OutIt,less_id>(_InIt1,_InIt1,_InIt2,_InIt2,_OutIt,less_id,std::_Range_checked_iterator_tag)' being compiled
with
[
_OutIt=std::back_insert_iterator<vec_deleted_type>,
_Traits=std::_Tset_traits<int,std::less<int>,std::allocator<int>,false>,
_Kty=int,
_Ty=int *,
_Pr=std::less<int>,
_Alloc=std::allocator<std::pair<const int,int *>>,
_Mfl=false,
_InIt1=std::_Tree<std::_Tset_traits<int,std::less<int>,std::allocator<int>,false>>::iterator,
_InIt2=std::_Tree<std::_Tmap_traits<int,int *,std::less<int>,std::allocator<std::pair<const int,int *>>,false>>::iterator
]
d:\myprojects\test2005\test2005\test2005.cpp(841) : see reference to function template instantiation 'std::back_insert_iterator<_Container> std::set_difference<std::_Tree<_Traits>::iterator,std::_Tree<std::_Tmap_traits<_Kty,_Ty,_Pr,_Alloc,_Mfl>>::iterator,std::back_insert_iterator<_Container>,less_id>(_InIt1,_InIt1,_InIt2,_InIt2,_OutIt,less_id)' being compiled
with
[
_Container=vec_deleted_type,
_Traits=std::_Tset_traits<int,std::less<int>,std::allocator<int>,false>,
_Kty=int,
_Ty=int *,
_Pr=std::less<int>,
_Alloc=std::allocator<std::pair<const int,int *>>,
_Mfl=false,
_InIt1=std::_Tree<std::_Tset_traits<int,std::less<int>,std::allocator<int>,false>>::iterator,
_InIt2=std::_Tree<std::_Tmap_traits<int,int *,std::less<int>,std::allocator<std::pair<const int,int *>>,false>>::iterator,
_OutIt=std::back_insert_iterator<vec_deleted_type>
]
d:\program files\microsoft visual studio 8\vc\include\xutility(325) : error C2664: 'bool less_id::operator ()(const int,const std::pair<_Ty1,_Ty2> &) const' : cannot convert parameter 2 from 'int' to 'const std::pair<_Ty1,_Ty2> &'
with
[
_Ty1=const int,
_Ty2=int *
]
Reason: cannot convert from 'int' to 'const std::pair<_Ty1,_Ty2>'
with
[
_Ty1=const int,
_Ty2=int *
]
No constructor could take the source type, or constructor overload resolution was ambiguous
d:\program files\microsoft visual studio 8\vc\include\xutility(323) : error C2664: 'bool less_id::operator ()(const int,const std::pair<_Ty1,_Ty2> &) const' : cannot convert parameter 1 from 'std::pair<_Ty1,_Ty2>' to 'const int'
with
[
_Ty1=const int,
_Ty2=int *
]
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
d:\program files\microsoft visual studio 8\vc\include\xutility(1449) : see reference to function template instantiation 'bool std::_Debug_lt_pred<_Pr,std::pair<_Ty1,_Ty2>,std::pair<_Ty1,_Ty2>>(_Pr,std::pair<_Ty1,_Ty2> &,std::pair<_Ty1,_Ty2> &,const wchar_t *,unsigned int)' being compiled
with
[
_Pr=less_id,
_Ty1=const int,
_Ty2=int *
]
d:\program files\microsoft visual studio 8\vc\include\xutility(1460) : see reference to function template instantiation 'void std::_Debug_order2<_InIt,_Pr>(_FwdIt,_FwdIt,_Pr,const wchar_t *,unsigned int,std::forward_iterator_tag)' being compiled
with
[
_InIt=std::_Tree<std::_Tmap_traits<int,int *,std::less<int>,std::allocator<std::pair<const int,int *>>,false>>::iterator,
_Pr=less_id,
_FwdIt=std::_Tree<std::_Tmap_traits<int,int *,std::less<int>,std::allocator<std::pair<const int,int *>>,false>>::iterator
]
d:\program files\microsoft visual studio 8\vc\include\algorithm(4162) : see reference to function template instantiation 'void std::_Debug_order<_InIt2,_Pr>(_InIt,_InIt,_Pr,const wchar_t *,unsigned int)' being compiled
with
[
_InIt2=std::_Tree<std::_Tmap_traits<int,int *,std::less<int>,std::allocator<std::pair<const int,int *>>,false>>::iterator,
_Pr=less_id,
_InIt=std::_Tree<std::_Tmap_traits<int,int *,std::less<int>,std::allocator<std::pair<const int,int *>>,false>>::iterator
]
d:\program files\microsoft visual studio 8\vc\include\xutility(325) : error C2664: 'bool less_id::operator ()(const int,const std::pair<_Ty1,_Ty2> &) const' : cannot convert parameter 1 from 'std::pair<_Ty1,_Ty2>' to 'const int'
with
[
_Ty1=const int,
_Ty2=int *
]
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called