std::lower_bound не компилируется в Debug
От: bobik1  
Дата: 10.12.11 00:38
Оценка:
Подскажите, почему этот пример кода:
#include <algorithm>
#include <vector>

struct MyStruct
{
    unsigned id;

    MyStruct(unsigned _id) : id(_id)
    {
    }
    
    MyStruct() : id(0)
    {
    }

    bool operator<(const MyStruct &right) const
    {
        return id < right.id;
    }
};


int main (int argc, char *argv[])
{
    std::vector<MyStruct> vec;
    unsigned val = 0;
    
    std::vector<MyStruct>::iterator it = std::lower_bound(vec.begin(), vec.end(), val);
    
    return 0;
}

не компилируется в Debug, а в Release все нормально. Компилятор — VS 2008.

Вот какие ошибки высыпаются в Debug:
1>c:\program files\microsoft visual studio 9.0\vc\include\xutility(285) : error C2784: bool std::operator <(const std::vector<_Ty,_Alloc> &,const std::vector<_Ty,_Alloc> &): не удалось вывести аргумент шаблон для "const std::vector<_Ty,_Alloc> &" из "const unsigned int"
1> c:\program files\microsoft visual studio 9.0\vc\include\vector(1322): см. объявление 'std::operator <'
1> c:\program files\microsoft visual studio 9.0\vc\include\algorithm(2264): см. ссылку на создание экземпляров функции шаблон при компиляции "bool std::_Debug_lt<MyStruct,_Ty>(_Ty1 &,const _Ty2 &,const wchar_t *,unsigned int)"
1> with
1> [
1> _Ty=unsigned int,
1> _Ty1=MyStruct,
1> _Ty2=unsigned int
1> ]
1> c:\program files\microsoft visual studio 9.0\vc\include\algorithm(2276): см. ссылку на создание экземпляров функции шаблон при компиляции "_FwdIt std::_Lower_bound<std::_Vector_iterator<_Ty,_Alloc>,unsigned int,__w64 int>(_FwdIt,_FwdIt,const unsigned int &,_Diff *)"
1> with
1> [
1> _FwdIt=std::_Vector_iterator<MyStruct,std::allocator<MyStruct>>,
1> _Ty=MyStruct,
1> _Alloc=std::allocator<MyStruct>,
1> _Diff=__w64 int
1> ]
1> e:\develop\cpp\test\test\test.cpp(28): см. ссылку на создание экземпляров функции шаблон при компиляции "_FwdIt std::lower_bound<std::_Vector_iterator<_Ty,_Alloc>,unsigned int>(_FwdIt,_FwdIt,const unsigned int &)"
1> with
1> [
1> _FwdIt=std::_Vector_iterator<MyStruct,std::allocator<MyStruct>>,
1> _Ty=MyStruct,
1> _Alloc=std::allocator<MyStruct>
1> ]
1>c:\program files\microsoft visual studio 9.0\vc\include\xutility(285) : error C2784: bool std::operator <(const std::reverse_iterator<_RanIt> &,const std::reverse_iterator<_RanIt2> &): не удалось вывести аргумент шаблон для "const std::reverse_iterator<_RanIt> &" из "const unsigned int"
1> c:\program files\microsoft visual studio 9.0\vc\include\xutility(2262): см. объявление 'std::operator <'
1>c:\program files\microsoft visual studio 9.0\vc\include\xutility(285) : error C2784: bool std::operator <(const std::_Revranit<_RanIt,_Base> &,const std::_Revranit<_RanIt2,_Base2> &): не удалось вывести аргумент шаблон для "const std::_Revranit<_RanIt,_Base> &" из "const unsigned int"
1> c:\program files\microsoft visual studio 9.0\vc\include\xutility(2072): см. объявление 'std::operator <'
1>c:\program files\microsoft visual studio 9.0\vc\include\xutility(285) : error C2784: bool std::operator <(const std::pair<_Ty1,_Ty2> &,const std::pair<_Ty1,_Ty2> &): не удалось вывести аргумент шаблон для "const std::pair<_Ty1,_Ty2> &" из "const unsigned int"
1> c:\program files\microsoft visual studio 9.0\vc\include\utility(99): см. объявление 'std::operator <'
1>c:\program files\microsoft visual studio 9.0\vc\include\xutility(285) : error C2677: бинарный '<': не найден глобальный оператор, принимающий тип 'MyStruct' (или приемлемое преобразование отсутствует)
lower_bound c2784
 
Подождите ...
Wait...
Пока на собственное сообщение не было ответов, его можно удалить.