Is this OK? The reason I'm asking is that I have a boolean type enum that I want to use to index a vector. I know this example doesn't make it look very elegant but it's the best solution I can think of for my code.
static_cast<int>(x) will try to cast x into an integer correctly, this makes the code obvious and not implicit, and in many cases, a lot safer (you don't actually write idx1 + 1 later on when you don't remember the type of idx1 and assume it's an integer.
Yes you can. An object of type bool will be implicitly converted to type int. So there is no any problem. You need no explicitly to write static_cast as it was shown. This code is valid