[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:27 PST 2023
================
@@ -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*>>();
----------------
var-const wrote:
Re. `types::for_each` -- other tests may not use it simply because it was not available yet at the time they were written. However, it's true that it doesn't make that much difference when there's only a single template parameter, so feel free to keep as is.
https://github.com/llvm/llvm-project/pull/73617
More information about the libcxx-commits
mailing list