Frederic Bouvier schrieb: > Hi Stefan, > > ----- "Stefan C. Müller" a écrit : > >> Small patch fixing bugs I've encountered while getting the current CVS >> to build in MSVC. >> * std::lower_bound was used with the key-type of a map, but >> lower_bound expects the value-type of the collection it works on, with is >> std::pair. MSVC seems to be more strict about this. >> > > As far as I can tell, this is not true. The third parameter type is > independant from the type of the container, and should only match the type of > the second parameter of the predicate. The current code compile under MSVC > 7.1 and under MSVC 9.0. Looking at the lower_bound code in the MSVC 8 > <algorithm>, I think it is the same for VS2005. > What is your msvc version, and what is the error message you are seeing ? > > -Fred I'm using VC Express 2005 (SP1). I must say I was rather confused to see that this does not work in MSVC. I tracked it down into xutility and found that the error was actually caused by debugging code that will later be thrown away be the optimizer anyway. Heres the part:
template<class _Pr, class _Ty1, class _Ty2> inline bool __CLRCALL_OR_CDECL _Debug_lt_pred(_Pr _Pred, _Ty1& _Left, const _Ty2& _Right, const wchar_t *_Where, unsigned int _Line) { // test if _Pred(_Left, _Right) and _Pred is strict weak ordering if (!_Pred(_Left, _Right)) return (false); else if (_Pred(_Right, _Left)) // THIS IS LINE 314 (see error message) _DEBUG_ERROR2("invalid operator<", _Where, _Line); return (true); } It checks if the predicate (orderingFunctor) is commutative. The _DEBUG_ERROR2 macro seems to lead into an emtpy function, so it has no effect at the end but caused the build to fail. The _Left is the result of dereferencing an iterator (with leads to std::pair) and _Right is the string given to lower_bound. Who ever wrote this code had a vector or a list in mind and not a map. I see two ways to work around this, the one I've chosen most certainly fixes the problem on all possible implementations of std::lower_bound. The other is to overload the operator() in the functor for all tree parameter combinations operator()(std::pair, std::string), operator()(std::string, std::pair) and operator()(std::pair,std::pair) (the pair,pair is required because of another debugging check in VC's implementation). But this is even more ugly and might still break on other c++ suites. Maybe you find a better way to do this. Having a dirty hack as my first contribution is not exactly what I hoped for :-) Heres the complete error message (for the one in fixlist.cpp) The messages are in german, sorry for that, I don't know how to get rid of the localization. fixlist.cxx 1>c:\programme\microsoft visual studio 8\vc\include\xutility(314) : error C2664: 'bool orderingFunctor::operator ()(const std::pair<_Ty1,_Ty2> &,const std::string &) const': Konvertierung des Parameters 1 von 'const std::string' in 'const std::pair<_Ty1,_Ty2> &' nicht möglich 1> with 1> [ 1> _Ty1=const std::string, 1> _Ty2=FGFix 1> ] 1> Ursache: Konvertierung von 'const std::string' in 'const std::pair<_Ty1,_Ty2>' nicht möglich 1> with 1> [ 1> _Ty1=const std::string, 1> _Ty2=FGFix 1> ] 1> Kein benutzerdefinierter Konvertierungsoperator verfügbar, der diese Konvertierung durchführen kann, oder der Operator kann nicht aufgerufen werden 1> c:\programme\microsoft visual studio 8\vc\include\algorithm(2304): Siehe Verweis auf die Instanziierung der gerade kompilierten Funktions-template "bool std::_Debug_lt_pred<_Pr,std::pair<_Ty1,_Ty2>,_Ty>(_Pr,std::pair<_Ty1,_Ty2> &,const std::basic_string<_Elem,_Traits,_Ax> &,const wchar_t *,unsigned int)". 1> with 1> [ 1> _Pr=orderingFunctor, 1> _Ty1=const std::string, 1> _Ty2=FGFix, 1> _Ty=std::string, 1> _Elem=char, 1> _Traits=std::char_traits<char>, 1> _Ax=std::allocator<char> 1> ] 1> c:\programme\microsoft visual studio 8\vc\include\algorithm(2318): Siehe Verweis auf die Instanziierung der gerade kompilierten Funktions-template "_FwdIt std::_Lower_bound<std::_Tree<_Traits>::iterator,_Ty,__w64 int,_Pr>(_FwdIt,_FwdIt,const _Ty &,_Pr,_Diff *)". 1> with 1> [ 1> _FwdIt=std::_Tree<std::_Tmap_traits<std::string,FGFix,std::less<std::string>,std::allocator<std::pair<const std::string,FGFix>>,true>>::iterator, 1> _Traits=std::_Tmap_traits<std::string,FGFix,std::less<std::string>,std::allocator<std::pair<const std::string,FGFix>>,true>, 1> _Ty=std::string, 1> _Pr=orderingFunctor, 1> _Diff=__w64 int 1> ] 1> d:\projects\flightgear\buildenv\flightgear\src\navaids\fixlist.cxx(158): Siehe Verweis auf die Instanziierung der gerade kompilierten Funktions-template "_FwdIt std::lower_bound<std::_Tree<_Traits>::iterator,std::string,orderingFunctor>(_FwdIt,_FwdIt,const _Ty &,_Pr)". 1> with 1> [ 1> _FwdIt=std::_Tree<std::_Tmap_traits<std::string,FGFix,std::less<std::string>,std::allocator<std::pair<const std::string,FGFix>>,true>>::iterator, 1> _Traits=std::_Tmap_traits<std::string,FGFix,std::less<std::string>,std::allocator<std::pair<const std::string,FGFix>>,true>, 1> _Ty=std::string, 1> _Pr=orderingFunctor 1> ] ------------------------------------------------------------------------- This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100&url=/ _______________________________________________ Flightgear-devel mailing list Flightgear-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/flightgear-devel