Boost logo

Boost Users :

Subject: Re: [Boost-users] [MultiIndex] Indexing integers
From: Joaquin M Lopez Munoz (joaquin_at_[hidden])
Date: 2014-07-31 05:49:16


Joaquin M Lopez Munoz <joaquin <at> tid.es> writes:

>
> Sensei <senseiwa <at> gmail.com> writes:
>
> >
> > My code, actually, won't find anything with equal_range, and find will
> > return 0, although my call works in some sense, or better, the element >
> I am passing DOES exist in the container. Source and output in the
> > following.
>
> OK, some weird things are happening here, though I can only guess as
> the code you're showing is not complete. Seemingly p.equal_range(v) is
> returning an empty result (since the output does not emit any EQID). As
> for p.find(v) returning something, what's actually hapenning is that
> it is returning an iterator to end --this is why FIND outputs 0|0|0 when
> there's no such element in the container, judging from the ALL dump. This
> you can easily check by comparing u with p.end().
>
> So... my wild guess is that Data::MSB is not working properly. Could
> you please show the code for that function? (even better, could you
> post a complete compilable snippet for me to play with?)

Ok, never mind, the problem is this: lookup functions take *keys*, not
whole values, so instead of

  auto q = p.equal_range(v);

you have to write

  auto q = p.equal_range(MSB(v));

The bug goes undetected at compile time because there's a default
conversion from __uint128_t to uint64_t, but this conversion of course
does not extract the MSB part, hence the run-time problems. In more
usual scenarios where the key is a member of the element, the error
would have been more apparent and the code wouldn't have compiled.

Joaquín M López Muñoz
Telefónica


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