Skip to content

Commit a950e7a

Browse files
committed
TEST/IODEMO: Use std::shuffle when available
random_shuffle was deprecated in C++14 and completely removed in C++17. With newer compilers like Clang 21, the build fails. This commit should preserve older behavior and use std::shuffle when available. Signed-off-by: Brahmajit Das <[email protected]>
1 parent 3c12be3 commit a950e7a

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

test/apps/iodemo/io_demo.cc

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <csignal>
2020
#include <cerrno>
2121
#include <vector>
22+
#include <random>
2223
#include <map>
2324
#include <queue>
2425
#include <algorithm>
@@ -2998,9 +2999,17 @@ static int do_client(options_t& test_opts)
29982999
IoDemoRandom::srand(test_opts.random_seed);
29993000
LOG << "random seed: " << test_opts.random_seed;
30003001

3001-
// randomize servers to optimize startup
3002+
// randomize servers to optimize startup (handle C++17+)
3003+
#if __cplusplus >= 201703L
3004+
// std::shuffle replaces std::random_shuffle in C++17
3005+
std::random_device rd;
3006+
std::mt19937 rng(rd());
3007+
std::shuffle(test_opts.servers.begin(), test_opts.servers.end(), rng);
3008+
#else
3009+
// For older C++ standards, keep std::random_shuffle
30023010
std::random_shuffle(test_opts.servers.begin(), test_opts.servers.end(),
30033011
IoDemoRandom::urand<size_t>);
3012+
#endif
30043013

30053014
UcxLog vlog(LOG_PREFIX, test_opts.verbose);
30063015
vlog << "List of servers:";

0 commit comments

Comments
 (0)