I was looking to the mongocxx query exemples and I don't get whats the point of using auto&&
over auto&
here.
auto cursor = db["restaurants"].find({}, opts);
for (auto&& doc : cursor) {
std::cout << bsoncxx::to_json(doc) << std::endl;
}
In the documentation, they use it this way:
mongocxx::cursor cursor = collection.find(document{} << finalize);
for(auto doc : cursor) {
std::cout << bsoncxx::to_json(doc) << "\n";
}
I want to use for(auto& doc : cursor)
What is the best practice here, and why ?