Re: operator< for algorithms
Hicham Mouline wrote:
"Hicham Mouline" <hicham@mouline.org> wrote in message
news:49d4d773$0$90275$14726298@news.sunsite.dk...
It doesn't seem to work
template<class T, class U>
bool operator<(const typename C<T,U>::EntryType& lhs,
const typename C<T,U>::EntryType& rhs)
{
std::cout<< "called" <<std::endl;
return true;
}
never prints anything
I just realized c++03 defines operators< for std::pair<> in std.
Maybe I need to override those
rds,
still doesn't wor, strange
http://codepad.org/h9uFoI1I
Hm...
I tried redefining your type 'EntryType' as derived from 'std::pair',
and it didn't help either.
I don't know. Apparently the compiler is unable to resolve it (or
instantiate the template) and if falls back on what it can do, the
operator < for std::pair...
I think you should resort to a named function/functor:
template<class T, class U>
bool op_less(const typename NS1::NS2::C<T,U>::EntryType& lhs,
const typename NS1::NS2::C<T,U>::EntryType& rhs)
{
std::cout<< "called" <<std::endl;
return true;
}
....
template<typename T1, typename T2>
void C<T1, T2>::FindX(xType x) const
{
std::cout<< "inside Find"<<std::endl;
if ( op_less<T1,T2>(mContainer[0], mContainer[1]) )
{
std::cout<<" 0 < 1 "<<std::endl;
}
if ( op_less<T1,T2>(mContainer[1], mContainer[0]) )
{
std::cout<<" 1 < 0 "<<std::endl;
}
}
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask