Skip to content

Commit 75160f1

Browse files
committed
C++17 fixes
`std::random_shuffle` and `std::mem_fun` have been removed.
1 parent fd16178 commit 75160f1

3 files changed

Lines changed: 16 additions & 10 deletions

File tree

src/covers/musicbrainzcoverprovider.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,10 @@
2121
#include <QUrlQuery>
2222
#include <QXmlStreamReader>
2323
#include <algorithm>
24-
#include <functional>
2524

2625
#include "core/closure.h"
2726
#include "core/network.h"
2827

29-
using std::mem_fun;
30-
3128
namespace {
3229

3330
static const char* kReleaseSearchUrl = "https://musicbrainz.org/ws/2/release/";
@@ -88,8 +85,9 @@ void MusicbrainzCoverProvider::ReleaseSearchFinished(QNetworkReply* reply,
8885

8986
void MusicbrainzCoverProvider::ImageCheckFinished(int id) {
9087
QList<QNetworkReply*> replies = image_checks_.values(id);
91-
int finished_count = std::count_if(replies.constBegin(), replies.constEnd(),
92-
mem_fun(&QNetworkReply::isFinished));
88+
int finished_count =
89+
std::count_if(replies.constBegin(), replies.constEnd(),
90+
[](QNetworkReply* reply) { return reply->isFinished(); });
9391
if (finished_count == replies.size()) {
9492
QString cover_name = cover_names_.take(id);
9593
QList<CoverSearchResult> results;

src/globalsearch/globalsearch.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <QTimerEvent>
2323
#include <QUrl>
2424
#include <algorithm>
25+
#include <random>
2526

2627
#include "core/application.h"
2728
#include "core/logging.h"
@@ -370,8 +371,10 @@ QStringList GlobalSearch::GetSuggestions(int count) {
370371
}
371372
}
372373

374+
static std::random_device rd;
375+
static std::mt19937 gen(rd());
373376
// Randomize the suggestions
374-
std::random_shuffle(ret.begin(), ret.end());
377+
std::shuffle(ret.begin(), ret.end(), gen);
375378

376379
// Only return the first count
377380
while (ret.length() > count) {

src/playlist/playlist.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2083,9 +2083,12 @@ void Playlist::ReshuffleIndices() {
20832083
break;
20842084

20852085
case PlaylistSequence::Shuffle_All:
2086-
case PlaylistSequence::Shuffle_InsideAlbum:
2087-
std::random_shuffle(begin, end);
2086+
case PlaylistSequence::Shuffle_InsideAlbum: {
2087+
static std::random_device rd;
2088+
static std::mt19937 gen(rd());
2089+
std::shuffle(begin, end, gen);
20882090
break;
2091+
}
20892092

20902093
case PlaylistSequence::Shuffle_Albums: {
20912094
QMap<int, QString> album_keys; // real index -> key
@@ -2101,8 +2104,10 @@ void Playlist::ReshuffleIndices() {
21012104

21022105
// Shuffle them
21032106
QStringList shuffled_album_keys = album_key_set.values();
2104-
std::random_shuffle(shuffled_album_keys.begin(),
2105-
shuffled_album_keys.end());
2107+
2108+
static std::random_device rd;
2109+
static std::mt19937 gen(rd());
2110+
std::shuffle(shuffled_album_keys.begin(), shuffled_album_keys.end(), gen);
21062111

21072112
// If the user is currently playing a song, force its album to be first
21082113
// Or if the song was not playing but it was selected, force its album

0 commit comments

Comments
 (0)