在 Rapidjson 中使用 Move

The use of Move in Rapidjson

本文关键字:Move Rapidjson      更新时间:2023-10-16

我想知道以下两种方式之间的rapidjson差异,我已经尝试阅读rapidjson文档,但仍然对此感到困惑。

1. doc.AddMember("tag", tag_str, doc.GetAllocator());
2. doc.AddMember("tag", rapidjson::Value(tag_str).Move(), doc.GetAllocator());

我想知道这两种用法之间的区别,谢谢。

1. doc.AddMember("tag", tag_str, doc.GetAllocator());

这将通过常量引用向文档添加tag_str。因此,tag_str必须比文档更长久。

2. doc.AddMember("tag", rapidjson::Value(tag_str).Move(), doc.GetAllocator());

这会将tag_str值复制到 Value 对象中,然后将其移动到文档中。