On 08/09/2021 15:56, John Emmas wrote:

I realise there are two types of hook available for 'boost::intrusive::list' ( the list_member_hook<> and the list_base_hook<>) - so are there certain situations where one would preferable over the other?


Overnight I got told (off-list) that when 2 x classes are both declared using the 'list_base_hook<>' option, I'll get a runtime crash if I try to add the same object to both lists. In other words, this will crash at the specified line:-

    class animal : public boost::intrusive::list_base_hook<>
    {
     public:
        animal (string n, int l) : name{move(n)}, legs{l} {}

        string name;
        int legs;
    };

    typedef boost::intrusive::list<animal> Animals;
    typedef boost::intrusive::list<animal> Dogs;

    int main()
    {
        animal a1{"labrador", 4};
        animal a2{"bulldog", 4};

        Animals animals;
        animals.push_back (a2);  // <--- 'bulldog' works okay

        Animals dogs;
        dogs.push_back (a1);     // <--- 'labrador' Works okay
        dogs.push_back (a2);     // <--- 'bulldog' crashes !!!

        return 0;
    }

and sure enough it does crash there! So I then tried changing the design to use 'boost::intrusive::list_member_hook<>' but that gave me the same runtime crash... so is this just a general limitation with 'boost::intrusive::list'?

Thanks again for any advice, John
_______________________________________________
Boost-users mailing list
Boost-users@lists.boost.org
https://lists.boost.org/mailman/listinfo.cgi/boost-users

Reply via email to