serenity icon indicating copy to clipboard operation
serenity copied to clipboard

AK: Introduce AK::enumerate similar to C++23's std::views::enumerate

Open DanShaders opened this issue 1 year ago • 2 comments

I'm sick of writing C-style loops in JSSC every time I need an index too.

I don't want to fully port JSSC to enumerate just yet since it will conflict with my main JSSC dev branch. I've changed one such loop though in order to not break the "unused code" rule.

The AK::enumerate itself is modeled loosely after C++23's std::views::enumerate but little attention was paid to the value categories and constness. We can always iterate on it in-tree when these things become an issue. First commit also introduces a bunch of stuff ~~inspired~~ copied from Ranges TS but leaves them as an implementation detail.

DanShaders avatar Mar 11 '24 01:03 DanShaders

A couple of notes:

  • New features added to AK should always have unit tests
  • This implementation feels overly complex and won't work with e.g. temporaries. I don't think we need to model the STL with ranges, it can be simpler and work with more types: https://godbolt.org/z/6ccGz35K7

trflynn89 avatar Mar 11 '24 16:03 trflynn89

I don't think we need to model the STL with ranges

enumerate is just the greatest pain point right now. I also want add some range algorithms and adaptors, they will all benefit readability of JSSC code a lot.

DanShaders avatar Mar 11 '24 16:03 DanShaders

I've reevaluated my life choices and decided to go with Tim's simpler version.

DanShaders avatar Mar 20 '24 00:03 DanShaders