[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 15:37:37 PST 2023
================
@@ -0,0 +1,116 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// <algorithm>
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
+
+// template<input_iterator I, sentinel_for<I> S, class T,
+// indirectly-binary-left-foldable<T, I> F>
+// constexpr see below ranges::fold_left_with_iter(I first, S last, T init, F f);
+//
+// template<input_range R, class T, indirectly-binary-left-foldable<T, iterator_t<R>> F>
+// constexpr see below ranges::fold_left_with_iter(R&& r, T init, F f);
+
+#include <algorithm>
+#include <cassert>
+#include <vector>
+#include <functional>
+
+#include "test_range.h"
+#include "../gaussian_sum.h"
+
+constexpr bool test() {
----------------
EricWF wrote:
I would add runtime tests for:
1. An empty range
2. A range where summing in any order other than `fold_left` would result in an overflow or other invalid condition.
3. That we don't copy the functor like we intend.
4. That the functor is applied the correct amount of times.
5. On non-integral or builtin types.
6. On types other than vector & its iterators.
I understand the signatures for a lot of these configurations are checked via meta-programming elsewhere, but we need to run code to test them too. What if there's a lifetime bug that wouldn't be caught unless the type were' folding allocates?
https://github.com/llvm/llvm-project/pull/75259
More information about the libcxx-commits
mailing list