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

via libcxx-commits libcxx-commits at lists.llvm.org
Mon Jun 3 14:22:53 PDT 2024


================
@@ -0,0 +1,135 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef TEST_STD_RANGES_RANGE_ADAPTORS_RANGE_ENUMERATE_TYPES_H
+#define TEST_STD_RANGES_RANGE_ADAPTORS_RANGE_ENUMERATE_TYPES_H
+
+#include <cstddef>
+#include <ranges>
+#include <tuple>
+
+#include "test_iterators.h"
+#include "test_macros.h"
+
+// Types
+
+template <typename T, typename DifferenceT = std::ptrdiff_t>
+using ValueType = std::tuple<DifferenceT, T>;
+
+struct RangeView : std::ranges::view_base {
+  using Iterator = cpp20_input_iterator<int*>;
+  using Sentinel = sentinel_wrapper<Iterator>;
+
+  constexpr explicit RangeView(int* b, int* e) : begin_(b), end_(e) {}
+  constexpr RangeView(RangeView const& other) : begin_(other.begin_), end_(other.end_), wasCopyInitialized(true) {}
+  constexpr RangeView(RangeView&& other) : begin_(other.begin_), end_(other.end_), wasMoveInitialized(true) {}
----------------
EricWF wrote:

This should set `other.begin_` and friends to `nullptr` or some other sentinal value.

I also worry about test types that track "was moved" and "was copied", because often times the _last_ copy or move construction isn't the one you care about.  (That said, there are types like this everywhere in the code base).

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


More information about the libcxx-commits mailing list