0

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)?

1 Answer 1

1

Use std::get<0>(frequentLines[i])[j] in your loop and sort(frequentLines.begin(),frequentLines.end(),[](std::tuple<std::array<int,64>,int> &a, std::tuple<std::array<int,64>,int>& b) { return std::get<1>(a)<std::get<1>(b); }).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.