[alogrithm] compile error with VS2008 in debug build (boost 1.38)

Hello, I have a strange problem. When I make a debug build from my program which uses minmax_element I get the following compile error: 1>c:\program files\microsoft visual studio 9.0\vc\include\utility(57) : error C2664: 'std::_Vector_iterator<_Ty,_Alloc>::_Vector_iterator(const std::_Vector_iterator<_Ty,_Alloc> &)' : cannot convert parameter 1 from 'int *const ' to 'const std::_Vector_iterator<_Ty,_Alloc> &' 1> with 1> [ 1> _Ty=int, 1> _Alloc=std::allocator<int> 1> ] 1> Reason: cannot convert from 'int *const ' to 'const std::_Vector_iterator<_Ty,_Alloc>' 1> with 1> [ 1> _Ty=int, 1> _Alloc=std::allocator<int> 1> ] 1> No constructor could take the source type, or constructor overload resolution was ambiguous 1> d:\projects\sandbox\boosttests\statistic\statistic.cpp(43) : see reference to function template instantiation 'std::pair<_Ty1,_Ty2>::pair<int*,int*>(const std::pair<int *,int *> &)' being compiled 1> with 1> [ 1> _Ty1=std::_Vector_iterator<int,std::allocator<int>>, 1> _Ty2=std::_Vector_iterator<int,std::allocator<int>> 1> ] 1>c:\program files\microsoft visual studio 9.0\vc\include\utility(57) : error C2664: 'std::_Vector_iterator<_Ty,_Alloc>::_Vector_iterator(const std::_Vector_iterator<_Ty,_Alloc> &)' : cannot convert parameter 1 from 'int *const ' to 'const std::_Vector_iterator<_Ty,_Alloc> &' 1> with 1> [ 1> _Ty=int, 1> _Alloc=std::allocator<int> 1> ] 1> Reason: cannot convert from 'int *const ' to 'const std::_Vector_iterator<_Ty,_Alloc>' 1> with 1> [ 1> _Ty=int, 1> _Alloc=std::allocator<int> 1> ] 1> No constructor could take the source type, or constructor overload resolution was ambiguous Is this a know issue. Is something wrong in my program? Best regards Hansjörg #include <algorithm> #include <vector> #include <iostream> #include <boost/algorithm/minmax_element.hpp> #include <boost/array.hpp> #include <boost/timer.hpp> using namespace boost; using namespace std; typedef array<int,100000000> dataarray; void do_tests(dataarray& data) { { timer t; std::pair< std::vector<int>::iterator, std::vector<int>::iterator > result = boost::minmax_element(data.begin(), data.end()); cout<<"min_max: minmax_element:"<<t.elapsed()<<endl; cout<<"minVal="<<*result.first<<",maxVal="<<*result.second<<endl; } } dataarray data; int main(int argc, char const* const* argv) { cout << "sorted array:" << endl; for(unsigned int i = 0; i< data.size();i++) { data[i] = i; } do_tests(data); cout << "random array:" << endl; std::srand(0); for(unsigned int i = 0; i< data.size();i++) { data[i] = std::rand(); } do_tests(data); return 0; }

On Wed, Feb 18, 2009 at 12:52:38PM +0100, Hansi wrote:
Is something wrong in my program?
Yes:
This line should be std::pair< dataarray::iterator, dataarray::iterator > result = boost::minmax_element(data.begin(), data.end()); minmax_element might be clever, but it can't magically turn boost::array's iterators into std::vector's iterators. -- Always crash crash crash Well come on and let me know You're happy when I'm running bash Should I play or should I code? One test is fine, next is black (with apologies to The Clash) So if you want a dodgy hack worse at http://surreal.istic.org/songs

I believe both iterators would be int* but a debut build might strengthen vectors iterators with bounds checking and stuff so it no longer is an int*. HB Sent from my iPhone On Feb 18, 2009, at 10:06 AM, Hansi <hansipet@web.de> wrote:
participants (4)
-
Andrey Semashev
-
Daniel Hulme
-
Hansi
-
Herve Bronnimann