4

I have a class wrapping a boost variant that only contains memmovable types (QList, QString, int etc).

May I declare that wrapper class memmovable to Qt containers?

4

2 回答 2

2

Aboost::variant只包含一个整数索引和一个aligned_storage,标准保证它是一个 POD。它没有虚拟成员,但有用户定义的构造函数和析构函数。因此,boost::variant它不是 POD 并试图记住它是 UB(嗯,我认为它是 UB,我在标准中找不到明确的参考)。

但是,对于 , 等也可以这样说QListQString显然 Qt 假定某些非 POD 类型可以安全地被存储,并在 POD(所谓的“原始类型”)和“可移动类型”之间进行了区分。

因此,如果您认为 memmove a 是安全的QList,您可以认为 memmove aboost::variant包含 memmovable 类型是安全的。

于 2012-06-06T10:15:07.393 回答
1

您可能知道 memmoving 非 POD 类型在技术上是未定义的行为。除此之外,variant 不包含任何在 memmoved 时会出现问题的内容。由于您提到 QList 和 QString 是可记忆的,并且我很难相信它们是 POD(尽管我没有看到它们),所以 boost::variant 也不会更糟。

于 2012-06-06T09:46:41.730 回答