Skip to content

Commit

Permalink
portability: replace deprecated random_shuffle()
Browse files Browse the repository at this point in the history
Summary:
In C++17, random_shuffle() has been deprecated. Still available in GCC,
but removed in CLANG.
Replace with a non-deprecated equivalent.
See: https://en.cppreference.com/w/cpp/algorithm/random_shuffle

Reviewed By: therealgymmy

Differential Revision: D33742049

fbshipit-source-id: 9feac85ea31e9b71ee4934ff38ac795b75e7ab32
  • Loading branch information
agordon authored and facebook-github-bot committed Jan 31, 2022
1 parent 023f2e5 commit 68351f4
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions cachelib/allocator/nvmcache/tests/TombStoneTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#include <folly/Random.h>
#include <gtest/gtest.h>

#include <algorithm>
#include <random>
#include <thread>
#include <vector>

Expand Down Expand Up @@ -55,7 +57,9 @@ TEST(TombStoneTest, ConcurrentAddRemove) {
}

auto addFunc = [&t, hashes, &guards](int index) mutable {
std::random_shuffle(hashes.begin(), hashes.end());
std::random_device rd;
std::mt19937 g(rd());
std::shuffle(hashes.begin(), hashes.end(), g);
for (auto hash : hashes) {
guards[index].push_back(std::make_unique<TombStones::Guard>(t.add(hash)));
}
Expand All @@ -67,7 +71,9 @@ TEST(TombStoneTest, ConcurrentAddRemove) {
}

auto removeFunc = [&guards](int index) mutable {
std::random_shuffle(guards[index].begin(), guards[index].end());
std::random_device rd;
std::mt19937 g(rd());
std::shuffle(guards[index].begin(), guards[index].end(), g);
for (auto& guard : guards[index]) {
// destroy the guard
guard.reset();
Expand Down

0 comments on commit 68351f4

Please sign in to comment.