You can overload them with SFINAE. e.g.
template<class TypeWithFunctionA>
auto doSomething(const TypeWithFunctionA & h) -> decltype(h.functionA())
{
return h.functionA();
}
template<class TypeWithFunctionB>
auto doSomething(const TypeWithFunctionB & h) -> decltype(h.functionB())
{
return h.functionB();
}
template<class TypeWithMember>
auto doSomething(const TypeWithMember & h) -> decltype(h.member)
{
return h.member;
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…