推断模板模板参数的类型

发布于 2025-01-14 07:05:15 字数 700 浏览 2 评论 0原文

我需要推断参数模板的类型名称。然后将通过反思使用这些参数来实现我的目标。到目前为止,我已经提出了以下似乎可行的方法:

template <typename... F, typename T>
static void templateA(T t) {
/* Use reflection to obtain the types in F */
}

然后将这样调用:

template <typename T>
void templateB() {
/* Do some work */
}

templateA<float>(templateB<float>);

这可行,但我想知道是否可以从 F 推断模板 B 的类型?我正在尝试模板模板参数,但到目前为止它还不起作用。像这样:

template <typename... F, template<typename V> class T>
static void templateA(T<F...> t) {
/* Use reflection to obtain the types in F */
}

templateA<float>(templateB);

这可能吗?我知道这是一个有点令人困惑的用例,但希望有任何关于如何实现这一目标的提示。

I need to deduce the typenames of a parameter template. Those parameters would then be used with reflection to achieve my goal. So far I have come up with the following which seems to work:

template <typename... F, typename T>
static void templateA(T t) {
/* Use reflection to obtain the types in F */
}

Which would then be called like this:

template <typename T>
void templateB() {
/* Do some work */
}

templateA<float>(templateB<float>);

This works but I was wondering if it is possible to infer the types of template B from F? I'm trying template template parameters but so far it's not working. Something like this:

template <typename... F, template<typename V> class T>
static void templateA(T<F...> t) {
/* Use reflection to obtain the types in F */
}

templateA<float>(templateB);

Is this possible. I understand this is a bit confusing use case but would appreciate any tips on how to achieve this.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文