用循环值实现枚举的最佳方法是什么,以及从一个值过渡到另一个值的适当函数是什么?循环枚举值的实现
例如:
enum class Direction {
NORTH, EAST, SOUTH, WEST
};
constexpr Direction left(Direction d) {
return (Direction)((std::underlying_type<Directions>::type(d) - 1) % 4);
}
不过,我觉得这是很容易出错,一般无法读取。有没有更适当的方法来处理这种类型的枚举?
有四拼出来明确案例切换声明?这将是最可读的选项。 – RichieHindle 2013-04-20 20:38:50
如果有更多的LOTS值,该怎么办? – Svalorzen 2013-04-20 20:39:41
如果将'left'改为'nextCounterclockwise'(或简称为'nextCCW'),对于我来说更具可读性:-D – deepmax 2013-04-20 20:50:51