File: use-ranges.rst

package info (click to toggle)
llvm-toolchain-19 1%3A19.1.7-3
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 1,998,520 kB
  • sloc: cpp: 6,951,680; ansic: 1,486,157; asm: 913,598; python: 232,024; f90: 80,126; objc: 75,281; lisp: 37,276; pascal: 16,990; sh: 10,009; ml: 5,058; perl: 4,724; awk: 3,523; makefile: 3,167; javascript: 2,504; xml: 892; fortran: 664; cs: 573
file content (187 lines) | stat: -rw-r--r-- 4,121 bytes parent folder | download | duplicates (6)
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
.. title:: clang-tidy - boost-use-ranges

boost-use-ranges
================

Detects calls to standard library iterator algorithms that could be replaced
with a Boost ranges version instead.

Example
-------

.. code-block:: c++

  auto Iter1 = std::find(Items.begin(), Items.end(), 0);
  auto AreSame = std::equal(Items1.cbegin(), Items1.cend(), std::begin(Items2),
                            std::end(Items2));


Transforms to:

.. code-block:: c++

  auto Iter1 = boost::range::find(Items, 0);
  auto AreSame = boost::range::equal(Items1, Items2);

Supported algorithms
--------------------

Calls to the following std library algorithms are checked:

``std::accumulate``,
``std::adjacent_difference``,
``std::adjacent_find``,
``std::all_of``,
``std::any_of``,
``std::binary_search``,
``std::copy_backward``,
``std::copy_if``,
``std::copy``,
``std::count_if``,
``std::count``,
``std::equal_range``,
``std::equal``,
``std::fill``,
``std::find_end``,
``std::find_first_of``,
``std::find_if_not``,
``std::find_if``,
``std::find``,
``std::for_each``,
``std::generate``,
``std::includes``,
``std::iota``,
``std::is_partitioned``,
``std::is_permutation``,
``std::is_sorted_until``,
``std::is_sorted``,
``std::lexicographical_compare``,
``std::lower_bound``,
``std::make_heap``,
``std::max_element``,
``std::merge``,
``std::min_element``,
``std::mismatch``,
``std::next_permutation``,
``std::none_of``,
``std::parital_sum``,
``std::partial_sort_copy``,
``std::partition_copy``,
``std::partition_point``,
``std::partition``,
``std::pop_heap``,
``std::prev_permutation``,
``std::push_heap``,
``std::random_shuffle``,
``std::reduce``,
``std::remove_copy_if``,
``std::remove_copy``,
``std::remove_if``,
``std::remove``,
``std::replace_copy_if``,
``std::replace_copy``,
``std::replace_if``,
``std::replace``,
``std::reverse_copy``,
``std::reverse``,
``std::search``,
``std::set_difference``,
``std::set_intersection``,
``std::set_symmetric_difference``,
``std::set_union``,
``std::sort_heap``,
``std::sort``,
``std::stable_partition``,
``std::stable_sort``,
``std::transform``,
``std::unique_copy``,
``std::unique``,
``std::upper_bound``.

The check will also look for the following functions from the
``boost::algorithm`` namespace:

``all_of_equal``,
``any_of_equal``,
``any_of``,
``apply_permutation``,
``apply_reverse_permutation``,
``clamp_range``,
``copy_if_until``,
``copy_if_while``,
``copy_if``,
``copy_until``,
``copy_while``,
``find_backward``,
``find_if_backward``,
``find_if_not_backward``,
``find_if_not``,
``find_not_backward``,
``hex_lower``,
``hex``,
``iota``, ``all_of``,
``is_decreasing``,
``is_increasing``,
``is_palindrome``,
``is_partitioned_until``,
``is_partitioned``,
``is_permutation``,
``is_sorted_until``,
``is_sorted``,
``is_strictly_decreasing``,
``is_strictly_increasing``,
``none_of_equal``,
``none_of``,
``one_of_equal``,
``one_of``,
``partition_copy``,
``partition_point``,
``reduce``,
``unhex``.

Reverse Iteration
-----------------

If calls are made using reverse iterators on containers, The code will be
fixed using the ``boost::adaptors::reverse`` adaptor.

.. code-block:: c++
  
  auto AreSame = std::equal(Items1.rbegin(), Items1.rend(),
                            std::crbegin(Items2), std::crend(Items2));

Transforms to:

.. code-block:: c++

  auto AreSame = boost::range::equal(boost::adaptors::reverse(Items1),
                                     boost::adaptors::reverse(Items2));

Options
-------

.. option:: IncludeStyle

   A string specifying which include-style is used, `llvm` or `google`. Default
   is `llvm`.

.. option:: IncludeBoostSystem
   
   If `true` (default value) the boost headers are included as system headers
   with angle brackets (`#include <boost.hpp>`), otherwise quotes are used
   (`#include "boost.hpp"`).

.. option:: UseReversePipe

  When `true` (default `false`), fixes which involve reverse ranges will use the
  pipe adaptor syntax instead of the function syntax.

  .. code-block:: c++

    std::find(Items.rbegin(), Items.rend(), 0);

  Transforms to:

  .. code-block:: c++

    boost::range::find(Items | boost::adaptors::reversed, 0);