1

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.

hyde
  • 60,639
  • 21
  • 115
  • 176
AeroSun
  • 2,401
  • 2
  • 23
  • 46

1 Answers1

1

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.

milleniumbug
  • 15,379
  • 3
  • 47
  • 71
  • I still don`t get. For example, in case of text editor I need container that would contain the list of the "descriptors" of the eath letter that user input. So how to implement it with boost? It must be list of flyweigts? (std::list> line;) – AeroSun Jan 26 '17 at 15:34
  • @AeroSun If you look at the examples in the documentation, like [this one, about formatted text processing](http://www.boost.org/doc/libs/1_63_0/libs/flyweight/example/html.cpp), you'll see they do exactly that: `typedef flyweight character; std::vector scanned_html;` – milleniumbug Jan 26 '17 at 16:46
  • Thx a lot! Now I understand. It's too differs from GoF patterns. The boost implementation looks very simple in use, but I don't sure if it's good that I don't have access to inner object repository. – AeroSun Jan 26 '17 at 22:32