Skip to content

Commit

Permalink
replace - 1 with std::prev for QMap iterators
Browse files Browse the repository at this point in the history
QMap::iterator operator- was removed in Qt6 by mistake. It has
been added back in Qt 6.2 with a deprecation warning saying to
use std::prev instead:
https://codereview.qt-project.org/c/qt/qtbase/+/362150
  • Loading branch information
Be-ing committed Oct 10, 2021
1 parent fbaafb4 commit fd22e9e
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/controllers/learningutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,14 @@ MidiInputMappings LearningUtils::guessMidiInputMappings(
// QMap keys are sorted so we can check this easily by checking the last key
// is <= 0x7F.
bool only_7bit_values = !stats.value_histogram.isEmpty() &&
(stats.value_histogram.end() - 1).key() <= 0x7F;
(std::prev(stats.value_histogram.end(), 1)).key() <= 0x7F;

// A 7-bit two's complement ticker swinging from +1 to -1 can generate
// unsigned differences of up to 126 (0x7E). If we see differences in
// individual messages above 96 (0x60) that's a good hint that we're looking
// at a two's complement ticker.
bool abs_differences_above_60 = !stats.abs_diff_histogram.isEmpty() &&
(stats.abs_diff_histogram.end() - 1).key() >= 0x60;
(std::prev(stats.abs_diff_histogram.end(), 1)).key() >= 0x60;

if (one_control && one_channel &&
two_values_7bit_max_and_min &&
Expand Down Expand Up @@ -268,9 +268,9 @@ MidiInputMappings LearningUtils::guessMidiInputMappings(
int control2 = *(++stats.controls.begin());

int control1_max_abs_diff =
(stats_by_control[control1].abs_diff_histogram.end() - 1).key();
(std::prev(stats_by_control[control1].abs_diff_histogram.end(), 1)).key();
int control2_max_abs_diff =
(stats_by_control[control2].abs_diff_histogram.end() - 1).key();
(std::prev(stats_by_control[control2].abs_diff_histogram.end(), 1)).key();

// The control with the larger abs difference in messages is the LSB. If
// they are equal we choose one arbitrarily (depends on QSet iteration
Expand Down

2 comments on commit fd22e9e

@daschuer
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest to use QMap::last() for better readability.

@Be-ing
Copy link
Contributor Author

@Be-ing Be-ing commented on fd22e9e Oct 10, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good idea

Please sign in to comment.