|
Boost Users : |
Subject: Re: [Boost-users] [multi_index and flyweight]
From: Samuel Charron (chammm_at_[hidden])
Date: 2009-12-07 12:06:40
Hi,
On Fri, Dec 4, 2009 at 9:58 PM, Joaquin M Lopez Munoz <joaquin_at_[hidden]> wrote:
> Samuel Charron <samuel.charron <at> gmail.com> writes:
>
>> Hi,
>>
>> I'm currently facing some limitations from flyweight and multi_index.
>>
>> Let's begin with multi_index:
>>
>> I'd want to have a multi_index storing containers, and have one index
>> based on all the contained elements.
>> For example:
>> two vectors [1 2 3] and [3 4] would be indexed as
>> 1 -> [1 2 3]
>> 2 -> [1 2 3]
>> 3 -> [1 2 3] [3 4]
>> 4 -> [3 4]
>>
>> How would you do that ?
>
> If I'm understanding your question well, you can do like
> this:
>
> Â struct container_compare
> Â {
> Â Â template<typename Container>
> Â Â bool operator()(const Container& x,const Container& y)const
> Â Â {
> Â Â Â return std::lexicographical_compare(
> Â Â Â Â x.begin(),x.end(),
> Â Â Â Â y.begin(),y.end());
> Â Â }
> Â };
>
> Â typedef std::vector<int> value_type;
>
> Â typedef multi_index_container<
> Â Â value_type,
> Â Â indexed_by<
> Â Â Â ordered_unique<
> Â Â Â Â identity<value_type>,container_compare
> Â Â Â >
> Â Â >
> Â > multi_t;
With your solution, my containers are sorted using all their values,
it's not what I meant.
My problem is that from any element from the container, I want to be
able to retrieve the whole container.
My index type would be the element contained, and the type of element
contained in the multi_index would be the container type.
The indices inserted would be all elements from my container, and the
element would be one occurence of the container.
something like:
foreach (element in container)
multi_index.insert(element, container);
Is this a better explaination ?
>
>> Flyweight:
>> I'd like to have a scoped flyweight, without tracking, i.e.:
>> {
>> Â ... // create some elements
>> }
>> // All elements are deleted when leaving the scope.
>>
>> However, currently I didn't see a method to clear the internal container.
>> One way I could do that would be copying - pasting the hashed_factory
>> and adding a clear method.
>> It would be easier to extend the class, just having the private
>> container be protected.
>> Would that be possible to do one a future release ?
>> Or is there another easy way to do so ?
>
> There's currently no way to do what you want save the
> trick you describe, which is perfectly OK. The roadmap
> for Boost.Flyweight includes features that will allow
> you to control the factory in the way you describe, see
>
> http://www.boost.org/doc/libs/1_41_0/libs/flyweight/doc/future_work.html#instrospection
>
> but I don't think I'll be able to begin working on
> new features for this lib until some time in 2010.
>
Ok I'll wait !
Thanks !
Regards,
Samuel
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