boost intrusive get next directly from node

324 Views Asked by At

Is it possible to get next node/element directly from node/element? Like so:

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

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

There are 1 best solutions below

2
On BEST ANSWER

Many boost intrusive containers have a static member function s_iterator_to to get an iterator directly from a value.

Thus you can get an iterator then use the iterator 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