|
Boost Users : |
Subject: Re: [Boost-users] [MultiIndex] is it possible to create multi-key key-extractors?
From: Mostafa (mostafa_working_away_at_[hidden])
Date: 2010-08-08 22:28:55
On Sun, 08 Aug 2010 17:29:49 -0700, Steven Watanabe <watanabesj_at_[hidden]>
wrote:
> AMDG
>
> Mostafa wrote:
>> For the following struct:
>>
>> struct Flower
>> {
>> int type;
>> string name;
>> std::list<string> aliases;
>> };
>>
>> I want to create a multiindexed container that indexes Flower objects
>> by type, name, and aliases, where aliases is some iteratable collection
>> of strings. I just don't know if it's possible to create a multi-key
>> key-extractor for aliases. So far I've come up with the following:
>
> I assume that you want to be able to look up
> the Flower from a string, which should be
> one of the aliases? You can't do this with
> multi-index.
Yes.
> A single object corresponds to a single key.
That's pretty much what I figured from the documentation, I was just
hoping for some kind of workaround that I might have missed.
Well, here goes a feature request ... (A rough outline.)
I propose adding a key-extractorS concept to the multi-index library.
Something along the lines of the existing key-extractor concept, modified
such that
key_extractorS::result_type is a Boost.Range of keys
and providing adaptor classes for creating such a Range from
multi_index::value_type member variables, methods ..., (basically a
key-extractorS counterpart for the equivalent existing key-extractors,
where approriate of course).
The motivation for this request is that a multi-index element can be
indexed by a collection of values associated with that element.
As an example: (rehashing from previous posts)
struct Flower
{
int getType() const;
string name;
std::list<string> aliases;
};
struct Nursery
{
std::list<Flower *> flowers;
};
1) a multi-index of Flower objects each indexed by an alias from
Flower::aliases,
2.1) a multi-index of Nursery objects each indexed by an alias from
Nursery::flowers.aliases,
2.2) and and also indexed by Nursery::flowers.getType()
Does this make sense? Should this be a new post, and if so should it be
posted in the dev's group?
Thanks,
-Mostafa
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