    template<typename E, E f, E...>
    struct First
    {
        static const E value = f;
    };
    
    template<typename E, E first, E head, E...>
    struct Advance
    {
        static void adv(E& v)
        {
            if(v == head)
                v = first;
        }
    };
    
    template<typename E, E first, E head, E next, E... tail>
    struct Advance<E,first,head,next,tail...>
    {
        static void adv(E& v)
        {
            if(v == head)
                v = next;
            else
                Advance<E,first,next,tail...>::adv(v);
        }
    };
    
    template<typename E, E... values>
    struct EnumValues
    {
        static void advance(E& v)
        {
            Advance<E, First<E, values...>::value, values...>::adv(v);
        }
    };
    
    
    /// Test enum
    enum class Fruit
    {
        apple,
        banana,
        orange,
        pineapple,
        lemon
    };
    
    /// Scalable way, C++11-ish
    typedef EnumValues<Fruit,
            Fruit::apple,
            Fruit::banana,
            Fruit::orange,
            Fruit::pineapple,
            Fruit::lemon
    > Fruit_values11;

    Fruit& operator++(Fruit& f)
    {
        Fruit_values11::advance(f);
        return f;
    }

    
    #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";
    }