Is it ok to specialize std::pointer_traits?

69 Views Asked by At

Standard documentation says this about a specialization of std::pointer_traits.

https://en.cppreference.com/w/cpp/memory/pointer_traits

"A specialization for user-defined fancy pointer types may provide an additional static member function to_address to customize the behavior of std::to_address. "

This seems to imply that one can specialize this std class. Is this correct?

I need to do this for a fancy pointer class I don't control, but doesn't work with std::pointer_traits::rebind (which doesn't do the correct substitutions for this particular pointer class).

A similar question has been asked here What can and can't I specialize in the std namespace? but the specific case of pointer_traits was not addressed.


NOTE: I need this because pointer rebinding otherwise doesn't work out of the box for a pointer type I do not control.

template<class... As>
struct std::pointer_traits<::thrust::pointer<As...>>
: ::thrust::detail::pointer_traits<thrust::pointer<As...>> {
    template<class T>
    using rebind = typename ::thrust::detail::pointer_traits<::thrust::pointer<As...>>::template rebind<T>::other;
};
0

There are 0 best solutions below