If InputReader is declared in the header file as an array of constant size, then it should work as long as you #include <array> or #include <iterator> or any of several other library headers, so that you get the declarations
template<typename T, std::size_t N> T* std::begin(T (&array)[N]); template<typename T, std::size_t N> T* std::end(T (&array)[N]);
But what if InputReader is declared something like
extern InputReaderObject* InputReader;
or maybe
extern InputReaderObject InputReader[];
...? It's not obvious from that how many objects are in the array, but let's suppose the same header also has something like:
extern unsigned int InputReaderSize;
Anything you pass into the range-based for loop needs to have begin and end functions which return iterators. (The functions can be class members, found by argument-dependent lookup, or in namespace std.) The standard library defines some begin and end functions for actual arrays and standard containers, but you can extend it by defining your own:
#include <iterator> struct InputReaderLoopType { InputReaderObject* begin() const { return InputReader; } InputReaderObject* end() const { return InputReader + InputReaderSize; } }; extern const InputReaderLoopType InputReaderLoop;
would let you do...
for ( InputReaderObject& irb : InputReaderLoop )
(Making irb a reference instead of a copy is just a suggestion. You might actually need a copy for some reason.)
You could also define InputReaderObject* begin(InputReaderObject*); and InputReaderObject* end(InputReaderObject*); if you really want the loop to work with InputReader as already declared. But that could cause confusing results if somebody had a pointer of that type which is not in fact InputReader.
InputReaderwould help a lot.