Problem
When calling insert with an empty sibling_iterator as the first parameter, it is expected that a new node will be inserted below that iterator's parent. This is indeed the case if the insert method is called using such a sibling_iterator and data passed by constant reference. However, when calling the method using std::move on the data instead, the new node is inserted at the end of the tree.
Possible solution
It seems the problem comes from the fact that there is a specialization of the insert method accepting sibling_iterator objects and data passed by constant reference, but there isn't one accepting moved data. This forces the code in Option 2 above to default to the generic version of the insert method that does accept moved data. Solving it seems as simple as creating such a specialization.
Problem When calling
insert
with an emptysibling_iterator
as the first parameter, it is expected that a new node will be inserted below that iterator's parent. This is indeed the case if the insert method is called using such asibling_iterator
and data passed by constant reference. However, when calling the method usingstd::move
on the data instead, the new node is inserted at the end of the tree.The following code snippet illustrates this:
Using
Option 1
you get this output (expected):Using
Option 2
, this happens:Possible solution It seems the problem comes from the fact that there is a specialization of the
insert
method acceptingsibling_iterator
objects and data passed by constant reference, but there isn't one accepting moved data. This forces the code inOption 2
above to default to the generic version of theinsert
method that does accept moved data. Solving it seems as simple as creating such a specialization.