I have the following method in a class A in C++ 11 where I know that TMethod gets converted to a typename B<C>.
How can I extract the C typename so that I can access further members from it like in the example below?
template<typename TMethod, typename... Args>
decltype(auto) calledMethod(const Member<TMethod>& method)
{
// somehow extract C from under TMethod
C::Output dummy;
return dummy;
}
I like using what I call a meta function for this. Having
template<template <typename> class T, typename C>
auto get_template_type(T<C>) -> C;
we can write an alias to get C like
template<typename T>
using template_type_t = decltype(get_template_type(declval<T>()));
and then in your function you you can get C like
template<typename TMethod, typename... Args>
decltype(auto) calledMethod(const Member<TMethod>& method)
{
using C = template_type_t<TMethod>;
typename C::Output dummy;
return dummy;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With