[libcxx-commits] [libcxx] [libc++][ranges] Applied [[nodiscard]] to `adjacent_transform_view` (PR #205900)
Lucas Mellone via libcxx-commits
libcxx-commits at lists.llvm.org
Tue Jun 30 04:41:36 PDT 2026
================
@@ -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
+//
+//===----------------------------------------------------------------------===//
+
+// REQUIRES: std-at-least-c++23
+
+// Test the libc++ extension that std::ranges::adjacent_transform_view and std::views::adjacent_transform are marked as [[nodiscard]].
+
+#include <ranges>
+#include <utility>
+#include <functional>
+
+struct View : std::ranges::view_interface<View> {
+ int* begin();
+ const int* begin() const;
+ volatile int* end();
+ const volatile int* end() const;
+};
+static_assert(!std::ranges::common_range<View>);
+static_assert(!std::same_as<std::ranges::iterator_t<View>, std::ranges::iterator_t<const View>>);
+static_assert(!std::same_as<std::ranges::sentinel_t<View>, std::ranges::sentinel_t<const View>>);
+
+void test() {
+ int range[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
----------------
lknknm wrote:
I was following the same way I've done in the `adjacent_view` nodiscard tests. What I can do is to move it down for this test and then apply the same as a follow-up to `adjacent_view`.
For the CPO testing, I think as a matter of example testing an `int` range like this aligns well with some examples in the Standard (https://eel.is/c++draft/range.adjacent.transform#overview-3).
But I probably done wrong, instead of:
```cpp
std::views::adjacent_transform<2>(range);
```
I should probably do:
```cpp
std::views::adjacent_transform<2>(range, std::multiplies());
```
So this aligns well with the example in the Standard and compiles normally. What do you think?
https://github.com/llvm/llvm-project/pull/205900
More information about the libcxx-commits
mailing list