In a type like the unspecialized template struct pointer_traits
(i.e. template <class Ptr> struct pointer_traits
), there exists a member alias template rebind
that is defined to be Ptr::rebind<U>
, if it exists, or some other type otherwise. Though I have seen a few answers on checking whether a certain member exists, how does one implement a "conditional" alias template like pointer_traits::rebind
? That is, as if by the following pseudo-C++:
template <typename T> using type = has_type<T::U> ? int : float;
or
template <typename T> using type = if_has_type<T::U, int, float>::type;
I considered using something like the method depicted at https://en.wikibooks.org/wiki/More_C%2B%2B_Idioms/Member_Detector (section "Detecting member types"), but I don't know how to implement a helper struct whose [sole] member type depends on the existence of another member type.