I landed here trying to figure out a similar problem. It took me a while to solve it, so hopefully this post helps others.
For me, the key to solving the problem was remembering that a ptree is a collection of boost::property_tree::ptree::value_type. So the problem reduces to "how can I add the value_types from one ptree into another".
Ptree provides a few methods for value_type insertion:
iterator push_front(const value_type &);
iterator push_back(const value_type &);
iterator insert(iterator, const value_type &);
Ptree doesn't have a const_reference typedef, so we cannot make use of std::copy with back_inserter iterator. But we can use std::for_each with a bound function.
#include <algorithm>
#include <functional>
#include <boost/property_tree/ptree.hpp>
using namespace std;
using namespace boost::property_tree;
...
ptree child;
child.put("Value1", 1);
child.put("Value2", 2);
ptree parent;
std::for_each(child.begin(),
child.end(),
std::bind(&ptree::push_back, &parent, placeholders::_1));
Now if parent is output as XML it would contain:
<Value1>1</Value1>
<Value2>2</Value2>