How to use boost::flyweight as a GOF pattern?

287 views Asked by At

I can't understand how to use boost::flyweight as a GOF pattern. Is there are exist example somewhere?

For example, I expect it usage in the following way. There must be some flyweight container, that consist the "fat" objects. This container can give some lightweight "holder/descriptor" for some object. And I can store the descriptor in some container.

I can't understand how to receive the "holder/descriptor" of object from the boost::flyweight.

1

There are 1 answers

3
milleniumbug On BEST ANSWER

A pattern implementation does not need to map 1:1 to the original pattern description. That's a good thing, since one can make use of the language features not available in the whatever set of features GoF were using, to make that implementation more performant, less verbose, more maintainable, and so on, and so on.

The boost::flyweight is the "lightweight holder/descriptor":

Boost.Flyweight makes it easy to use this common programming idiom by providing the class template flyweight<T>, which acts as a drop-in replacement for const T.