gpt4 book ai didi

c++ - boost intrusive 直接从节点获取下一个

转载 作者:行者123 更新时间:2023-11-28 04:27:56 25 4
gpt4 key购买 nike

是否可以直接从节点/元素获取下一个节点/元素?像这样:

struct Data{
boost::intrusive::list_member_hook<> node;

Data* get_next(){
node.get_next() ???
}
}

最佳答案

许多boost侵入式容器都有一个静态成员函数s_iterator_to直接从值中获取迭代器。

因此你可以获得一个迭代器然后使用迭代器接口(interface):

struct Data{
boost::intrusive::list_member_hook<> node;

inline Data* get_next();
}

namespace bis = boost::intrusive;

using List = bis::list<Data,
bis::member_hook<Data, bis::list_member_hook<>, &Data::node>
>;

Data* Data::get_next() {
return &*++List::s_iterator_to(*this);
}

Live Demo

关于c++ - boost intrusive 直接从节点获取下一个,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53815956/

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