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

Konstantin Varlamov via libcxx-commits libcxx-commits at lists.llvm.org
Tue Dec 5 20:47:28 PST 2023


================
@@ -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
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
+
+// <ranges>
+
+// class enumerate_view
+
+// class enumerate_view::iterator
+
+// constexpr iterator(iterator<!Const> i)
+//   requires Const && convertible_to<iterator_t<V>, iterator_t<Base>>;
+
+#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>;
+  using EnumerateView          = std::ranges::enumerate_view<View>;
+  using EnumerateIterator      = std::ranges::iterator_t<EnumerateView>;
+  using EnumerateConstIterator = std::ranges::iterator_t<const EnumerateView>;
+
+  auto make_enumerate_view = [](auto begin, auto end) {
+    View view{Iterator(begin), Sentinel(Iterator(end))};
+
+    return EnumerateView(std::move(view));
+  };
+
+  static_assert(std::is_convertible_v<EnumerateIterator, EnumerateConstIterator>);
+
+  std::array array{0, 84, 2, 3, 4};
+  auto view = make_enumerate_view(array.begin(), array.end());
+  {
+    std::same_as<EnumerateIterator> decltype(auto) it     = view.begin();
----------------
var-const wrote:

Is this test actually testing the converting constructor of the iterator?

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


More information about the libcxx-commits mailing list