Off the cuff:
// C++ support machinery.
template< class Derived, Base >
constexpr bool is_same_or_derived_and_base_ =
std::is_base_of_v<Base, Derived>; // (sic!)
template< bool condition >
using Enable_if_ = std::enable_if_v<condition, int>;
template< class T > using const_ = const T;
// Problem solution: use a freestanding function.
// Possibly with trivial non-static member function wrappers.
struct My_class {};
template<
class T,
Enable_if_<is_same_or_derived_and_base_<T, My_class>> = 0
>
auto drop( const_<T*> p ) -> T* { return p; }
Disclaimer: not checked by a compiler.
See also: upcoming C++23 support for exactly this problem; <url:
https://www.google.com/search?q=c%2B%2B23+deduced+this>.
- Alf