|
Boost Users : |
Subject: Re: [Boost-users] [MultiIndex] Indexing integers
From: Sensei (senseiwa_at_[hidden])
Date: 2014-07-29 11:26:39
As Joaquín helped me out, I'm currently using his solution to test multi
index containers.
Playing with that, I'm now moving to hashed indices and 128 bits
integers, just for fun.
So now, in my class Data, I have a 128bit integer, indexed by
most/half/least significant bits, with access functions. It works
nicely. I added a fourth index, a hashed one, hashed by the MSB, and now
I'd like to access all items that have MSB equal to 3, for instance.
You will find my badly-written code below.
Following the example [1], I proceeded in defining the index type, but
here my compiler throws me two errors:
error: missing 'typename' prior to dependent type name
'DataWithIndices::nth_index'
^
and
error: expected unqualified-id
typedef DataWithIndices::nth_index<3>::type byHashedIndex;
^
So I followed the suggestion and used typename, but an error is there:
error: use 'template' keyword to treat 'nth_index' as a dependent
template name
typedef typename DataWithIndices::nth_index<3>::type byHashedIndex;
^
Again, I follow the suggestion, use template and it works. Adding the
following line from the example gives me an error:
error: expected expression
byHashedIndex &p = multiIndex_.get<3>();
^
error: declaration of reference variable 'p' requires an initializer
byHashedIndex &p = multiIndex_.get<3>();
^
Sincerely, I think I'm translating the example in a right manner, but
obviously I am not.
Can you help me? I am learning still, so please excuse me if this is
trivial!
Thanks & Cheers!
=== CODE ===
typedef boost::multi_index::multi_index_container<
__uint128_t,
boost::multi_index::indexed_by<
boost::multi_index::ordered_non_unique<boost::multi_index::global_fun<__uint128_t,
uint64, &Data::msb>>,
boost::multi_index::ordered_non_unique<boost::multi_index::global_fun<__uint128_t,
uint64, &Data::hsb>>,
boost::multi_index::ordered_non_unique<boost::multi_index::global_fun<__uint128_t,
uint64, &Data::lsb>>,
boost::multi_index::hashed_non_unique<boost::multi_index::global_fun<__uint128_t,
uint64, &Data::msb>>
>
> DataWithIndices;
DataWithIndices multiIndex_;
void objs()
{
typedef typename DataWithIndices::template nth_index<3>::type
byHashedIndex;
byHashedIndex &p = multiIndex_.get<3>();
}
[1]
http://www.boost.org/doc/libs/1_55_0/libs/multi_index/doc/tutorial/indices.html#hash_lookup
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