================ @@ -0,0 +1,101 @@ +//===----------------------------------------------------------------------===// +// +// 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 auto operator*() const; + +#include <array> +#include <cassert> +#include <concepts> +#include <cstddef> +#include <utility> +#include <tuple> + +#include "test_iterators.h" +#include "test_macros.h" +#include "../types.h" + +template <class Iterator, class ValueType = int, 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 Result = std::tuple<typename EnumerateIterator::difference_type, + std::ranges::range_reference_t<MinimalView<Iterator, Sentinel>>>; + + std::array array{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + + View view{Iterator(array.begin()), Sentinel(Iterator(array.end()))}; + EnumerateView ev{std::move(view)}; + + { + auto it = ev.begin(); + for (std::size_t index = 0; index < array.size(); ++index) { + std::same_as<Result> decltype(auto) result = *it; + + auto [resultIndex, resultValue] = result; + assert(std::cmp_equal(index, resultIndex)); + assert(array[index] == resultValue); + + ++it; + } + + assert(it == ev.end()); + } + + // const + { + auto constIt = std::as_const(ev).begin(); + for (std::size_t index = 0; index < array.size(); ++index) { + std::same_as<Result> decltype(auto) result = *constIt; + + auto [resultIndex, resultValue] = result; + assert(std::cmp_equal(index, resultIndex)); + assert(array[index] == resultValue); + + ++constIt; + } ---------------- cjdb wrote:
Please hand-roll. https://github.com/llvm/llvm-project/pull/73617 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits