[lld] [clang] [clang-tools-extra] [libcxx] [compiler-rt] [flang] [llvm] [libc++][ranges] P2116R9: Implements `views::enumerate` (PR #73617)

Hristo Hristov via cfe-commits cfe-commits at lists.llvm.org
Mon Jan 1 06:07:00 PST 2024


================
@@ -0,0 +1,71 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
+
+// <ranges>
+
+// class enumerate_view
+
+// class enumerate_view::sentinel
+
+// template<bool OtherConst>
+//   requires sentinel_for<sentinel_t<Base>, iterator_t<maybe-const<OtherConst, V>>>
+// friend constexpr bool operator==(const iterator<OtherConst>& x, const sentinel& y);
+
+#include <ranges>
+
+#include <array>
+#include <cassert>
+#include <concepts>
+#include <utility>
+
+#include "test_iterators.h"
+#include "../types.h"
+
+template <class Iterator, class Sentinel = sentinel_wrapper<Iterator>>
+constexpr void test() {
+  using View = MinimalView<Iterator, Sentinel>;
+
+  std::array array{0, 1, 2, 3, 84};
+
+  View v(Iterator(array.begin()), Sentinel(Iterator(array.end())));
+  std::ranges::enumerate_view view(std::move(v));
+
+  auto const it = view.begin();
+  auto const s  = view.end();
+
+  std::same_as<bool> decltype(auto) eqItSResult = (it == s);
+  assert(!eqItSResult);
+  std::same_as<bool> decltype(auto) eqSItResult = (s == it);
+  assert(!eqSItResult);
+
+  std::same_as<bool> decltype(auto) neqItSResult = (it != s);
+  assert(neqItSResult);
+  std::same_as<bool> decltype(auto) neqSItResult = (s != it);
+  assert(neqSItResult);
+}
+
+constexpr bool tests() {
+  test<cpp17_input_iterator<int*>>();
----------------
H-G-Hristov wrote:

I'll keep this as is for now. If we do the suggested changes, I'll prefer to do them after everything else is ironed out.

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


More information about the cfe-commits mailing list