|
Boost Users : |
From: John Emmas (john_at_[hidden])
Date: 2021-09-09 09:28:12
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 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