Thanks Joaquin - one quick question... do I need to define 'struct
animal_tag' and 'struct dog_tag' somewhere?
At present, your code compiles and links okay but I still see a runtime
crash at the same line ('dogs.push_back (a2);')
This time though, it gives me a runtime error message saying:- Assertion
failed: !safemode_or_autounlink || node_algorithms::inited(to_insert),
file F:\+GTK-SOURCES\gnu-windows\include\boost\intrusive\list.hpp, line 271
Thanks, John
On 09/09/2021 12:16, Joaquin M López Muñoz via Boost-users wrote:
if you mean for the elements to be allowed in both lists at the same
time, use tags:
#include <boost/intrusive/list.hpp>
#include <string>
#include <utility>
typedef
boost::intrusive::list_base_hook<boost::intrusive::tag<struct
animal_tag>> animals_hook;
typedef
boost::intrusive::list_base_hook<boost::intrusive::tag<struct
dog_tag>> dogs_hook;
class animal :
public animals_hook, public dogs_hook
{
public:
animal (std::string n, int l) : name{std::move(n)}, legs{l} {}
std::string name;
int legs;
};
typedef
boost::intrusive::list<animal,boost::intrusive::base_hook<animals_hook>>
Animals;
typedef
boost::intrusive::list<animal,boost::intrusive::base_hook<dogs_hook>>
Dogs;
int main()
{
animal a1{"labrador", 4};
animal a2{"bulldog", 4};
Animals animals;
animals.push_back (a2); // <--- 'bulldog' works okay
Dogs dogs;
dogs.push_back (a1); // <--- 'labrador' works okay
dogs.push_back (a2); // <--- 'bulldog' works okay
return 0;
}
Joaquín M López Muñoz
_______________________________________________
Boost-users mailing list
Boost-users@lists.boost.org
https://lists.boost.org/mailman/listinfo.cgi/boost-users
_______________________________________________
Boost-users mailing list
Boost-users@lists.boost.org
https://lists.boost.org/mailman/listinfo.cgi/boost-users