gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 05:18:08 33 4
gpt4 key购买 nike

我无法理解如何将 boost::flyweight 用作 GOF 模式。有没有现成的例子?

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

我不明白如何从 boost::flyweight 接收对象的“持有者/描述符”。

最佳答案

模式实现不需要 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.

关于c++ - 如何使用 boost::flyweight 作为 GOF 模式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41873089/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com