Retain type safety by using const_cast instead of C-style cast