私のコードでは、一連の測定値 (float のベクトル) を扱っています。各要素には 2 つの関連する不確実性 (+up/-down など) があります。これらの値を画面にダンプしたいとしましょう。
Loop over the vector of the measurements
{
cout << i-th central value << " +" << i-th up uncertainty << " / -" << i-th down uncertainty << end;
}
それを行うための最も効率的/エレガントな方法は何ですか?
1) ベクトルのペアを使用する
vector<float> central; //central measurement
pair<vector<float>, vector<float>> errors; //errors
for( int i = 0; i < central.size ; i++ )
{
cout << central.at(i) << " +" << errors.first.at(i) << " / -" << errors.second.at(i) << endl;
}
2) ペアのベクトルを使用:
vector<float> central; //central measurement
vector<pair<float,float>> errors; //errors
for( int i = 0; i < central.size ; i++ )
{
cout << central.at(i) << " +" << errors.at(i).first << " / -" << errors.at(i).second << endl;
}
3) 2 つの別々のベクトル:
vector<float> central; //central measurement
vector<float> errUp; //errors up
vector<float> errDown; //errors down
for( int i = 0; i < central.size ; i++ )
{
cout << central.at(i) << " +" << errUp.at(i) << " / -" << errDown.at(i) << endl;
}