| 1 |
.. title:: clang-tidy - readability-use-std-min-max |
| 2 |
|
| 3 |
readability-use-std-min-max |
| 4 |
=========================== |
| 5 |
|
| 6 |
Replaces certain conditional statements with equivalent calls to |
| 7 |
``std::min`` or ``std::max``. |
| 8 |
Note: This may impact performance in critical code due to potential |
| 9 |
additional stores compared to the original if statement. |
| 10 |
|
| 11 |
Before: |
| 12 |
|
| 13 |
.. code-block:: c++ |
| 14 |
|
| 15 |
void foo() { |
| 16 |
int a = 2, b = 3; |
| 17 |
if (a < b) |
| 18 |
a = b; |
| 19 |
} |
| 20 |
|
| 21 |
|
| 22 |
After: |
| 23 |
|
| 24 |
.. code-block:: c++ |
| 25 |
|
| 26 |
void foo() { |
| 27 |
int a = 2, b = 3; |
| 28 |
a = std::max(a, b); |
| 29 |
} |