Enum-Iterator (EnumIt) is a header only C++11 library that supports iterators for enum and enum class type. EnumIt requires that the enumeration has no custom values (such as enum sample {VALUE = 1}) and requires knowledge of the last entry in the enumeration.
#include <iostream>
#include <string>
#include "enumit.hpp"
enum class SampleId {
FIRST,
SECOND,
THIRD
};
/*
enum SampleId {
FIRST,
SECOND,
THIRD
};*/
int main() {
for (auto iter = enumit::Begin<SampleId>(); iter != enumit::End<SampleId>(SampleId::THIRD); ++iter) {
SampleId entry = *iter;
std::cout << "Current SampleId: " << static_cast<int>(entry) << std::endl;
}
for (auto entry : enumit::Iterate<SampleId>(SampleId::THIRD)) {
std::cout << "Current SampleId: " << static_cast<int>(entry) << std::endl;
}
return 0;
}