如何检查模板类型参数是否是打字机?

发布于 2025-02-04 15:36:23 字数 730 浏览 3 评论 0原文

我计划将BOOST :: MP11或BRIGAND用于我的TMP。在这里,我使用一些伪代码来说明我想做什么:

template< typename... Types >
class factory
{
  // if the passing type is a typelist, 
  //   then use for_each() to get types out of it one by one.
  // else 
  //   do something.
}

因此,类Factory的用户可能会通过常规类型(INT,Bool等)或打字机(Brigand或MP11 Typelist)传递。 。我希望我的代码在类Factory中可以从variadic模板包中选择类型,并根据是否是打字机进行不同的处理?例如:

factory<int, bool, typelist>       f1;
factory<typelist1, int, typelist2> f2
factory<typelist>                  f3

我没有找到两个库(MP11,Brigand)提供任何设施功能来检查类型是否是打字机。有人可以分享一些想法吗?

I plan to use either boost::mp11 or brigand for my TMP. Here I use some pseudo code to illustrate what I want to do:

template< typename... Types >
class factory
{
  // if the passing type is a typelist, 
  //   then use for_each() to get types out of it one by one.
  // else 
  //   do something.
}

So the user of class factory may pass in regular types (int, bool, etc.) or a typelist (either brigand or mp11 typelist). I want my code inside the class factory can pick types from the variadic template pack and do different processing according to whether it's a typelist or not? For example:

factory<int, bool, typelist>       f1;
factory<typelist1, int, typelist2> f2
factory<typelist>                  f3

I did not find the two libraries (mp11, brigand) provide any facility function to check whether a type is a typelist. Anyone can share some thoughts on this?

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

第七度阳光i 2025-02-11 15:36:23

哦,刚才,我从mp11文档中找到了此mp_is_list&lt; l&gt;。我想我可以利用这一点。

oh, just now, I found this mp_is_list<L> from MP11 document. I guess I can make use of that.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文