lundi 29 avril 2019

C++: Array in Tuple in Vector - How to refer to the array elements and how to sort the vector

I have a setup like this.

std::vector<std::tuple<std::array<int,64>,int>> frequentLines;

There is a vector which has tuples. Each tuple is made of an array of 64 ints and another int which represents the frequency of every array.

My first question is, how do I refer to the array elements?

I know that when you have an array in a tuple you would have something like this.

for (uint i=0; i<64; i++) {     
    get<1>(foo)[i]
}

I'm not sure how to refer to the array elements while having everything in a vector.

I tried

for (uint i=0; i<frequentLines.size(); i++) {
    for (int j=0; j<64; j++) {
        std::get<0>(frequentLines)[i][j]
    }
}

but it's not working.

My second question is what would be an efficient way to sort this vector based on the frequency of each array of ints (i.e., based on the second element (int) of the tuple)?

Aucun commentaire:

Enregistrer un commentaire