mercredi 24 mai 2017

Possible implementation of std::addressof

This could be a duplicate[link] but, the answer is rather short and dismissive. In a possible implementation like this:

template <class T>
T * addressof(T & v)
{
  return reinterpret_cast<T *>(& const_cast<char&>(reinterpret_cast<const volatile char &>(v)));
}

why is the const_cast needed?

Aucun commentaire:

Enregistrer un commentaire