I'd like to sort m_correlationValues in descending order and get ids of the sorted list. I've got this error. I'll appreciate your help. no match for 'operator=' (operand types are 'std::vector<std::pair<int, float> >' and 'void') return idx_correlation.second; });
void MatrixCanvas::SortMatrix()
{
int naxes = (int) m_correlationData.size();
std::vector<std::pair<int,float>> idx_correlations;
std::vector<std::pair<int,float>> sorted;
std::vector<int> idxs(naxes);
for(int idx =0; idx<naxes;idx++){
idx_correlations[idx] = std::make_pair(idx, m_correlationValues[chosen_row_id][idx]);}
// Wrong
sorted = std::sort(idx_correlations.begin(),
idx_correlations.end(),
[](std::pair<int,float> &idx_correlation){
return idx_correlation.second; });
// this will contain the order:
for(int i =0; i<naxes;i++)
idxs[i] = sorted[i].first;
}
boolthat indicates whether the first argument is to be considered "less" than the second. - lubgrstd::sortdoes not return anything. It sorts in place. When it returnsidx_correlationswill be sorted. If you want to keep that unsorted then you should make a copy first, likesorted = idx_correlationsand pass iterators tosortedtosort. If you do fix that then prepare yourself for a really long error about the sort predicate that @lubgr mentioned. :) - Retired Ninjasorted = std::sort(idx_correlations.begin(),...-- What was your intention with this code? This is not howstd::sortworks. - PaulMcKenzieint,doubles,pairs, or Widgets -- it doesn't matter. Thestd::sortpredicate takes two arguments of that type. You are given two values, and you're supposed to returntrueorfalse, depending on whether the first value should be placed before the second value. Maybe if you used modern C++ syntax usingauto, things would be more understandable:std::sort(idx_correlations.begin(), idx.correlations.end(), [](auto& val1, auto& val2).... Whatautois will depend on the types that the vector holds. - PaulMcKenzie