Relative Content

Tag Archive for iterator

Interface to enumerate over files

I’m trying to design a generic interface for enumerating over a list files. Each iteration will open a file, allow the consuming code to access the file to perform some task, and then close the file.

Interface to enumerate over files

I’m trying to design a generic interface for enumerating over a list files. Each iteration will open a file, allow the consuming code to access the file to perform some task, and then close the file.

How to create a custom next() function?

In C++, I need a custom iterator that goes over an array, not all elements of which are marked as valid. Thus, the next() function must be a bit smarter than the one just doing ++iterator; I need it to check validity of the next element, skip it if not valid, and so forth till a valid element is found or encoutering the array end. Just wonder if there’s a more elegant way to do so, rather than checking all elements in a loop one by one. For example: