/// Test enum
enum class Fruit
{
apple,
banana,
orange,
pineapple,
lemon
};
/// Non-scalable way
Fruit& operator++(Fruit& f)
{
switch(f)
{
case Fruit::apple: return f = Fruit::banana;
case Fruit::banana: return f = Fruit::orange;
case Fruit::orange: return f = Fruit::pineapple;
case Fruit::pineapple: return f = Fruit::lemon;
case Fruit::lemon: return f = Fruit::apple;
}
}
#include <iostream>
std::ostream& operator<<(std::ostream& os, Fruit f)
{
switch(f)
{
case Fruit::apple: os << "Fruit::apple"; return os;
case Fruit::banana: os << "Fruit::banana"; return os;
case Fruit::orange: os << "Fruit::orange"; return os;
case Fruit::pineapple: os << "Fruit::pineapple"; return os;
case Fruit::lemon: os << "Fruit::lemon"; return os;
}
}
int main()
{
Fruit f = Fruit::banana;
std::cout << "f = " << f << ";\n";
std::cout << "++f = " << ++f << ";\n";
}
CiAgICAvLy8gVGVzdCBlbnVtCiAgICBlbnVtIGNsYXNzIEZydWl0CiAgICB7CiAgICAgICAgYXBwbGUsCiAgICAgICAgYmFuYW5hLAogICAgICAgIG9yYW5nZSwKICAgICAgICBwaW5lYXBwbGUsCiAgICAgICAgbGVtb24KICAgIH07CgogICAgLy8vIE5vbi1zY2FsYWJsZSB3YXkKICAgIEZydWl0JiBvcGVyYXRvcisrKEZydWl0JiBmKQogICAgewogICAgICAgIHN3aXRjaChmKQogICAgICAgIHsKICAgICAgICAgICAgY2FzZSBGcnVpdDo6YXBwbGU6IHJldHVybiBmID0gRnJ1aXQ6OmJhbmFuYTsKICAgICAgICAgICAgY2FzZSBGcnVpdDo6YmFuYW5hOiByZXR1cm4gZiA9IEZydWl0OjpvcmFuZ2U7CiAgICAgICAgICAgIGNhc2UgRnJ1aXQ6Om9yYW5nZTogcmV0dXJuIGYgPSBGcnVpdDo6cGluZWFwcGxlOwogICAgICAgICAgICBjYXNlIEZydWl0OjpwaW5lYXBwbGU6IHJldHVybiBmID0gRnJ1aXQ6OmxlbW9uOwogICAgICAgICAgICBjYXNlIEZydWl0OjpsZW1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