|
Boost Users : |
Subject: Re: [Boost-users] [MultiIndex] Indexing integers
From: Sensei (senseiwa_at_[hidden])
Date: 2014-07-20 03:56:11
Thanks Joaquin, I've played with your example and I find it very useful!
Now the appetite grew and combining your example with the custom key
extractor docs you provided, I am trying to move to a single class with
a multi index member. However, I cannot compile it.
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.
The errors are puzzling to me. Here they are:
== LOG ==
In file included from Data.h:15:
/usr/local/include/boost/multi_index/mem_fun.hpp:42:50: error: member
pointer refers into non-class type 'unsigned __int128'
template<class Class,typename Type,Type
(Class::*PtrToMemberFunction)()const>
Data.h:42:32: note: while substituting prior template arguments into
non-type template parameter 'PtrToMemberFunction' [with Class = unsigned
__int128, Type = unsigned long long]
ordered_non_unique<const_mem_fun<__uint128_t, uint64_t,
&soData::msb>>,
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Data.h:42:83: error: expected a type
ordered_non_unique<const_mem_fun<__uint128_t, uint64_t,
&soData::msb>>,
^
/Users/sensei/Documents/Projects/sparql/Sparql/Sparqlo/soData.h:45:5:
error: expected a type
> soDataStorage;
^
== END ==
I must confess I cannot understand what type it expects.
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.
// sort by less<int> on name_length()
ordered_non_unique<
const_mem_fun<employee,std::size_t,&employee::name_length>
>
I believe less<> isn't a problem, since it should work on 128bit
integers with my specilization... I think!
Can anyone help me?
Thanks & Cheers!
#include <boost/multi_index_container.hpp>
#include <boost/multi_index/mem_fun.hpp>
#include <boost/multi_index/ordered_index.hpp>
#include <functional>
using namespace boost::multi_index;
namespace std {
template<>
struct less<__uint128_t>
{
bool operator()(const __uint128_t& x, const __uint128_t& y) const
{
return x < y;
}
};
};
using namespace boost::multi_index;
class Data
{
public:
Data();
uint64_t msb(__uint128_t storage) const
{
return static_cast<uint64_t>(storage >> 64);
};
uint64_t lsb(__uint128_t storage) const
{
return static_cast<uint64_t>(storage & 0xFFFFFFFFFFFFFFFF);
};
private:
typedef multi_index_container<
__uint128_t,
indexed_by<
ordered_non_unique<const_mem_fun<__uint128_t, uint64_t,
&Data::msb>>,
ordered_non_unique<const_mem_fun<__uint128_t, uint64_t,
&Data::lsb>>
>
> DataStorage;
};
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