Boost logo

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