如何使用 boost::flyweight 作为 GOF 模式?

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

我无法理解如何将 boost::flyweight 用作 GOF 模式。某处有例子吗?

例如,我希望它以下列方式使用。必须有一些享元容器,其中包含 "fat" 个对象。这个容器可以为某些对象提供一些轻量级 "holder/descriptor"。我可以将描述符存储在某个容器中。

我无法理解如何从 boost::flyweight 接收对象的 "holder/descriptor"。

模式实现不需要将 1:1 映射到原始模式描述。这是一件 好事 ,因为可以利用 GoF 使用的任何一组功能中不可用的语言功能,使该实现更高效、更简洁、更易于维护,并且依此类推。

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.