Let's say I have an array of integers, one for each member of a particular enum class. I can cast the enum class to an int to index the array but I'd rather use the enum class for type safety since that's the only type that should be allowed, in my case, to index that array.
If you are talking about a raw c-style-array, then there is little chance of forcing the index type to be an enum class. However, your assumption in point 2. is not necessarily true. If you inline define the function along with its declaration chances are high that for a trivial wrapper function the compiler will optimise the call:
enum class E {/*...*/};
template <typename T, std::size_t N>
struct A {
T data[N];
auto& operator[](E e) {
return data[static_cast<std::size_t>(e)];
}
auto const& operator[](E e) const {
return data[static_cast<std::size_t>(e)];
}
};
The calls to these inline functions are removed by the compiler. (live demo)