Personally, I prefer to use casts at the boundary of the library that is not const correct. The upside of this approach is that you allow your code to get the benefits of the proper usage of const. The downside is that if the library modifies an object, even "temporarily", that you've casted away const on, your program can fault.
For example, I've seen C libraries that take char *
parameters that they don't logically modify. However, their parser may temporarily replace delimiters in the string with zeroes to use strcpy
to extract them. If you cast away const to allow a C++ function to take a const char *
, and someone passes a pointer to an object that's actually const, the "temporary" replacement of the delimiter with a zero will cause a fault.