[libcxx-commits] [libcxx] [libc++][ranges] P2164R9: Implements `views::enumerate` (PR #73617)

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Thu Jan 8 15:11:24 PST 2026


================
@@ -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();
----------------
ldionne wrote:

Gentle ping on this.

https://github.com/llvm/llvm-project/pull/73617


More information about the libcxx-commits mailing list