| 1 |
.. title:: clang-tidy - boost-use-ranges |
| 2 |
|
| 3 |
boost-use-ranges |
| 4 |
================ |
| 5 |
|
| 6 |
Detects calls to standard library iterator algorithms that could be replaced |
| 7 |
with a Boost ranges version instead. |
| 8 |
|
| 9 |
Example |
| 10 |
------- |
| 11 |
|
| 12 |
.. code-block:: c++ |
| 13 |
|
| 14 |
auto Iter1 = std::find(Items.begin(), Items.end(), 0); |
| 15 |
auto AreSame = std::equal(Items1.cbegin(), Items1.cend(), std::begin(Items2), |
| 16 |
std::end(Items2)); |
| 17 |
|
| 18 |
|
| 19 |
Transforms to: |
| 20 |
|
| 21 |
.. code-block:: c++ |
| 22 |
|
| 23 |
auto Iter1 = boost::range::find(Items, 0); |
| 24 |
auto AreSame = boost::range::equal(Items1, Items2); |
| 25 |
|
| 26 |
Supported algorithms |
| 27 |
-------------------- |
| 28 |
|
| 29 |
Calls to the following std library algorithms are checked: |
| 30 |
|
| 31 |
``std::accumulate``, |
| 32 |
``std::adjacent_difference``, |
| 33 |
``std::adjacent_find``, |
| 34 |
``std::all_of``, |
| 35 |
``std::any_of``, |
| 36 |
``std::binary_search``, |
| 37 |
``std::copy_backward``, |
| 38 |
``std::copy_if``, |
| 39 |
``std::copy``, |
| 40 |
``std::count_if``, |
| 41 |
``std::count``, |
| 42 |
``std::equal_range``, |
| 43 |
``std::equal``, |
| 44 |
``std::fill``, |
| 45 |
``std::find_end``, |
| 46 |
``std::find_first_of``, |
| 47 |
``std::find_if_not``, |
| 48 |
``std::find_if``, |
| 49 |
``std::find``, |
| 50 |
``std::for_each``, |
| 51 |
``std::generate``, |
| 52 |
``std::includes``, |
| 53 |
``std::iota``, |
| 54 |
``std::is_partitioned``, |
| 55 |
``std::is_permutation``, |
| 56 |
``std::is_sorted_until``, |
| 57 |
``std::is_sorted``, |
| 58 |
``std::lexicographical_compare``, |
| 59 |
``std::lower_bound``, |
| 60 |
``std::make_heap``, |
| 61 |
``std::max_element``, |
| 62 |
``std::merge``, |
| 63 |
``std::min_element``, |
| 64 |
``std::mismatch``, |
| 65 |
``std::next_permutation``, |
| 66 |
``std::none_of``, |
| 67 |
``std::parital_sum``, |
| 68 |
``std::partial_sort_copy``, |
| 69 |
``std::partition_copy``, |
| 70 |
``std::partition_point``, |
| 71 |
``std::partition``, |
| 72 |
``std::pop_heap``, |
| 73 |
``std::prev_permutation``, |
| 74 |
``std::push_heap``, |
| 75 |
``std::random_shuffle``, |
| 76 |
``std::reduce``, |
| 77 |
``std::remove_copy_if``, |
| 78 |
``std::remove_copy``, |
| 79 |
``std::remove_if``, |
| 80 |
``std::remove``, |
| 81 |
``std::replace_copy_if``, |
| 82 |
``std::replace_copy``, |
| 83 |
``std::replace_if``, |
| 84 |
``std::replace``, |
| 85 |
``std::reverse_copy``, |
| 86 |
``std::reverse``, |
| 87 |
``std::search``, |
| 88 |
``std::set_difference``, |
| 89 |
``std::set_intersection``, |
| 90 |
``std::set_symmetric_difference``, |
| 91 |
``std::set_union``, |
| 92 |
``std::sort_heap``, |
| 93 |
``std::sort``, |
| 94 |
``std::stable_partition``, |
| 95 |
``std::stable_sort``, |
| 96 |
``std::transform``, |
| 97 |
``std::unique_copy``, |
| 98 |
``std::unique``, |
| 99 |
``std::upper_bound``. |
| 100 |
|
| 101 |
The check will also look for the following functions from the |
| 102 |
``boost::algorithm`` namespace: |
| 103 |
|
| 104 |
``all_of_equal``, |
| 105 |
``any_of_equal``, |
| 106 |
``any_of``, |
| 107 |
``apply_permutation``, |
| 108 |
``apply_reverse_permutation``, |
| 109 |
``clamp_range``, |
| 110 |
``copy_if_until``, |
| 111 |
``copy_if_while``, |
| 112 |
``copy_if``, |
| 113 |
``copy_until``, |
| 114 |
``copy_while``, |
| 115 |
``find_backward``, |
| 116 |
``find_if_backward``, |
| 117 |
``find_if_not_backward``, |
| 118 |
``find_if_not``, |
| 119 |
``find_not_backward``, |
| 120 |
``hex_lower``, |
| 121 |
``hex``, |
| 122 |
``iota``, ``all_of``, |
| 123 |
``is_decreasing``, |
| 124 |
``is_increasing``, |
| 125 |
``is_palindrome``, |
| 126 |
``is_partitioned_until``, |
| 127 |
``is_partitioned``, |
| 128 |
``is_permutation``, |
| 129 |
``is_sorted_until``, |
| 130 |
``is_sorted``, |
| 131 |
``is_strictly_decreasing``, |
| 132 |
``is_strictly_increasing``, |
| 133 |
``none_of_equal``, |
| 134 |
``none_of``, |
| 135 |
``one_of_equal``, |
| 136 |
``one_of``, |
| 137 |
``partition_copy``, |
| 138 |
``partition_point``, |
| 139 |
``reduce``, |
| 140 |
``unhex``. |
| 141 |
|
| 142 |
Reverse Iteration |
| 143 |
----------------- |
| 144 |
|
| 145 |
If calls are made using reverse iterators on containers, The code will be |
| 146 |
fixed using the ``boost::adaptors::reverse`` adaptor. |
| 147 |
|
| 148 |
.. code-block:: c++ |
| 149 |
|
| 150 |
auto AreSame = std::equal(Items1.rbegin(), Items1.rend(), |
| 151 |
std::crbegin(Items2), std::crend(Items2)); |
| 152 |
|
| 153 |
Transforms to: |
| 154 |
|
| 155 |
.. code-block:: c++ |
| 156 |
|
| 157 |
auto AreSame = boost::range::equal(boost::adaptors::reverse(Items1), |
| 158 |
boost::adaptors::reverse(Items2)); |
| 159 |
|
| 160 |
Options |
| 161 |
------- |
| 162 |
|
| 163 |
.. option:: IncludeStyle |
| 164 |
|
| 165 |
A string specifying which include-style is used, `llvm` or `google`. Default |
| 166 |
is `llvm`. |
| 167 |
|
| 168 |
.. option:: IncludeBoostSystem |
| 169 |
|
| 170 |
If `true` (default value) the boost headers are included as system headers |
| 171 |
with angle brackets (`#include <boost.hpp>`), otherwise quotes are used |
| 172 |
(`#include "boost.hpp"`). |
| 173 |
|
| 174 |
.. option:: UseReversePipe |
| 175 |
|
| 176 |
When `true` (default `false`), fixes which involve reverse ranges will use the |
| 177 |
pipe adaptor syntax instead of the function syntax. |
| 178 |
|
| 179 |
.. code-block:: c++ |
| 180 |
|
| 181 |
std::find(Items.rbegin(), Items.rend(), 0); |
| 182 |
|
| 183 |
Transforms to: |
| 184 |
|
| 185 |
.. code-block:: c++ |
| 186 |
|
| 187 |
boost::range::find(Items | boost::adaptors::reversed, 0); |