Boost logo

Boost Users :

Subject: Re: [Boost-users] [MultiIndex] Indexing integers
From: Joaquin M Lopez Munoz (joaquin_at_[hidden])
Date: 2014-07-20 06:55:15


Sensei <senseiwa <at> gmail.com> writes:

>
> [...]
>
> My attempt is now to use a 128bit integers, and extract MSB/LSB as
> before. The difference is using a const member function. Of course, I've
> specialized std::less for my type.

This is off-topic, but you don't need to specialize std::less for
__uint128_t because the default implementation does exactly the same
as your specialization (both use operator<).

>
> [...]
>
> From the documentation I see that I need in const_mem_fun<> in order,
> the input type, the output type, and the address of a member function, a
> const member in my case.

const_mem_fun expects a member function *of the class being inserted
into the container* (which in your case is __uint128_t), not just
any member function of some unrelated class (in your case, you're
trying to plug &Data::msb and &Data::lsb).

So, turn &Data::msb and &Data::lsb into *static* member functions
(as they're really global functions, not needing to access any
member of Data):

  static uint64_t msb(__uint128_t storage)
  {
    return static_cast<uint64_t>(storage >> 64);
  };

  static uint64_t lsb(__uint128_t storage)
  {
    return static_cast<uint64_t>(storage & 0xFFFFFFFFFFFFFFFF);
  };

and resort to global_fun rather than const_mem_fun:

  ordered_non_unique<global_fun<__uint128_t, uint64_t, &Data::msb>>,
  ordered_non_unique<global_fun<__uint128_t, uint64_t, &Data::lsb>>

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