I'm not sure where you're going wrong there. But that seems entirely too complicated. Surely, all you need to do is use
const_cast<>
without all of the intermediate steps using
add/remove_pointer_t
?
const cfoo _cfoo;
const cfoo const_cfoo_ptr = &_cfoo; auto cfoo_ptr = const_cast<add_pointer_t<remove_const_t<remove_pointer_t<decltype(const_cfoo_ptr)>>>>(const_cfoo_ptr); auto cfoo2_ptr = const_cast<cfoo*>(const_foo_ptr);
optional<const cfoo*> optional_const_cfoo_ptr = &_cfoo; auto const_cfoo_ptr_from_optional = *optional_const_cfoo_ptr; auto cfoo_ptr_from const_optional = const_cast<cfoo *>(*optional_const_cfoo_ptr);
Which gets you to a pointer to a cfoo, which is what I think you're trying to achieve.