Heywood Floyd <soul...@gmail.com> wrote:

Is this possible somehow:
     int op(int r, int i)
    {
        static auto tbl = [&add, &sub, &mul];
        goto tbl[i % 3];
           add:
            r++;
            goto end;
        sub:
            r--;
            goto end;
        mul:
            r*=r;
            goto end;
        end:
        return r;
    }

Absolutely:

enum ops : int {
    add = 0,
    sub = 1,
    mul = 2;
}

int op( int r, int i ) {
    switch( i % 3 ) {
        case add:
            r++;
            break;
        case sub:
            r--;
            break;
        case mul:
            r*=r;
            break;
    }
    return r;
}

--
Simen

Reply via email to