Skip to content

Commit 56456ab

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 56456ab

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

test/apps/iodemo/io_demo.cc

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <netinet/in.h>
1010
#include <arpa/inet.h>
1111
#include <sys/time.h>
12+
#include <algorithm>
1213
#include <iostream>
1314
#include <string.h>
1415
#include <getopt.h>
@@ -19,6 +20,7 @@
1920
#include <csignal>
2021
#include <cerrno>
2122
#include <vector>
23+
#include <random>
2224
#include <map>
2325
#include <queue>
2426
#include <algorithm>
@@ -2998,9 +3000,17 @@ static int do_client(options_t& test_opts)
29983000
IoDemoRandom::srand(test_opts.random_seed);
29993001
LOG << "random seed: " << test_opts.random_seed;
30003002

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

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

0 commit comments

Comments
 (0)