jkang
jkang

Reputation: 549

Combining multiple boost property_tree

Very basic question: does Boost's PropertyTree support addition of any kind?? For example, can I:

boost::property_tree::ptree pt0;
boost::property_tree::ptree pt1;
boost::property_tree::ptree pt;

boost::property_tree::ini_parser::read_ini("config0.ini", pt0);
boost::property_tree::ini_parser::read_ini("config1.ini", pt1);
pt = pt0 + pt1;

The documentation isn't very clear. I assume there isn't an overloaded + operator?

What's the recommended "clean" way to combine 2 Boost property_tree objects?

Upvotes: 1

Views: 678

Answers (1)

parktomatomi
parktomatomi

Reputation: 4079

This class appears to have a range insert that you can use to copy all the parameters at once

This is how you can use that method to create the + operator overload you're looking for:

boost::property_tree::ptree operator +(const boost::property_tree::ptree& lhs, const boost::property_tree::ptree& rhs) {
    boost::property_tree::ptree result(lhs);
    result.insert(result.end(), rhs.begin(), rhs.end());
    return result;
}

Upvotes: 2

Related Questions