In a pre-c++20 question Access index in range-for loop (answer), it was mentioned that
2020 note: It would probably be more wise to use a lambda-based solution instead of macro trickery.
Could someone post the lambda-based solution for c++20? Are there any other solutions new to c++20?
Edit: I have a main loop which is polymorphic over the size of a vector. Since I have to read and modify this piece of code frequently, I think I'm justified wanting the nicest solution. What happens if I want to use views::reverse
sometimes in the main loop and not others? (I don't actually need this, and solved my immediate problem after refactoring, but still I'm using additional initializations so frequently to access the current element in cold development areas of my code base, it's worth finding a solution)
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…