[libcxx-commits] [clang] [libcxx] [clang-tools-extra] [llvm] [libcxx] adds ranges::fold_left_with_iter and ranges::fold_left (PR #75259)
Christopher Di Bella via libcxx-commits
libcxx-commits at lists.llvm.org
Tue Dec 19 11:13:55 PST 2023
================
@@ -87,4 +89,15 @@ void test() {
std::ranges::unique(iter, iter); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
std::ranges::upper_bound(range, 1); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
std::ranges::upper_bound(iter, iter, 1); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
+
+#if TEST_STD_VER >= 23
+ std::ranges::fold_left(range, 0, std::plus());
+ // expected-warning at -1{{ignoring return value of function declared with 'nodiscard' attribute}}
----------------
cjdb wrote:
I think it's substantially better to be explicit about wanting to discard the result, since the primary function of this algorithm is to return a computed result. I also expect the common case to be to want the result, rather than not.
```cpp
(void)std::ranges::fold_left(r, 0, side_effect_f); // clearly discarding the result
```
https://github.com/llvm/llvm-project/pull/75259
More information about the libcxx-commits
mailing list