[clang-tools-extra] Add clang-tidy check to suggest replacement of conditional statement with std::min/std::max (PR #77816)

via cfe-commits cfe-commits at lists.llvm.org
Fri Jan 12 07:31:23 PST 2024


================
@@ -0,0 +1,33 @@
+.. title:: clang-tidy - readability-use-std-min-max
+
+readability-use-std-min-max
+===========================
+
+Replaces certain conditional statements with equivalent ``std::min`` or ``std::max`` expressions, 
+improving readability and promoting the use of standard library functions.
+Note: While this transformation improves code clarity, it may not be
+suitable for performance-critical code. Using ``std::min`` or ``std::max`` can
+introduce additional stores, potentially impacting performance compared to
+the original if statement that only assigns when the value needs to change.
+
+Examples:
+
+Before:
+
+.. code-block:: c++
+
+  void foo(){
----------------
EugeneZelenko wrote:

Please Clang-format both snippets.

https://github.com/llvm/llvm-project/pull/77816


More information about the cfe-commits mailing list