Is this conversion type safe
vector<int*> a;
const vector<const int*>& b = reinterpret_cast<const vector<const int*>&>(a);
A static cast obviously doesnt work in this case because the template argument is changing. But by doing this reinterpret cast, I am just adding constness to essentially the same type. So should this be safe for all practical purposes?
Like any use of reinterpret_cast
to convert a reference to an unrelated type, it gives undefined behaviour, and so is not safe unless you define "safe" to mean "works on my compiler".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With