c++ – A case for GOTO

First and foremost I want to say that I’m fully aware GOTO should normally be avoided in production code and it tends to be unreadable for others. For this specific case however, the code will not be read by anyone but me and the question is being asked mostly so I can understand what other options do I even have available since I lack experience with C++.

I also have not been able to find anything regarding this type of use for goto:

void class_method() {

    std::queue<int> my_queue;
    // generation of many objects happens here

    // Now I want to find the best element and I store the values for decider parameters
    // storing the object itself would be very inefficient as I care only about some key values
    int best_element_id = 0;
    int best_parameter_a = 0;
    int best_parameter_b = 0;
    // ...
    int best_parameter_z = 0;

    while (!my_queue.empty()) {
        if (my_queue.front().a_getter() > best_parameter_a) {
            // Found new best element since parameter A is most important
            int best_element_id = my_queue.front().id_getter();
            int best_parameter_a = my_queue.front().a_getter();
            int best_parameter_b = my_queue.front().b_getter();
            // ...
            int best_parameter_z = my_queue.front().z_getter();
        }
        else if (my_queue.front().a_getter() == best_parameter_a) {
            if (my_queue.front().b_getter() > best_parameter_b) {
                // Found new best element since parameter B is second most important
                int best_element_id = my_queue.front().id_getter();
                int best_parameter_a = my_queue.front().a_getter();
                int best_parameter_b = my_queue.front().b_getter();
                // ...
                int best_parameter_z = my_queue.front().z_getter();
            }
            else if (my_queue.front().a_getter() == best_parameter_a) {
                // ...
                // Many more checks
                // ...

                // Till last parameter is checked
                if (my_queue.front().z_getter() > best_parameter_z) {
                    int best_element_id = my_queue.front().id_getter();
                    int best_parameter_a = my_queue.front().a_getter();
                    int best_parameter_b = my_queue.front().b_getter();
                    // ...
                    int best_parameter_z = my_queue.front().z_getter();
                }
            }
        }

        my_queue.pop();
    }
};

The conditions are obviously oversimplified and there are actually less than 26 parameters, I’m using a-z just to generalize the problem.

Now I was obviously very displeased with this code and attempted to come up with some way to have the lines that update the parameters in one place. This is what I came up with:

void class_method() {

    std::queue<int> my_queue;
    // generation of many objects happens here

    // Now I want to find the best element and I store the values for deciding parameters
    // storing the object itself would be very inefficient as I care only about some key values
    int best_element_id = 0;
    int best_parameter_a = 0;
    int best_parameter_b = 0;
    // ...
    int best_parameter_z = 0;

    while (!my_queue.empty()) {
        if (my_queue.front().a_getter() > best_parameter_a) {
            // Found new best element since parameter A is most important
            goto new_best;
        }
        else if (my_queue.front().a_getter() == best_parameter_a) {
            if (my_queue.front().b_getter() > best_parameter_b) {
                // Found new best element since parameter B is second most important
                goto new_best;
            }
            else if (my_queue.front().a_getter() == best_parameter_a) {
                // ...
                // Many more checks
                // ...

                // Till last parameter is checked
                if (my_queue.front().z_getter() > best_parameter_z) {
                    goto new_best;
                }
            }
        }
        
        if (false) {
            new_best:
            int best_element_id = my_queue.front().id_getter();
            int best_parameter_a = my_queue.front().a_getter();
            int best_parameter_b = my_queue.front().b_getter();
            // ...
            int best_parameter_z = my_queue.front().z_getter();
        }
        my_queue.pop();
    }
};

What other options do I have?

Would such usecase be considered okay? If it is, maybe there is a more elegant way to write that without the if (false) condition?

Last but not least, my IDE throws warnings because of the if (false) line, but I’m assuming the compiler will not optimize it away, right?