Is there any good way to obviate the const_cast
below, while keeping const correctness?
Without const_cast
the code below doesn\'t compile.
I want to explain the underlying logic of why this is impossible.
Suppose set
would be legitimate. Then you could do the following:
set s;
const int* p_const;
// fill s and p
auto it = s.find(p_const);
int* p = *it;
Hey presto! You transformed const int*
to int*
without performing const_cast
.