/* * Copyright (c) 2024-2025, Tim Flynn * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include namespace AK { namespace Detail { template struct Enumerator { using IteratorType = decltype(declval().begin()); using ValueType = decltype(*declval()); struct Enumeration { size_t index { 0 }; ValueType value; }; struct Iterator { Enumeration operator*() { return { index, *iterator }; } Enumeration operator*() const { return { index, *iterator }; } bool operator!=(Iterator const& other) const { return iterator != other.iterator; } void operator++() { ++index; ++iterator; } size_t index { 0 }; IteratorType iterator; }; Iterator begin() { return { 0, iterable.begin() }; } Iterator end() { return { 0, iterable.end() }; } Iterable iterable; }; } template auto enumerate(T&& range) { return Detail::Enumerator { forward(range) }; } } #ifdef USING_AK_GLOBALLY using AK::enumerate; #endif