|
Boost Users : |
Subject: Re: [Boost-users] [multi_index and flyweight]
From: Joaquin M Lopez Munoz (joaquin_at_[hidden])
Date: 2009-12-04 15:58:39
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;
> 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.
JoaquÃn M López Muñoz
Telefónica, Investigación y Desarrollo
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