[libcxx-commits] [libcxx] [libc++] Fix complexity guarantee in std::clamp (PR #68413)

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Tue Oct 10 10:40:45 PDT 2023


================
@@ -37,9 +37,10 @@ struct __fn {
     _LIBCPP_ASSERT_UNCATEGORIZED(!bool(std::invoke(__comp, std::invoke(__proj, __high), std::invoke(__proj, __low))),
                                  "Bad bounds passed to std::ranges::clamp");
 
-    if (std::invoke(__comp, std::invoke(__proj, __value), std::invoke(__proj, __low)))
+    auto&& __projected = std::invoke(__proj, __value);
----------------
ldionne wrote:

I don't understand. We're extending the lifetime here with rvalue references, is that what you would want to make more explicit? FWIW, this is how other implementations do it too, and lifetime extending with rvalue references is a fairly common pattern, so if that's what your concern is about my preference would be to keep it simple.

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


More information about the libcxx-commits mailing list