有一个填充boost :: property_tree :: ptree
的示例boost::property_tree::ptree pt;
pt.put("one", "value1");
pt.put("one.two", "value2");
pt.put("one.three", "value3");
如何扩展适合初始化boost::property_tree::ptree
对象的 Boost.Assign 库?
我喜欢像
// XXX is some function / functor
boost::property_tree::ptree pt =
XXX("one", "value1")("one.two", "value2")("one.three", "value3");
答案 0 :(得分:3)
您可以使用类似
的内容template<class C>
class call_put
{
C& c_;
public:
call_put(C& c) : c_(c) {}
template<typename T, typename V>
void operator () (const T& key, const V& value)
{
c_.put(key, value);
}
};
template<class C>
inline boost::assign::list_inserter<call_put<C> >
put(C& c)
{
return boost::assign::make_list_inserter(call_put<C>(c));
}
用法:
boost::property_tree::ptree pt;
put(pt)("one", "value1")("one.two", "value2")("one.three", "value3");