gpt4 book ai didi

c++ - 为 boost::property_tree::ptree 移动构造函数

转载 作者:太空狗 更新时间:2023-10-29 21:11:27 27 4
gpt4 key购买 nike

我使用 boost::property_tree::ptree相当多,但我发现我创建、传递和保存拷贝的次数太多了。对于大的 ptree 对象,这是昂贵的。

Boost 提供了一个 swap函数,但没有移动构造函数。他们为什么要这样做?

我目前的解决方案是扩展 ptree 并自己制作一个:

class MyPtree : public boost::property_tree::ptree
{
MyPtree(MyPtree&& other)
{
swap(other);
}

... plus adding the other constructors and operators
};

这是最好的解决方案还是我遗漏了什么?

最佳答案

我认为您的解决方案非常不错。请注意,它永远不会影响内部树操作,因为树会将其子项视为 ptree,而不是 MyPtree

更好的做法是提出新功能并将其建议给图书馆开发人员。


相关的是Is there a convenient way to erase a node from a property tree, preserving its child nodes? .

如果您想深入挖掘,您会发现 Property Tree 建立在 Boost MultiIndex 之上,出于各种原因,它似乎不允许从以下值移动:Move element from boost multi_index array

您可以添加一个 splice() 操作,该操作建立在所使用的各种索引的列表性之上:

For now, ptree could add a splice operation, which would naturally wrap multi_index's list operations: I just made a draft implementation sehe - Sep 23 '17 at 9:48

关于c++ - 为 boost::property_tree::ptree 移动构造函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50627064/

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