You can const_cast
away qualification if the underlying object isn't const
-qualified, but only the reference is.
But const
qualification isn't necessarily the same thing as being stored statically in physical ROM. In most cases, the compiler simply believes it's safe that the object won't be modified by anyone.
Yes, it's undefined behavior. And this is considered a serious shortcoming of initializer_list
. Hopefully it will be fixed for C++17.
Yes, you'll probably get away with it if moving is the only thing that ever happens to those elements, which in fact covers almost all the safe use-cases of initializer_list
under the sun.