Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
180 views
Welcome To Ask or Share your Answers For Others

1 Answer

After looking into defining a view interface, I decided to use range-v3.

There are several things missing from std::ranges https://stackoverflow.com/a/68172842/11998382, and until they are added in future standards, it is sensible to use range-v3 rather than repeatedly attempting non-trivial implementations yourself.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...