gpt4 book ai didi

c++ - 如何使用 Boost.Assign 初始化 Boost.PropertyTree

转载 作者:行者123 更新时间:2023-11-28 00:36:34 29 4
gpt4 key购买 nike

有填充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");

最佳答案

你可以使用类似的东西

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");

关于c++ - 如何使用 Boost.Assign 初始化 Boost.PropertyTree,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20701026/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com