[libcxx-commits] [libcxx] [libcxx] adds ranges::fold_left_with_iter and ranges::fold_left (PR #75259)
via libcxx-commits
libcxx-commits at lists.llvm.org
Thu Dec 14 17:40:08 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}}
----------------
EricWF wrote:
Sure. the binary operator can contain state. That state can be consumed after the algorithm has run. Consider an addition operator that checked for overflows and reported that out-of-band.
It may not be good code, but it's correct code.
https://github.com/llvm/llvm-project/pull/75259
More information about the libcxx-commits
mailing list