[libcxx] [clang-tools-extra] [clang] [llvm] [libc++] Fix complexity guarantee in ranges::clamp (PR #68413)

Louis Dionne via cfe-commits cfe-commits at lists.llvm.org
Tue Oct 31 07:55:00 PDT 2023


================
@@ -37,9 +37,10 @@ struct __fn {
     _LIBCPP_ASSERT_UNCATEGORIZED(!bool(std::invoke(__comp, std::invoke(__proj, __high), std::invoke(__proj, __low))),
----------------
ldionne wrote:

@var-const I think we have an interesting case here. This assertion causes the complexity guarantee of `ranges::clamp` not to be satisfied when we enable this assertion, because `clamp` says that it should not apply the projection more than 3 times and the comparator more than twice.

This is a case where complexity is not about asymptotic behavior but really about a specific number of function applications.

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


More information about the cfe-commits mailing list