Vector of pairs or pair of vectors?
In my code I'm dealing with a set of measurements (a vector of float), in
which each element has two associated uncertainties (say +up/-down). Let's
say I want to dump on screen these values, something like
Loop over the vector of the measurements
{
cout << i-th central value << " +" << i-th up uncertainty << " / -" <<
i-th down uncertainty << end;
}
What's the most efficient/elegant way to do it?
1) Using a pair of vectors
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) Using a vector of pairs:
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) Two separate vectors:
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;
}
No comments:
Post a Comment