[libcxx-commits] [libcxx] [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
Mon Dec 18 17:15:57 PST 2023
================
@@ -0,0 +1,93 @@
+//===----------------------------------------------------------------------===//
+//
+// 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(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(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() {
+ {
+ auto data = std::vector<int>{1, 2, 3, 4};
+ auto const result = std::ranges::fold_left(data.begin(), data.begin(), 0, std::plus());
+
+ assert(result == 0);
+
+ auto range = std::span(data.data(), 0);
+ assert(std::ranges::fold_left(range, 0, std::plus()) == result);
+ }
----------------
cjdb wrote:
I've partially done this. There are some cases where the test cases are identical, but have extra things attached, and having those be adjacent is sorta good for showing that? WDYT?
https://github.com/llvm/llvm-project/pull/75259
More information about the libcxx-commits
mailing list