问题
I've searched a lot through the boost manual, and the internet, as I believe it is quite a standard feature?
Well I'm looking into "merging" property trees. - I noticed the function insert
, and I hope I can merge trees with this?
Below is the line which I am trying to get working:
base.insert(base.get_child("BRANCH"), t);
base
and t
are "property trees", base
has as (one of many) branch "BRANCH". Now I wish to insert t
into this branch?
More specifically: how can I get an iterator to "element" if I know that element by name?
回答1:
You can get an iterator to an element using the begin() method:
base.get_child("BRANCH").begin();
In order to insert every element in t on that position, you should use:
base.insert(base.get_child("BRANCH").begin(), t.begin(), t.end());
If t contains one parent node or you only want to insert the first node, you can use:
base.insert(base.get_child("BRANCH").begin(), t.front());
来源:https://stackoverflow.com/questions/7590370/boost-property-tree-iterators-to-an-element-for-inserting