I am using BSONCXX to manage documents for a c++ application.
when composing documents I sometimes append local documents to documents with a larger scope. This works however I feel nervous that I might be creating dangling pointers or creating memory leaks. Can someone please advise if its ok to do this.
example code is below:
if (true){
auto localDoc = bsoncxx::builder::basic::document{};
localDoc.append(bsoncxx::builder::basic::kvp(“key”, “value”));
mainDoc.append(bsoncxx::builder::basic::kvp(“mainKey”, localDoc.view()));
}std::cout<<"mainDoc: "<<bsoncxx::to_json(mainDoc.view())<<std::endl;
when i run the code i get the following as expected.
mainDoc: { “mainKey” : { “key” : “value” } }
I assume that a copy is made of the local document is that right.