Boost logo

Boost Users :

From: JOAQUIN LOPEZ MU?Z (joaquin_at_[hidden])
Date: 2006-12-28 10:46:18


Hello David,

----- Mensaje original -----
De: David Brownell <david_brownell_at_[hidden]>
Fecha: Jueves, Diciembre 28, 2006 9:02 am
Asunto: [Boost-users] [Multi-Index] find returning false positives?
Para: boost-users_at_[hidden]

> When comparing the results of the find method to the end iterator
> in the code below, it appears that find is finding elements that
> are not in the container. Am I using multi-index in the
> wrong way?
>
> Thanks for the help!
[...]
> struct CompareFunc
> {
> bool operator()(MyObject const &o, int i) const
> { return(i == o.Get());}
> bool operator()(int i, MyObject const &o) const
> { return(o.Get() == i);}
> };

Here's the problem: your comparison functor must have
less-than rather than equality semantics. Try rewriting it
as follows:

struct CompareFunc
{
   bool operator()(MyObject const &o, int i) const
   { return(o.Get() < i);}
   bool operator()(int i, MyObject const &o) const
   { return(i < o.Get());}
};

Hope this helps. Thank you for using Boost.MultiIndex.

Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net