3 ms·
Indeed. This is part of why I included "idiomatic" in the title here. Someone smarter than me already wrote a bit prettier iterator increment function, and us
by jzwinck 13y ago
Indeed. This is part of why I included "idiomatic" in the title here. Someone smarter than me already wrote a bit prettier iterator increment function, and using that is easy once you have the interface decided. And in C++, iterators abound, and can be used as infinite sequence generators with no difference to how they are normally used and understood.
The code may be spaghetti, but I mostly just lifted it from the referenced article and solved the problems the original author brought up, namely the separation of concerns. The C++ solution to this problem will never be as beautiful as the Haskell one, but I wanted to show it doesn't have to be alienating for people who program C++ daily.
C++ iterators are powerful, and can be used for a lot more than stepping through a container. We write too few of them.