有许多IEnumXXXX类型的COM接口具有纯虚拟方法下一步,如下所示:
IEnumString : IUnknown {
...
virtual HRESULT Next(ULONG, LPOLESTR*, ULONG*) = 0;
...
};
IEnumGUID : IUnknown {
...
virtual HRESULT Next(ULONG, GUID*, ULONG*) = 0;
...
};
需要一个模板,像这样:
enum_value_type<IEnumString>::type // LPOLESTR
enum_value_type<IEnumGUID>::type // GUID
沿着这些线的东西:
template <typename T> struct ExtractArgType;
template <typename C, typename T>
struct ExtractArgType<HRESULT (C::*)(ULONG, T*, ULONG*)>{
using type = T;
};
template <typename IEnum>
struct enum_value_type {
using type = typename ExtractArgType<decltype(&IEnum::Next)>::type;
};
演示