admin管理员组文章数量:1123261
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 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;
}
Share
Improve this question
asked 9 hours ago
JustplayitJustplayit
7171 gold badge7 silver badges23 bronze badges
3
|
1 Answer
Reset to default 0I like using what I call a meta function for this. Having
template<typename 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(decval<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>;
C::Output dummy;
return dummy;
}
本文标签: cExtracting typename from under typenameStack Overflow
版权声明:本文标题:c++ - Extracting typename from under typename - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736558575a1944613.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
B
always the same type? – Drew Dormann Commented 9 hours agotemplate<template <typename> class B, typename C, typename... Args> decltype(auto) calledMethod(const Member<B<C>>& method)
? – Igor Tandetnik Commented 9 hours ago