I think this is a classical question but I did not manage to find a clear answer (maybe my keywords are not the good one).
Let’s say I have a structure of the form (this is a recurrent situation in my programming practice):
std::vector< pair<unsigned int, double> > pairAgeSize;
and I have a function of the form :
double getMean(const std::vector<double> & sample);
What is the “best” way to call getMean on the elements [pairAgeSize[0].first,…,pairAgeSize[n].first] ?
or even on [pairAgeSize[0].second,…,pairAgeSize[n].second] ?
More generally, is there any pragmatical practice rules that can prevent this kind of situation ?
getMeanshould take iterators as inputs to it to be fully general, and you should write a custom iterator that will returnpair.first.