[clang] [clang-format] Add Natural option for SortIncludes (PR #210788)

Tshaka Lekholoane via cfe-commits cfe-commits at lists.llvm.org
Mon Jul 27 04:45:22 PDT 2026


================
@@ -3647,10 +3660,25 @@ static void sortCppIncludes(const FormatStyle &Style,
         LHSFilenameLower = Includes[LHSI].Filename.lower();
         RHSFilenameLower = Includes[RHSI].Filename.lower();
       }
-      return std::tie(Includes[LHSI].Priority, LHSStemLower, LHSStem,
-                      LHSFilenameLower, Includes[LHSI].Filename) <
-             std::tie(Includes[RHSI].Priority, RHSStemLower, RHSStem,
-                      RHSFilenameLower, Includes[RHSI].Filename);
+
+      const auto Compare = Style.SortIncludes.Natural
+                               ? &StringRef::compare_numeric
+                               : &StringRef::compare;
+
+      if (Style.SortIncludes.IgnoreCase) {
+        if (int Cmp = (StringRef(LHSStemLower).*Compare)(RHSStemLower))
----------------
tshakalekholoane wrote:

I assume you mean `std::invoke`? `std::apply` would require packing the arguments into tuples and a [possible implementation of this](https://en.cppreference.com/cpp/utility/apply#Possible_implementation) seems to just forward to `std::invoke`.

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


More information about the cfe-commits mailing list