File: use-ranges.cpp

package info (click to toggle)
llvm-toolchain-20 1%3A20.1.8-1~exp1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 2,111,388 kB
  • sloc: cpp: 7,438,767; ansic: 1,393,871; asm: 1,012,926; python: 241,728; f90: 86,635; objc: 75,411; lisp: 42,144; pascal: 17,286; sh: 10,027; ml: 5,082; perl: 4,730; awk: 3,523; makefile: 3,349; javascript: 2,251; xml: 892; fortran: 672
file content (91 lines) | stat: -rw-r--r-- 4,358 bytes parent folder | download | duplicates (16)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// RUN: %check_clang_tidy -std=c++14 %s boost-use-ranges %t  -- -- -I %S/Inputs/use-ranges/
// RUN: %check_clang_tidy -std=c++17 %s boost-use-ranges %t -check-suffixes=,CPP17 -- -I %S/Inputs/use-ranges/

// CHECK-FIXES: #include <boost/range/algorithm/find.hpp>
// CHECK-FIXES: #include <boost/range/algorithm/reverse.hpp>
// CHECK-FIXES: #include <boost/range/algorithm/set_algorithm.hpp>
// CHECK-FIXES: #include <boost/range/algorithm/equal.hpp>
// CHECK-FIXES: #include <boost/range/algorithm/permutation.hpp>
// CHECK-FIXES: #include <boost/range/algorithm/heap_algorithm.hpp>
// CHECK-FIXES: #include <boost/algorithm/cxx11/copy_if.hpp>
// CHECK-FIXES: #include <boost/algorithm/cxx11/is_sorted.hpp>
// CHECK-FIXES-CPP17: #include <boost/algorithm/cxx17/reduce.hpp>
// CHECK-FIXES: #include <boost/range/adaptor/reversed.hpp>
// CHECK-FIXES: #include <boost/range/numeric.hpp>

#include "fake_boost.h"
#include "fake_std.h"

bool returnTrue(int val) {
  return true;
}

void stdLib() {
  std::vector<int> I, J;
  std::find(I.begin(), I.end(), 0);
  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use a boost version of this algorithm
  // CHECK-FIXES: boost::range::find(I, 0);

  std::reverse(I.cbegin(), I.cend());
  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use a boost version of this algorithm
  // CHECK-FIXES: boost::range::reverse(I);

  std::includes(I.begin(), I.end(), std::begin(J), std::end(J));
  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use a boost version of this algorithm
  // CHECK-FIXES: boost::range::includes(I, J);

  std::equal(std::cbegin(I), std::cend(I), J.begin(), J.end());
  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use a boost version of this algorithm
  // CHECK-FIXES: boost::range::equal(I, J);

  std::next_permutation(I.begin(), I.end());
  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use a boost version of this algorithm
  // CHECK-FIXES: boost::range::next_permutation(I);

  std::push_heap(I.begin(), I.end());
  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use a boost version of this algorithm
  // CHECK-FIXES: boost::range::push_heap(I);

  std::copy_if(I.begin(), I.end(), J.begin(), &returnTrue);
  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use a boost version of this algorithm
  // CHECK-FIXES: boost::algorithm::copy_if(I, J.begin(), &returnTrue);

  std::is_sorted_until(I.begin(), I.end());
  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use a boost version of this algorithm
  // CHECK-FIXES: boost::algorithm::is_sorted_until(I);

  std::reduce(I.begin(), I.end());
  // CHECK-MESSAGES-CPP17: :[[@LINE-1]]:3: warning: use a boost version of this algorithm
  // CHECK-FIXES-CPP17: boost::algorithm::reduce(I);

  std::reduce(I.begin(), I.end(), 2);
  // CHECK-MESSAGES-CPP17: :[[@LINE-1]]:3: warning: use a boost version of this algorithm
  // CHECK-FIXES-CPP17: boost::algorithm::reduce(I, 2);

  std::reduce(I.begin(), I.end(), 0, [](int a, int b){ return a + b; });
  // CHECK-MESSAGES-CPP17: :[[@LINE-1]]:3: warning: use a boost version of this algorithm
  // CHECK-FIXES-CPP17: boost::algorithm::reduce(I, 0, [](int a, int b){ return a + b; });

  std::equal(boost::rbegin(I), boost::rend(I), J.begin(), J.end());
  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use a boost version of this algorithm
  // CHECK-FIXES: boost::range::equal(boost::adaptors::reverse(I), J);

  std::accumulate(I.begin(), I.end(), 0);
  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use a boost version of this algorithm
  // CHECK-FIXES: boost::accumulate(I, 0);
}

void boostLib() {
  std::vector<int> I;
  boost::algorithm::reduce(I.begin(), I.end(), 0, [](int a, int b){ return a + b; });
  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use a ranged version of this algorithm
  // CHECK-FIXES: boost::algorithm::reduce(I, 0, [](int a, int b){ return a + b; });

  boost::algorithm::reduce(boost::begin(I), boost::end(I), 1, [](int a, int b){ return a + b; });
  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use a ranged version of this algorithm
  // CHECK-FIXES: boost::algorithm::reduce(I, 1, [](int a, int b){ return a + b; });

  boost::algorithm::reduce(boost::const_begin(I), boost::const_end(I), 2, [](int a, int b){ return a + b; });
  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use a ranged version of this algorithm
  // CHECK-FIXES: boost::algorithm::reduce(I, 2, [](int a, int b){ return a + b; });
}