[libcxx-commits] [libcxx] [libc++][ranges] P2164R9: Implements `views::enumerate` (PR #73617)
A. Jiang via libcxx-commits
libcxx-commits at lists.llvm.org
Sat Dec 27 01:47:48 PST 2025
================
@@ -0,0 +1,84 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+
+// Check that functions are marked [[nodiscard]]
+
+#include <ranges>
+#include <utility>
+#include <vector>
+
+void test() {
+ std::vector<int> range;
+
+ // [range.enumerate.view]
+
+ auto ev = std::ranges::subrange(range.begin(), range.end() - 1) | std::views::enumerate;
+
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ ev.begin();
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ std::as_const(ev).begin();
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ ev.end();
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ std::as_const(ev).end();
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ ev.size();
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ std::as_const(ev).size();
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ ev.base();
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ std::move(ev).base();
+
+ // [range.enumerate.iterator]
+
+ auto it = ev.begin();
+ // auto const_it = std::as_const(ev).begin();
----------------
frederick-vs-ja wrote:
Looks like that you wanted to verify iterator and sentinel of a const view which is not _`simple-view`_?
https://github.com/llvm/llvm-project/pull/73617
More information about the libcxx-commits
mailing list