std :: tuple和标准布局 [英] std::tuple and standard layout

查看:95
本文介绍了std :: tuple和标准布局的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果std::tuple的所有成员都是标准布局类型,则std::tuple本身就是标准布局?用户定义的复制构造函数的存在使它变得不平凡,但是我想知道它是否仍然可以是标准布局.

If all of the members of std::tuple are of standard layout types, is that std::tuple itself standard layout? The presence of a user-defined copy-constructor makes it non-trivial, but I was wondering if it can still be standard layout.

从规范中引用是很好的.

A quote from the spec would be good.

推荐答案

不,标准布局要求所有非静态数据成员属于一个基本子对象或直接属于最派生的类型,并且std::tuple的典型实现实现一个每个基类的成员.

No, standard layout requires that all nonstatic data members belong to either one base subobject or directly to the most derived type, and typical implementations of std::tuple implement one member per base class.

由于成员声明不能是包扩展,因此,根据上述要求,标准布局tuple不能具有多个成员.通过将所有tuple成员"存储在一个char[]中,并通过reinterpret_cast获取对象引用,实现仍可以避开该问题.元程序将必须生成类布局.特殊成员功能将必须重新实现.会很痛苦的.

Because a member-declaration cannot be a pack expansion, in light of the above requirement, a standard layout tuple cannot have more than one member. An implementation could still sidestep the issue by storing all the tuple "members" inside one char[], and obtaining the object references by reinterpret_cast. A metaprogram would have to generate the class layout. Special member functions would have to be reimplemented. It would be quite a pain.

这篇关于std :: tuple和标准布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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