1// RUN: %check_clang_tidy %s modernize-replace-random-shuffle %t
2
3//CHECK-FIXES: #include <random>
4
5namespace std {
6template <typename T> struct vec_iterator {
7 T *ptr;
8 vec_iterator operator++(int);
9};
10
11template <typename T> struct vector {
12 typedef vec_iterator<T> iterator;
13
14 iterator begin();
15 iterator end();
16};
17
18template <typename FwIt>
19void random_shuffle(FwIt begin, FwIt end);
20
21template <typename FwIt, typename randomFunc>
22void random_shuffle(FwIt begin, FwIt end, randomFunc& randomfunc);
23
24template <typename FwIt>
25void shuffle(FwIt begin, FwIt end);
26} // namespace std
27
28// Random Func
29int myrandom (int i) { return i;}
30
31using namespace std;
32
33int main() {
34 std::vector<int> vec;
35
36 std::random_shuffle(begin: vec.begin(), end: vec.end());
37 // CHECK-MESSAGES: [[@LINE-1]]:3: warning: 'std::random_shuffle' has been removed in C++17; use 'std::shuffle' instead
38 // CHECK-FIXES: std::shuffle(vec.begin(), vec.end(), std::mt19937(std::random_device()()));
39
40 std::shuffle(begin: vec.begin(), end: vec.end());
41
42 random_shuffle(begin: vec.begin(), end: vec.end());
43 // CHECK-MESSAGES: [[@LINE-1]]:3: warning: 'std::random_shuffle' has been removed in C++17; use 'std::shuffle' instead
44 // CHECK-FIXES: shuffle(vec.begin(), vec.end(), std::mt19937(std::random_device()()));
45
46 std::random_shuffle(begin: vec.begin(), end: vec.end(), randomfunc&: myrandom);
47 // CHECK-MESSAGES: [[@LINE-1]]:3: warning: 'std::random_shuffle' has been removed in C++17; use 'std::shuffle' and an alternative random mechanism instead
48 // CHECK-FIXES: std::shuffle(vec.begin(), vec.end(), std::mt19937(std::random_device()()));
49
50 random_shuffle(begin: vec.begin(), end: vec.end(), randomfunc&: myrandom);
51 // CHECK-MESSAGES: [[@LINE-1]]:3: warning: 'std::random_shuffle' has been removed in C++17; use 'std::shuffle' and an alternative random mechanism instead
52 // CHECK-FIXES: shuffle(vec.begin(), vec.end(), std::mt19937(std::random_device()()));
53
54 shuffle(begin: vec.begin(), end: vec.end());
55
56 return 0;
57}
58

source code of clang-tools-extra/test/clang-tidy/checkers/modernize/replace-random-shuffle.cpp