I think this looks neater where it's used (and it makes Emacs indentation happier than the bare unbraced lists):
ENUMSPACE_CREATE(First, ONE)
ENUMSPACE_EXTEND(First, Second, TWO, THREE, FOUR)
ENUMSPACE_EXTEND(Second, Third, FIVE, SIX, SEVEN)
ENUMSPACE_EXTEND(Third, Fourth, EIGHT, NINE, TEN)
#include <algorithm>
#include <array>
#include <iostream>
#include <iterator>
int main()
{
using namespace Fourth;
std::ranges::copy(std::array<int, Fourth::_last>{
Fourth::ONE, Fourth::TWO,
Fourth::THREE, Fourth::FOUR,
Fourth::FIVE, Fourth::SIX,
Fourth::SIX, SEVEN, Fourth::EIGHT,
Fourth::NINE, Fourth::TEN
},
std::ostream_iterator<int>(std::cout, ", "));
}
One defect that this improved version doesn't address is that we can't specify the integer type underlying the enum, nor use enum class
, with these declarations.