从decltype(someFunction)中提取参数类型列表 [英] Extract just the argument type list from decltype(someFunction)

查看:302
本文介绍了从decltype(someFunction)中提取参数类型列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个可变参数模板,代表一个函数的参数列表,例如:

I have a variadic template that represents a list of parameters for a function, eg:

void myFunc (int,int,std::string) { }
template<typename... Args> class MyTemplateClass { };
...
MyTemplateClass<int,int,std::string> myConcrete; // for use with myFunc later

有没有办法我只能从decltype func)保存以手动编写,例如:

Is there any way I can extract just the argument types from decltype(func) to save having to write them manually, eg:

MyTemplateClass<something_like_decltype(myFunc)> myConcrete;

在这种情况下,decltype会给我void(int,int,string)一种提取在可变参数模板中使用的int,int,string部分的方法?

ie decltype in this case would give me "void(int,int,string)" but is there a way of extracting just the "int,int,string" part for use in the variadic template?

注意:我必须使用可变参数模板方法,

Note: I must use the variadic template method because within the template it performs processing on each argument type in turn.

推荐答案

以下应适用:

template<template<typename...> class C,typename T>
struct apply_args;

template<template<typename...> class C,typename R,typename... Args>
struct apply_args<C, R(Args...) >
{
    typedef C<Args...> type;
};

typedef apply_args<MyTemplateClass,decltype(myFunc)>::type MyConcrete;
MyConcrete myConcrete;

这篇关于从decltype(someFunction)中提取参数类型列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆