Samuel Charron
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
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#ins... 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