JSONファイルを解析するためにnlohmannのJSONライブラリを使用しています。このコンテキストでは、オブジェクトの受け渡しに関連する効率とオーバーヘッドの観点から、JSON オブジェクトを値または参照で渡すのがベスト プラクティスであるかどうか疑問に思いました。
値で渡すことを示す短い例を次に示します。
#include <iostream>
#include <string>
#include <fstream>
#include "json.hpp"
void read_json(nlohmann::json j) /// pass by value or reference?
{
///...
}
int main()
{
std::string file_name = "asd.json";
std::ifstream filename_stream(file_name);
nlohmann::json j = nlohmann::json::parse(filename_stream);
read_json(j);
return 0;
}