Boost logo

Boost Users :

Subject: Re: [Boost-users] boost::multi_index
From: Dominique Devienne (ddevienne_at_[hidden])
Date: 2011-04-07 10:20:09

On Wed, Apr 6, 2011 at 1:54 PM, <ppatel_at_[hidden]> wrote:
> I have a question regarding creating composite key/specifying length for
> arrays while using multi_index container based on following structure.
> struct TestStruct {
>                 char firstKey[50];
>                 char secondKeyPart[3];
>                 uint32_t thirdKeyPart;
>                 ……Some other information….
> };

Using a composite key and associated hasher/equalTo types yields some
pretty long (and ugly?) types for the multi-index
container/extractor/hasher/equaler. If "……Some other information…." is
not too large such that TestStruct is not too expensive to construct,
you're often better of using the identity key extractor, and implement
the hasher and op== in terms of TestStruct itself. The only downside I
see is that you must constructs a whole new TestStruct when you want
to look one up instead of doing a make_tuple(part1, part2, part3),
which is why I mentioned above "if TestStruct is not too expensive to
construct". This is the route we followed, away from composite keys
and into custom hasher/equaler of our own structs. Not sure if Joaquin
also recommend that route, but it worked fine for us and makes things
simpler IMHO. --DD

PS: Note that the custom hash/equal functors end up being equivalent
hand-written versions of the template-based composite_key_* types
would have been, but then it's simple straight forward code which is
easier to understand when you debug too.

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at