diff -r 8a60250175ba -r 993c46d7eb75 src/basics.h --- a/src/basics.h Sun May 08 16:26:16 2016 +0300 +++ b/src/basics.h Sun May 08 20:12:54 2016 +0300 @@ -234,3 +234,46 @@ { a = not a; } + +// +// Iterates an enum +// +template +struct EnumIterShell +{ + struct Iterator + { + Iterator(typename std::underlying_type::type i) : + i(i) {} + + Iterator& operator++() { ++i; return *this; } + bool operator==(Iterator other) { return i == other.i; } + bool operator!=(Iterator other) { return i != other.i; } + Enum operator*() const { return Enum(i); } + + typename std::underlying_type::type i; + }; + + Iterator begin() + { + return Iterator(EnumLimits::First); + }; + + Iterator end() + { + return Iterator(EnumLimits::End); + } +}; + +template +EnumIterShell iterateEnum() +{ + return EnumIterShell(); +} + +// Is a value inside an enum? +template +bool valueInEnum(typename std::underlying_type::type x) +{ + return x >= EnumLimits::First and x <= EnumLimits::Last; +} \ No newline at end of file