Consider the following code snippet:
#include <iostream>
#include
#include
#include
using namespace std;
using namespace boost::multi_index;
struct LinkList;
struct LinkList {
size_t index;
LinkList* parent;
LinkList(size_t index, LinkList* parent) : index(index), parent(parent)
{}
};
struct llindex {};
typedef ordered_unique > LinkListIndex;
typedef boost::multi_index_container
IndexedLinkList;
template <typename T> void show(T& iterable) {
for(auto const& element: iterable) {
if(element.parent != nullptr) {
std::cout << "Index<" << element.index << ">: " <<
element.parent->index << std::endl;
}
else {
std::cout << "Index<" << element.index << ">: " << "NULL" <<
std::endl;
}
}
}
int main() {
IndexedLinkList ill;
auto &index_ll = ill.get<0>();
ill.insert(LinkList{0, nullptr});
ill.insert(LinkList{1, (LinkList*)(&(*index_ll.find(0)))});
ill.insert(LinkList{2, (LinkList*)(&(*index_ll.find(0)))});
ill.insert(LinkList{3, (LinkList*)(&(*index_ll.find(2)))});
show(ill);
return 0;
}
Would (LinkList*)(&(*index__ll.find(value))) be the recommended way to
fetch the pointer to parent?