| 1 | // RUN: %check_clang_tidy -std=c++14 %s boost-use-ranges %t -- -- -I %S/Inputs/use-ranges/ |
| 2 | // RUN: %check_clang_tidy -std=c++17 %s boost-use-ranges %t -check-suffixes=,CPP17 -- -I %S/Inputs/use-ranges/ |
| 3 | |
| 4 | // CHECK-FIXES: #include <boost/range/algorithm/find.hpp> |
| 5 | // CHECK-FIXES: #include <boost/range/algorithm/reverse.hpp> |
| 6 | // CHECK-FIXES: #include <boost/range/algorithm/set_algorithm.hpp> |
| 7 | // CHECK-FIXES: #include <boost/range/algorithm/equal.hpp> |
| 8 | // CHECK-FIXES: #include <boost/range/algorithm/permutation.hpp> |
| 9 | // CHECK-FIXES: #include <boost/range/algorithm/heap_algorithm.hpp> |
| 10 | // CHECK-FIXES: #include <boost/algorithm/cxx11/copy_if.hpp> |
| 11 | // CHECK-FIXES: #include <boost/algorithm/cxx11/is_sorted.hpp> |
| 12 | // CHECK-FIXES-CPP17: #include <boost/algorithm/cxx17/reduce.hpp> |
| 13 | // CHECK-FIXES: #include <boost/range/adaptor/reversed.hpp> |
| 14 | // CHECK-FIXES: #include <boost/range/numeric.hpp> |
| 15 | |
| 16 | #include "fake_boost.h" |
| 17 | #include "fake_std.h" |
| 18 | |
| 19 | bool returnTrue(int val) { |
| 20 | return true; |
| 21 | } |
| 22 | |
| 23 | void stdLib() { |
| 24 | std::vector<int> I, J; |
| 25 | std::find(I.begin(), I.end(), 0); |
| 26 | // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use a boost version of this algorithm |
| 27 | // CHECK-FIXES: boost::range::find(I, 0); |
| 28 | |
| 29 | std::reverse(I.cbegin(), I.cend()); |
| 30 | // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use a boost version of this algorithm |
| 31 | // CHECK-FIXES: boost::range::reverse(I); |
| 32 | |
| 33 | std::includes(I.begin(), I.end(), std::begin(J), std::end(J)); |
| 34 | // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use a boost version of this algorithm |
| 35 | // CHECK-FIXES: boost::range::includes(I, J); |
| 36 | |
| 37 | std::equal(std::cbegin(I), std::cend(I), J.begin(), J.end()); |
| 38 | // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use a boost version of this algorithm |
| 39 | // CHECK-FIXES: boost::range::equal(I, J); |
| 40 | |
| 41 | std::next_permutation(I.begin(), I.end()); |
| 42 | // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use a boost version of this algorithm |
| 43 | // CHECK-FIXES: boost::range::next_permutation(I); |
| 44 | |
| 45 | std::push_heap(I.begin(), I.end()); |
| 46 | // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use a boost version of this algorithm |
| 47 | // CHECK-FIXES: boost::range::push_heap(I); |
| 48 | |
| 49 | std::copy_if(I.begin(), I.end(), J.begin(), &returnTrue); |
| 50 | // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use a boost version of this algorithm |
| 51 | // CHECK-FIXES: boost::algorithm::copy_if(I, J.begin(), &returnTrue); |
| 52 | |
| 53 | std::is_sorted_until(I.begin(), I.end()); |
| 54 | // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use a boost version of this algorithm |
| 55 | // CHECK-FIXES: boost::algorithm::is_sorted_until(I); |
| 56 | |
| 57 | std::reduce(I.begin(), I.end()); |
| 58 | // CHECK-MESSAGES-CPP17: :[[@LINE-1]]:3: warning: use a boost version of this algorithm |
| 59 | // CHECK-FIXES-CPP17: boost::algorithm::reduce(I); |
| 60 | |
| 61 | std::reduce(I.begin(), I.end(), 2); |
| 62 | // CHECK-MESSAGES-CPP17: :[[@LINE-1]]:3: warning: use a boost version of this algorithm |
| 63 | // CHECK-FIXES-CPP17: boost::algorithm::reduce(I, 2); |
| 64 | |
| 65 | std::reduce(I.begin(), I.end(), 0, [](int a, int b){ return a + b; }); |
| 66 | // CHECK-MESSAGES-CPP17: :[[@LINE-1]]:3: warning: use a boost version of this algorithm |
| 67 | // CHECK-FIXES-CPP17: boost::algorithm::reduce(I, 0, [](int a, int b){ return a + b; }); |
| 68 | |
| 69 | std::equal(boost::rbegin(I), boost::rend(I), J.begin(), J.end()); |
| 70 | // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use a boost version of this algorithm |
| 71 | // CHECK-FIXES: boost::range::equal(boost::adaptors::reverse(I), J); |
| 72 | |
| 73 | std::accumulate(I.begin(), I.end(), 0); |
| 74 | // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use a boost version of this algorithm |
| 75 | // CHECK-FIXES: boost::accumulate(I, 0); |
| 76 | } |
| 77 | |
| 78 | void boostLib() { |
| 79 | std::vector<int> I; |
| 80 | boost::algorithm::reduce(I.begin(), I.end(), 0, [](int a, int b){ return a + b; }); |
| 81 | // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use a ranged version of this algorithm |
| 82 | // CHECK-FIXES: boost::algorithm::reduce(I, 0, [](int a, int b){ return a + b; }); |
| 83 | |
| 84 | boost::algorithm::reduce(boost::begin(I), boost::end(I), 1, [](int a, int b){ return a + b; }); |
| 85 | // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use a ranged version of this algorithm |
| 86 | // CHECK-FIXES: boost::algorithm::reduce(I, 1, [](int a, int b){ return a + b; }); |
| 87 | |
| 88 | boost::algorithm::reduce(boost::const_begin(I), boost::const_end(I), 2, [](int a, int b){ return a + b; }); |
| 89 | // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use a ranged version of this algorithm |
| 90 | // CHECK-FIXES: boost::algorithm::reduce(I, 2, [](int a, int b){ return a + b; }); |
| 91 | } |
| 92 | |