Generators in C++

As we know iterators in C++ is a good but not perfect abstraction. Concept of foreach() (D, Python, Ruby, etc.) appears as more generic solution. At least foreach() does not require artificial iterator::end() to be defined for the collection. Abstraction foreach() can be imagined as some function/object that is returning next value of collection/sequence each…