2

Is is correct by the standard to cast std::pair<T1,T2>& to std::pair<const T1,T2>& ?

I have some customized map object which holds its inner key-value pair as std::pair<Key,Value>. I want to give to possibility to iterate over the map with an iterator, with the possibility to change the value, but not the key.

trying to static_cast the type pair<K,V>& to pair<const K,V>& with VC++ fails. I could do it with reinterpret_cast tricks, but I wonder if it is safe by the standard. and if not, is there any possibility to expose pair<K,V>& as pair<const K,V>& that doesn't require re-write the class ?

David Haim
  • 25,446
  • 3
  • 44
  • 78

0 Answers0