c++ - STL lower_bound not spec compliant -
the following code doesn't compile in c++builder 2009 or in visual c++ 2005 when macro _has_iterator_debugging
equals 1
if commented out will. appears lower_bound
function isn't spec compliant. library swapping arguments. here's excerpt form spec. value
should second argument. wrong?
note: test code wasn't designed run. designed illustrate library bug.
c++ spec excerpt
template<class forwarditerator, class t, class compare> forwarditerator lower_bound(forwarditerator first, forwarditerator last, const t& value, compare comp);
25.3.3.1.3
returns: furthermost iterator in range [first, last] such iterator j in range [first, i) following corresponding conditions hold: *j < value or comp(*j, value) != false
visual studio error message
msg: error c2664: 'double mike::operator ()(const double,const char *) const' : cannot convert parameter 1 'const char [1]' 'const double'
file: c:\program files\microsoft visual studio 8\vc\include\xutility
line no: 314
test code
#define _has_iterator_debugging 1 // needs in stdafx.h file visual studio #include "stdafx.h" #include <algorithm> #include <functional> struct mike : public std::binary_function<double, char*, double> { double operator() (const double i, const char*) const { return i; } }; int main() { double r[] = {0}; std::lower_bound(r, r, "", mike()); return 0; }
this known issue in visual c++ 2005 c++ standard library implementation (see "binary predicate paramter lower_bound
assumes both parameters same type when compiling in debug mode" on microsoft connect).
the bug fixed in visual c++ 2008.
Comments
Post a Comment