Trying to learn boost::intrusive Q2

后端 未结 2 423
故里飘歌
故里飘歌 2021-01-17 06:26

if I uncomment these

//BaseList   baselist; 
//MemberList memberlist;

outside the loop and comment out the ones inside the loop it

2条回答
  •  温柔的废话
    2021-01-17 07:04

    Here's the error message, which you omitted:

    Assertion `node_algorithms::inited(to_insert)' failed.
    

    From this we can understand that an element is being inserted twice. This isn't valid with intrusive containers in general.

    When you have your lists inside the loop, they are destroyed and recreated each time. But when they are outside, you never clear them, and you also never clear values, so this sequence occurs:

    1. Add 11 elements to values.
    2. Add all values to the lists.
    3. Add 11 elements to values; it still has the previous 11 so now 22 elements.
    4. Add all values to the lists. Crash on the first one, because it is already in a list.

    One solution is to add values.clear() at the top of the while(!done) loop.

提交回复
热议问题