可变参数模板和类型特征
我目前有一个可变参数函数,它接受任意数量的任意类型的参数(废话),但是,我想将类型限制为仅 POD 的类型,并且大小与 void* 的大小相同或更小。
void* 检查很简单,我只是这样做了:
static_assert(sizeof...(Args) <= sizeof(PVOID), "Size of types must be <= memsize.");
但是我不知道如何对 std::is_pod 执行相同的操作。
这可以吗?
I currently have a variadic function which takes an arbitrary number of arguments of arbitrary types (duh), however, I want to restrict the types to ones which are POD only, and also the same size or smaller than that of a void*.
The void* check was easy, I just did this:
static_assert(sizeof...(Args) <= sizeof(PVOID), "Size of types must be <= memsize.");
However I can't work out how to do the same for std::is_pod.
Is this possible to do?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你可以写一个元函数来判断是否都是POD类型:
然后
You can write a meta-function to determine if all are POD types:
then