Boost 侵入式列表挂钩
Boost::Intrusive 库中的基本钩子和成员钩子有什么区别?什么时候使用其中一个比另一个更好?
我已经阅读了 boost 文档,但它没有那么解释。
What is the difference in a base hook and a member hook in Boost::Intrusive library and when is one better to use then the other?
I've read the boost documentation, but its not that explanatory.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
据我所知,这是风格和面向对象设计的问题。基钩子侵入继承层次结构,需要额外的公共父类,并可能在设计上强制多重继承。使用成员挂钩允许程序员将对象视为与容器具有
has-a
关系,而不是与容器成员资格的is-a
关系。As far as I can tell it is a matter of style and object-oriented design. Base hooks intrude upon the inheritance hierarchy, necessitating an extra
public
parent class and possibly forcing multiple inheritance upon the design. Using member hooks allows the programmer to treat an object as having ahas-a
relation with a container, rather than anis-a
relation with container membership.恕我直言,如果您的对象只想包含在单个容器中,则基本钩子似乎更方便。否则(对于多个容器),多个成员挂钩提供了不太模糊的解决方案(因为避免了多重继承)
imho if your object is intended to be included into single container only, base hook seems more convinient. Otherwise (for multiple containers), multiple member hooks provide less ambigious solution (since multiple inheritance is avoided)
http://www.boost.org/doc/libs /1_47_0/doc/html/intrusive/recursive.html
“成员钩子不适合递归结构”
http://www.boost.org/doc/libs/1_47_0/doc/html/intrusive/recursive.html
"Member hooks are not suitable for recursive structures"