|
Boost Users : |
From: John Emmas (john_at_[hidden])
Date: 2021-09-07 11:11:43
I'm in the early stages of trying to understand boost::intrusive::list'
so forgive me if I'm just doing something stupid!! Using VS2019 I wrote
a small demo app which uses 'boost::intrusive::list_base_hook<>':-
#include <boost/intrusive/list.hpp>
#include <string>
#include <iostream>
using namespace std;
class animal : public boost::intrusive::list_base_hook<>
{
public:
animal (string n, int l) : name{move(n)}, legs{l} {}
string name;
int legs;
};
using animal_list = boost::intrusive::list<animal>;
template<typename T>
void print_list (const boost::intrusive::list<T>& elem)
{
for (const T& a : elem)
cout << "A " << a.name << " has " << a.legs << " legs" << '\n';
}
int main()
{
animal a1{"dog", 4};
animal a2{"spider", 6};
animal a3{"budgie", 2};
animal_list animals;
animals.push_back(a1);
animals.push_back(a2);
animals.push_back(a3);
print_list (animals);
return 0;
}
Everything runs fine and I see the expected output but I've noticed that
some other developers use something called a 'list_member_hook' rather
than my 'list_base_hook' - so class animal would look like this:-
class animal
{
public:
animal (string n, int l) : name{move(n)}, legs{l} {}
string name;
int legs;
boost::intrusive::list_member_hook<> _animal_hook;
};
and then later on in the program there'd be a couple of lines looking
something like this:-
typedef boost::intrusive::member_hook<animal,
boost::intrusive::list_member_hook<>, &animal::_animal_hook>
AnimalHookOption;
typedef boost::intrusive::list<animal, AnimalHookOption> Animals;
But when I try that here, VS2019 throws up this compiler error:-
error C2039: 'default_list_hook': is not a member of 'animal'
Can anyone explain what I'm doing wrong??
John
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net