Hello,
My code is using std::count() on a list of an abstract data type that i have defined. (Sommet or Edge in english). But it doesn't work, although i've overloaded the < and == operators like this :
bool operator< (const Sommet &left, const Sommet &right)
{
if(left.m_id_sommet < right.m_id_sommet)
return true;
return false;
}
bool operator== (const Sommet &left, const Sommet &right)
{
if(left.m_id_sommet == right.m_id_sommet)
return true;
return false;
}
Just notice that this worked using std::sort() and std::unique().
The errors are:
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_algo.h: In function 'typename std::iterator_traits<_Iterator>::difference_type std::count(_InputIterator, _InputIterator, const _Tp&) [with _InputIterator = __gnu_cxx::__normal_iterator<Sommet*, std::vector<Sommet, std::allocator<Sommet> > >, _Tp = __gnu_cxx::__normal_iterator<Sommet*, std::vector<Sommet, std::allocator<Sommet> > >]':
Graphe.cpp:43: instantiated from here
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_algo.h:422: error: no match for 'operator==' in '__first.__gnu_cxx::__normal_iterator<_Iterator, _Container>::operator* [with _Iterator = Sommet*, _Container = std::vector<Sommet, std::allocator<Sommet> >]() == __value'
Sommet.h:7: note: candidates are: bool operator==(const Sommet&, const Sommet&)
Thanks !
EDIT
This is how i used std::count() :
for(vector<Sommet>::iterator iter = m_sommets.begin();
iter != s_iter_end; iter++)
{
iter->SetNbSuccesseurs(count(m_sommets.begin(), m_sommets.end(), iter));
}