boost::mpl typelist函数应用
我有一个函数,我想对类型列表中的所有类型执行(当前由 mpl 列表表示——这是否是实现它的合理方法?)
这里的关键是该函数只关心类型,非实际数据;它调用该类型的静态函数来检索一些信息,然后将其推入哈希表以供以后参考。
然而,据我所知, mpl 没有办法做到这一点 --- 我能找到的最接近的是 mpl for_each 运算符,但它似乎想用于每种类型的实际实例化,不是类型本身。
Loki 库有一个“apply”函数,这或多或少正是我所寻找的——它通过将指向类型列表中类型的指针作为参数传递来帮助推导,从而解决了实例化问题,但没有执行完整实例化。为了获得该功能,我应该在 MPL 中查看什么?或者我错过了一些明显的东西?
I have a function that I want to perform on all the types in a typelist (currently represented by an mpl list --- is this even a reasonable way to approach it?)
The key here is that the function only cares about the type, not actual data; it calls a static function in that type to retrieve some information and then does shoves it into a hash table for later reference.
However, as far as I can tell, the mpl does not have a means of doing this --- the closest I can find is the mpl for_each operator, but it appears to want to be used on actual instantiations of each of the types, not the types themselves.
The Loki library had an "apply" function, which is more or less what I am looking for -- it got around the instantiation issue by passing a pointer to the type in the typelist as a parameter to help with deduction, but not doing a full instantiation. What should I be looking at in the MPL to get that functionality? Or am I missing something obvious?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以将 for_each “重载”与 TransformOp 一起使用 以避免实例化类型:
You can use for_each "overload" with TransformOp to avoid instantiating the types:
最简单的选择可能就是这样:
The easiest option just might just be this:
在 MPL 中执行相同的操作:使用
boost::add_pointer
调用boost::mpl::transform
来创建指向您的类型的指针序列,然后使用boost::mpl::for_each
。Do the same thing in MPL: Call
boost::mpl::transform
withboost::add_pointer
to make a sequence of pointers to your types, and then useboost::mpl::for_each
.