Hacker News new | ask | show | jobs
by morelisp 1312 days ago
Normally (when containers are not involved) this is exactly the point of a const cast.
1 comments

No, the primary point of a const cast is "I need to pass this to an API that expects a non-const pointer even though it won't mutate it".

Casting const away and then mutating is a footgun as you are in undefined behavior territory as soon as your pointer/reference is not just const itself but points to a const variable.