Declare and Use an Array on One Line

So I'm lazy and want to try and make and use a small lookup array on one line. I've tried this: int cap = {20,50,200,9001}[itemId-1]; but the compiler doesn't like it. Is there a way to do this or do I have to just suck it up and use two statements?
int cap[]={20,50,200,9001};
Well yeah, that allows the problem to be solved in two statements but I would like to do it in one. cap in this case is a scalar, not an array. I would essentially like to quickly set it to an element of an array as in my above code.
With VC++, this was the best I could do:

    using int_array = int const [];
    int cap = int_array{ 20,50,200,9001 }[itemId-1];

GCC and clang accept:

int cap = (int const[]){ 20,50,200,9001 }[itemId-1];
That's exactly what I was looking for, thanks!
Topic archived. No new replies allowed.